Skip to content

Commit

Permalink
Remove pkg_resources usage (#100)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
luizirber authored Jan 12, 2023
1 parent 6fb3e49 commit ba1d4eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
17 changes: 17 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions screed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions screed/tests/screed_tst_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ test =
pytest >= 6.2.2
pycodestyle
pytest-cov
importlib_resources;python_version<'3.9'
all =
%(test)s
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[tox]
envlist = py38, py39, py310
minversion = 3.12
isolated_build = true
skip_missing_interpreters = true

[testenv]
passenv =
Expand Down

0 comments on commit ba1d4eb

Please sign in to comment.