Repository: sourmash-bio/sourmash (language: python)

Issue:
WIP: remove version retrieval exception handling code
Found some outdated code per https://github.com/sourmash-bio/sourmash/issues/2425#issuecomment-1440068864, looking to see what happens if I remove it ;).



Discussion / hints:
# [Codecov](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio) Report
> Merging [#2491](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio) (01a1816) into [latest](https://codecov.io/gh/sourmash-bio/sourmash/commit/59f48c1224b5d6e5e7462921479ed8d948b29c1b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio) (59f48c1) will **increase** coverage by `7.80%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           latest    #2491      +/-   ##
==========================================
+ Coverage   84.72%   92.52%   +7.80%     
==========================================
  Files         132      103      -29     
  Lines       14731    11936    -2795     
  Branches     2503     2503              
==========================================
- Hits        12481    11044    -1437     
+ Misses       1948      590    -1358     
  Partials      302      302              
```

| Flag | Coverage Δ | |
|---|---|---|
| python | `92.52% <100.00%> (-0.01%)` | :arrow_down: |
| rust | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio) | Coverage Δ | |
|---|---|---|
| [src/sourmash/\_\_init\_\_.py](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL3NvdXJtYXNoL19faW5pdF9fLnB5) | `100.00% <100.00%> (ø)` | |
| [src/core/src/ffi/minhash.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2ZmaS9taW5oYXNoLnJz) | | |
| [src/core/src/sketch/hyperloglog/mod.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL3NrZXRjaC9oeXBlcmxvZ2xvZy9tb2QucnM=) | | |
| [src/core/src/index/bigsi.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2luZGV4L2JpZ3NpLnJz) | | |
| [src/core/src/errors.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2Vycm9ycy5ycw==) | | |
| [src/core/src/index/search.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2luZGV4L3NlYXJjaC5ycw==) | | |
| [src/core/src/ffi/storage.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2ZmaS9zdG9yYWdlLnJz) | | |
| [src/core/src/ffi/index/mod.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2ZmaS9pbmRleC9tb2QucnM=) | | |
| [src/core/src/ffi/utils.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL2ZmaS91dGlscy5ycw==) | | |
| [src/core/src/sketch/hyperloglog/estimators.rs](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio#diff-c3JjL2NvcmUvc3JjL3NrZXRjaC9oeXBlcmxvZ2xvZy9lc3RpbWF0b3JzLnJz) | | |
| ... and [20 more](https://codecov.io/gh/sourmash-bio/sourmash/pull/2491?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio) | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sourmash-bio)


Fix patch:
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/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


Test patch:
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