From ba1d4ebbdbe3dbfdea702c6e01322e9f62c12193 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Wed, 11 Jan 2023 19:44:05 -0800 Subject: [PATCH] Remove pkg_resources usage (#100) `pkg_resources` is part of `setuptools`, so removing it allows not having a runtime dep on `setuptools`. It is also discouraged since `importlib` has the necessary features. https://setuptools.pypa.io/en/latest/pkg_resources.html Declare `importlib_resources` as a dependency for tests in 3.8 (since the `.files()` method was added in 3.9 stdlib) Update Read the Docs config to avoid the default 3.7 version. Relevant to https://github.com/sourmash-bio/sourmash/pull/2433 and https://github.com/NixOS/nixpkgs/pull/205878 --- .readthedocs.yaml | 17 +++++++++++++++++ screed/__init__.py | 6 +++--- screed/tests/screed_tst_utils.py | 16 ++++++++-------- setup.cfg | 1 + tox.ini | 3 +++ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 .readthedocs.yaml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..51862c2 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,17 @@ +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-22.04 + tools: + python: "3.10" + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: doc/conf.py + +python: + install: + - method: pip + path: . + system_packages: true diff --git a/screed/__init__.py b/screed/__init__.py index 5f0861f..70c4558 100755 --- a/screed/__init__.py +++ b/screed/__init__.py @@ -36,10 +36,10 @@ from screed.screedRecord import Record -from pkg_resources import get_distribution, DistributionNotFound +from importlib.metadata import version, PackageNotFoundError try: - VERSION = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover + VERSION = version(__name__) +except PackageNotFoundError: # pragma: no cover try: from .version import version as VERSION # noqa except ImportError: # pragma: no cover diff --git a/screed/tests/screed_tst_utils.py b/screed/tests/screed_tst_utils.py index ec3d4a6..ab99b8c 100644 --- a/screed/tests/screed_tst_utils.py +++ b/screed/tests/screed_tst_utils.py @@ -11,20 +11,20 @@ import tempfile import os import shutil -from pkg_resources import Requirement, resource_filename, ResolutionError from io import StringIO import sys import traceback +from importlib import resources + +# Remove when we drop support for 3.8 +if sys.version_info < (3, 9): + import importlib_resources as resources + def get_test_data(filename): - filepath = None - try: - filepath = resource_filename( - Requirement.parse("screed"), "screed/tests/" + filename) - except ResolutionError: - pass - if not filepath or not os.path.isfile(filepath): + filepath = resources.files('screed') / 'screed' / 'tests' / filename + if not filepath.exists() or not os.path.isfile(filepath): filepath = os.path.join(os.path.dirname(__file__), 'test-data', filename) return filepath diff --git a/setup.cfg b/setup.cfg index 328a24d..f7cc503 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,5 +50,6 @@ test = pytest >= 6.2.2 pycodestyle pytest-cov + importlib_resources;python_version<'3.9' all = %(test)s diff --git a/tox.ini b/tox.ini index 71edf75..4581f8c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,8 @@ [tox] envlist = py38, py39, py310 +minversion = 3.12 +isolated_build = true +skip_missing_interpreters = true [testenv] passenv =