From d5fe4b0d78ef109582e9562adb9a67d33a8871ea Mon Sep 17 00:00:00 2001 From: rsetaluri Date: Tue, 24 Oct 2023 13:19:44 -0700 Subject: [PATCH] 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. --- scripts/update_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index c68597ea2..78bfb6b7a 100755 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1827,17 +1827,25 @@ def write_core_py_preamble(core_py): core_py.write( """ # Automatically generated file +import atexit import sys, os +import contextlib import ctypes -import pkg_resources +import importlib_resources from .z3types import * from .z3consts import * +_file_manager = contextlib.ExitStack() +atexit.register(_file_manager.close) _ext = 'dll' if sys.platform in ('win32', 'cygwin') else 'dylib' if sys.platform == 'darwin' else 'so' _lib = None +_z3_lib_resource = importlib_resources.files('z3', 'lib') +_z3_lib_resource_path = _file_manager.enter_context( + importlib_resources.as_file(_z3_lib_resource) +) _default_dirs = ['.', os.path.dirname(os.path.abspath(__file__)), - pkg_resources.resource_filename('z3', 'lib'), + _z3_lib_resource_path, os.path.join(sys.prefix, 'lib'), None] _all_dirs = []