diff --git a/doc/conf.py b/doc/conf.py index d7113d6e4d..23331efe08 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -65,8 +65,8 @@ # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. -from pkg_resources import get_distribution -release = get_distribution('sourmash').version +from importlib.metadata import version +release = version('sourmash') version = '.'.join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation diff --git a/pyproject.toml b/pyproject.toml index 942a898f18..e196af7be7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ dependencies = [ "deprecation>=2.0.6", "cachetools>=4,<6", "bitstring>=3.1.9,<5", - "importlib_metadata;python_version<'3.10'" + "importlib_metadata>=3.6;python_version<'3.10'" ] requires-python = ">=3.8" @@ -144,7 +144,7 @@ features = ["maturin"] locked = true [tool.isort] -known_third_party = ["deprecation", "hypothesis", "mmh3", "numpy", "pkg_resources", "pytest", "screed", "setuptools", "sourmash_tst_utils"] +known_third_party = ["deprecation", "hypothesis", "mmh3", "numpy", "pytest", "screed", "sourmash_tst_utils"] multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 diff --git a/src/sourmash/__init__.py b/src/sourmash/__init__.py index f28a7e9337..33170edcd8 100644 --- a/src/sourmash/__init__.py +++ b/src/sourmash/__init__.py @@ -16,6 +16,7 @@ class MinHash - hash sketch class BSD 3-Clause license. """ from deprecation import deprecated +from importlib.metadata import version __all__ = ['MinHash', 'SourmashSignature', 'load_one_signature', @@ -33,19 +34,7 @@ class MinHash - hash sketch class ffi.init_once(lib.sourmash_init, "init") -from pkg_resources import get_distribution, DistributionNotFound - -try: - VERSION = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover - try: - from .version import version as VERSION # noqa - except ImportError: # pragma: no cover - raise ImportError( - "Failed to find (autogenerated) version.py. " - "This might be because you are installing from GitHub's tarballs, " - "use the PyPI ones." - ) +VERSION = version(__name__) from .minhash import MinHash, get_minhash_default_seed, get_minhash_max_hash diff --git a/tests/sourmash_tst_utils.py b/tests/sourmash_tst_utils.py index e10913f9a7..07582b0dc2 100644 --- a/tests/sourmash_tst_utils.py +++ b/tests/sourmash_tst_utils.py @@ -6,13 +6,21 @@ import subprocess import collections import pprint - -import pkg_resources -from pkg_resources import Requirement, resource_filename, ResolutionError import traceback from io import open # pylint: disable=redefined-builtin from io import StringIO +from importlib import resources +from importlib.metadata import entry_points + +# Remove when we drop support for 3.8 +if sys.version_info < (3, 9): + import importlib_resources as resources + +# Remove when we drop support for 3.9 +if sys.version_info < (3, 10): + from importlib_metadata import entry_points + SIG_FILES = [os.path.join('demo', f) for f in ( "SRR2060939_1.sig", "SRR2060939_2.sig", "SRR2241509_1.sig", @@ -44,9 +52,10 @@ def _runscript(scriptname): namespace['sys'] = globals()['sys'] try: - pkg_resources.load_entry_point("sourmash", 'console_scripts', scriptname)() + (script,) = entry_points(name=scriptname, group="console_scripts") + script.load()() return 0 - except pkg_resources.ResolutionError: + except ValueError: pass path = scriptpath() @@ -129,14 +138,8 @@ def runscript(scriptname, args, **kwargs): def get_test_data(filename): - filepath = None - try: - filepath = resource_filename( - Requirement.parse("sourmash"), "sourmash/sourmash/test-data/"\ - + filename) - except ResolutionError: - pass - if not filepath or not os.path.isfile(filepath): + filepath = resources.files("sourmash") / "tests" / "test-data" / 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/tox.ini b/tox.ini index 87e4330004..4fae4cc6ff 100644 --- a/tox.ini +++ b/tox.ini @@ -99,7 +99,7 @@ commands = [testenv:docs] description = invoke sphinx-build to build the HTML docs -basepython = python3.8 +basepython = python3.10 extras = doc whitelist_externals = pandoc passenv = HOME