Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pkg_resources usage #2505

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to avoid having behavior differences in importlib_metadata

]

requires-python = ">=3.8"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 2 additions & 13 deletions src/sourmash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

Expand Down
29 changes: 16 additions & 13 deletions tests/sourmash_tst_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down