Skip to content

Commit d5fe4b0

Browse files
authored
Update script to use importlib_resources (#6949)
To avoid a deprecation warning, this change updates scripts/update_api.py to use 'importlib_resources' instead of 'pkg_resources'. See https://setuptools.pypa.io/en/latest/pkg_resources.html and https://importlib-resources.readthedocs.io/en/latest/migration.html for more information.
1 parent f07c46a commit d5fe4b0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: scripts/update_api.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1827,17 +1827,25 @@ def write_core_py_preamble(core_py):
18271827
core_py.write(
18281828
"""
18291829
# Automatically generated file
1830+
import atexit
18301831
import sys, os
1832+
import contextlib
18311833
import ctypes
1832-
import pkg_resources
1834+
import importlib_resources
18331835
from .z3types import *
18341836
from .z3consts import *
18351837
1838+
_file_manager = contextlib.ExitStack()
1839+
atexit.register(_file_manager.close)
18361840
_ext = 'dll' if sys.platform in ('win32', 'cygwin') else 'dylib' if sys.platform == 'darwin' else 'so'
18371841
_lib = None
1842+
_z3_lib_resource = importlib_resources.files('z3', 'lib')
1843+
_z3_lib_resource_path = _file_manager.enter_context(
1844+
importlib_resources.as_file(_z3_lib_resource)
1845+
)
18381846
_default_dirs = ['.',
18391847
os.path.dirname(os.path.abspath(__file__)),
1840-
pkg_resources.resource_filename('z3', 'lib'),
1848+
_z3_lib_resource_path,
18411849
os.path.join(sys.prefix, 'lib'),
18421850
None]
18431851
_all_dirs = []

0 commit comments

Comments
 (0)