From fbd874aa6ea52a4052c627b4952fb52aca1c8b3f Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Mon, 17 Jun 2024 11:43:20 -0500 Subject: [PATCH 1/2] fix: Use importlib-resources over deprecated pkg_resources * Add importlib-resources as an install dependency for Python 3.8 as Python 3.12 deprecates and removes pkg_resources. * Replace use of pkg_resources.resource_filename with importlib.resources.files for Python 3.9+ and importlib_resources.files for Python 3.8. * Apply isort. --- setup.py | 1 + yadageschemas/__init__.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 6f73295..25f4b61 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,7 @@ 'jsonschema<=4.9.1', # c.f. https://github.com/yadage/yadage-schemas/issues/38 'click', 'six>=1.4.0', # six.moves added in six v1.4.0 + 'importlib-resources>=5.10;python_version<"3.9"' # for accessing package filepaths ], extras_require = { 'develop': [ diff --git a/yadageschemas/__init__.py b/yadageschemas/__init__.py index 7d1b013..9971894 100644 --- a/yadageschemas/__init__.py +++ b/yadageschemas/__init__.py @@ -1,12 +1,18 @@ import json -import pkg_resources -schemadir = pkg_resources.resource_filename('yadageschemas','') +try: + from importlib.resources import files +except ImportError: + # Support Python 3.8 as importlib.resources added in Python 3.9 + # https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files + from importlib_resources import files -from .utils import WithJsonRefEncoder from . import dialects +from .utils import WithJsonRefEncoder from .validator import validate_spec +schemadir = files("yadageschemas") + def load(spec, specopts, validate = True, validopts = None, dialect = 'raw_with_defaults'): data = dialects.handlers[dialect](spec, specopts) if validate: From a9c96babaae349ed959509bf4e409693288a86ba Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Mon, 17 Jun 2024 11:51:06 -0500 Subject: [PATCH 2/2] revert import order --- yadageschemas/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yadageschemas/__init__.py b/yadageschemas/__init__.py index 9971894..eb4ec64 100644 --- a/yadageschemas/__init__.py +++ b/yadageschemas/__init__.py @@ -7,11 +7,13 @@ # https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files from importlib_resources import files +# FIXME: Import order must be before yadageschemas.utils to avoid circular import +schemadir = files("yadageschemas") + from . import dialects from .utils import WithJsonRefEncoder from .validator import validate_spec -schemadir = files("yadageschemas") def load(spec, specopts, validate = True, validopts = None, dialect = 'raw_with_defaults'): data = dialects.handlers[dialect](spec, specopts)