Skip to content

Commit 7bc0779

Browse files
authored
MAINT: Remove any imports from __init__ (hide __version__) (#38)
The helpers were just not needed and should be private. `__version__` is a bit awkard and probably not quite right. Hiding it seems good to me, I also changed it to look-up via `__name__`. The thing is, I would like to vendor it, and then looking up `spatch` is wrong and can fail. Looking up `__name__` may not actually be any better, but for now I'll assume it is better than what we have. Not sure if this matters either way, if it does we might have to find a better solution...
1 parent 551f997 commit 7bc0779

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/spatch/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
from .utils import from_identifier, get_identifier, get_project_version
1+
def __getattr__(name):
2+
if name == "__version__":
3+
from .utils import get_project_version
24

3-
__version__ = get_project_version("spatch")
5+
return get_project_version(__name__)
6+
7+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

tests/test_general.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import spatch
2+
3+
4+
def test___version__():
5+
# Sanity check that __version__ exists and returns
6+
# something that faintly looks like a version string.
7+
v = spatch.__version__
8+
major, minor, *rest = v.split(".")
9+
assert major.isdigit()
10+
assert minor.isdigit()

0 commit comments

Comments
 (0)