From c9e1e41cb583a05ee763c6363d708810a06570e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20Courtney?= Date: Thu, 13 Feb 2025 18:59:08 +0000 Subject: [PATCH 1/2] 7-remove-the-use-of-pkg_resources: pump version --- python_wrapper/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_wrapper/setup.py b/python_wrapper/setup.py index 21de3ab89..4cd543e4a 100644 --- a/python_wrapper/setup.py +++ b/python_wrapper/setup.py @@ -2,7 +2,7 @@ setup( name='twa', - version='0.0.7', + version='0.0.8', author='Jiaru Bai; Daniel Nurkowski', author_email='jb2197@cam.ac.uk; danieln@cmclinnovations.com', license='MIT', From e2f0751b39d8b8ff7e24c0e573f0fff08d30f536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20Courtney?= Date: Thu, 13 Feb 2025 19:01:41 +0000 Subject: [PATCH 2/2] 7-remove-the-use-of-pkg_resources: replace pkg_resources with importlib_resources --- python_wrapper/setup.py | 1 + python_wrapper/twa/resRegistry/resRegistry.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python_wrapper/setup.py b/python_wrapper/setup.py index 4cd543e4a..bb4c07bf7 100644 --- a/python_wrapper/setup.py +++ b/python_wrapper/setup.py @@ -25,6 +25,7 @@ 'python-dotenv', 'yagmail', 'Werkzeug', + 'importlib_resources>=5.10', ], include_package_data=True, entry_points={ diff --git a/python_wrapper/twa/resRegistry/resRegistry.py b/python_wrapper/twa/resRegistry/resRegistry.py index 6ddde9308..e4e18b336 100644 --- a/python_wrapper/twa/resRegistry/resRegistry.py +++ b/python_wrapper/twa/resRegistry/resRegistry.py @@ -1,4 +1,4 @@ -import pkg_resources +import importlib_resources import json import os import shutil @@ -6,7 +6,7 @@ import builtins import textwrap -_RES_DIR = pkg_resources.resource_filename(__name__, os.path.join('..','resources')) +_RES_DIR = importlib_resources.files(__name__).joinpath('..','resources') _RES_REG_FILE = 'resources_registry.json' _DEF_RES_META_FILE = 'default_resources.json' _URL_ID = 'url://' @@ -24,7 +24,9 @@ def __init__(self): Constructs the registry object. If regsitry file does not exists, it creates one on the fly. """ try: - self.resReg = json.load(pkg_resources.resource_stream(__name__, os.path.join('..','resources',_RES_REG_FILE))) + resource_path = importlib_resources.files(__name__).joinpath('..', 'resources', _RES_REG_FILE) + with importlib_resources.open_text(__name__, resource_path) as resource_file: + self.resReg = json.load(resource_file) except FileNotFoundError: self.resReg = {'resources':{}} self._updateRegFile()