Skip to content

Commit 6a248eb

Browse files
committed
fix: Remove pkg_resources dependency
There is no reasonable case where a user has pkg_resources-accessible metadata (or importlib-metadata) and does not have a `_version.py` file. Instead of replacing with importlib-metadata, I'm just skipping ahead to the hard-coded "unknown", using `0+unknown` to satisfy PEP440. There may be a very rare case where someone makes an editable installation and borks their directory, but knowing what the version was when they installed it won't help us a lot there.
1 parent e280510 commit 6a248eb

File tree

2 files changed

+3
-34
lines changed

2 files changed

+3
-34
lines changed

nitransforms/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@
2424
try:
2525
from ._version import __version__
2626
except ModuleNotFoundError:
27-
from pkg_resources import get_distribution, DistributionNotFound
28-
29-
try:
30-
__version__ = get_distribution("nitransforms").version
31-
except DistributionNotFound:
32-
__version__ = "unknown"
33-
del get_distribution
34-
del DistributionNotFound
27+
__version__ = "0+unknown"
3528

3629
__packagename__ = "nitransforms"
3730
__copyright__ = "Copyright (c) 2021 The NiPy developers"

nitransforms/tests/test_version.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
"""Test _version.py."""
22
import sys
3-
from collections import namedtuple
43
from importlib import reload
5-
import pytest
64
import nitransforms
75

8-
try:
9-
from pkg_resources import DistributionNotFound
10-
except ImportError:
11-
pytest.skip(allow_module_level=True)
12-
136

147
def test_version_scm0(monkeypatch):
158
"""Retrieve the version via setuptools_scm."""
@@ -22,26 +15,9 @@ class _version:
2215
assert nitransforms.__version__ == "10.0.0"
2316

2417

25-
def test_version_scm1(monkeypatch):
26-
"""Retrieve the version via pkg_resources."""
27-
monkeypatch.setitem(sys.modules, "nitransforms._version", None)
28-
29-
def _dist(name):
30-
Distribution = namedtuple("Distribution", ["name", "version"])
31-
return Distribution(name, "success")
32-
33-
monkeypatch.setattr("pkg_resources.get_distribution", _dist)
34-
reload(nitransforms)
35-
assert nitransforms.__version__ == "success"
36-
37-
38-
def test_version_scm2(monkeypatch):
18+
def test_version_fallback(monkeypatch):
3919
"""Check version could not be interpolated."""
4020
monkeypatch.setitem(sys.modules, "nitransforms._version", None)
4121

42-
def _raise(name):
43-
raise DistributionNotFound("No get_distribution mock")
44-
45-
monkeypatch.setattr("pkg_resources.get_distribution", _raise)
4622
reload(nitransforms)
47-
assert nitransforms.__version__ == "unknown"
23+
assert nitransforms.__version__ == "0+unknown"

0 commit comments

Comments
 (0)