Skip to content

Commit ba1d4eb

Browse files
authored
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 sourmash-bio/sourmash#2433 and NixOS/nixpkgs#205878
1 parent 6fb3e49 commit ba1d4eb

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

.readthedocs.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
3+
# Set the version of Python and other tools you might need
4+
build:
5+
os: ubuntu-22.04
6+
tools:
7+
python: "3.10"
8+
9+
# Build documentation in the docs/ directory with Sphinx
10+
sphinx:
11+
configuration: doc/conf.py
12+
13+
python:
14+
install:
15+
- method: pip
16+
path: .
17+
system_packages: true

screed/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
from screed.screedRecord import Record
3737

3838

39-
from pkg_resources import get_distribution, DistributionNotFound
39+
from importlib.metadata import version, PackageNotFoundError
4040
try:
41-
VERSION = get_distribution(__name__).version
42-
except DistributionNotFound: # pragma: no cover
41+
VERSION = version(__name__)
42+
except PackageNotFoundError: # pragma: no cover
4343
try:
4444
from .version import version as VERSION # noqa
4545
except ImportError: # pragma: no cover

screed/tests/screed_tst_utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
import tempfile
1212
import os
1313
import shutil
14-
from pkg_resources import Requirement, resource_filename, ResolutionError
1514
from io import StringIO
1615
import sys
1716
import traceback
1817

18+
from importlib import resources
19+
20+
# Remove when we drop support for 3.8
21+
if sys.version_info < (3, 9):
22+
import importlib_resources as resources
23+
1924

2025
def get_test_data(filename):
21-
filepath = None
22-
try:
23-
filepath = resource_filename(
24-
Requirement.parse("screed"), "screed/tests/" + filename)
25-
except ResolutionError:
26-
pass
27-
if not filepath or not os.path.isfile(filepath):
26+
filepath = resources.files('screed') / 'screed' / 'tests' / filename
27+
if not filepath.exists() or not os.path.isfile(filepath):
2828
filepath = os.path.join(os.path.dirname(__file__), 'test-data',
2929
filename)
3030
return filepath

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ test =
5050
pytest >= 6.2.2
5151
pycodestyle
5252
pytest-cov
53+
importlib_resources;python_version<'3.9'
5354
all =
5455
%(test)s

tox.ini

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[tox]
22
envlist = py38, py39, py310
3+
minversion = 3.12
4+
isolated_build = true
5+
skip_missing_interpreters = true
36

47
[testenv]
58
passenv =

0 commit comments

Comments
 (0)