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

fix: Remove pkg_resources dependency #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 1 addition & 8 deletions nitransforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@
try:
from ._version import __version__
except ModuleNotFoundError:
from pkg_resources import get_distribution, DistributionNotFound

try:
__version__ = get_distribution("nitransforms").version
except DistributionNotFound:
__version__ = "unknown"
del get_distribution
del DistributionNotFound
__version__ = "0+unknown"

__packagename__ = "nitransforms"
__copyright__ = "Copyright (c) 2021 The NiPy developers"
Expand Down
28 changes: 2 additions & 26 deletions nitransforms/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
"""Test _version.py."""
import sys
from collections import namedtuple
from importlib import reload
import pytest
import nitransforms

try:
from pkg_resources import DistributionNotFound
except ImportError:
pytest.skip(allow_module_level=True)


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


def test_version_scm1(monkeypatch):
"""Retrieve the version via pkg_resources."""
monkeypatch.setitem(sys.modules, "nitransforms._version", None)

def _dist(name):
Distribution = namedtuple("Distribution", ["name", "version"])
return Distribution(name, "success")

monkeypatch.setattr("pkg_resources.get_distribution", _dist)
reload(nitransforms)
assert nitransforms.__version__ == "success"


def test_version_scm2(monkeypatch):
def test_version_fallback(monkeypatch):
"""Check version could not be interpolated."""
monkeypatch.setitem(sys.modules, "nitransforms._version", None)

def _raise(name):
raise DistributionNotFound("No get_distribution mock")

monkeypatch.setattr("pkg_resources.get_distribution", _raise)
reload(nitransforms)
assert nitransforms.__version__ == "unknown"
assert nitransforms.__version__ == "0+unknown"