Skip to content

Commit

Permalink
fix: Use importlib-resources over deprecated pkg_resources (#51)
Browse files Browse the repository at this point in the history
* 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.
* Note import order issue to be fixed.
  • Loading branch information
matthewfeickert authored Jun 17, 2024
1 parent c1d4502 commit 1739071
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
14 changes: 11 additions & 3 deletions yadageschemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
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

# FIXME: Import order must be before yadageschemas.utils to avoid circular import
schemadir = files("yadageschemas")

from .utils import WithJsonRefEncoder
from . import dialects
from .utils import WithJsonRefEncoder
from .validator import validate_spec


def load(spec, specopts, validate = True, validopts = None, dialect = 'raw_with_defaults'):
data = dialects.handlers[dialect](spec, specopts)
if validate:
Expand Down

0 comments on commit 1739071

Please sign in to comment.