Skip to content

Commit 9919a22

Browse files
feat: Resolve version from pip (#83)
* feat: Make versioning resolve with importlib * feat: Add __version__ * test: Ensure version can be accessed and follows semver Signed-off-by: AlexNg <contact@ngjx.org>
1 parent 9ed8426 commit 9919a22

File tree

8 files changed

+69
-13
lines changed

8 files changed

+69
-13
lines changed

poetry.lock

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ thread = "thread.__main__:app"
4242
[tool.poetry.dependencies]
4343
python = "^3.9"
4444
typing-extensions = "^4.9.0"
45-
45+
importlib-metadata = { version = ">=4.4", python = "<3.10" }
4646

4747
[tool.poetry.group.dev.dependencies]
4848
pytest = "^7.4.3"

ruff.toml

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ docstring-quotes = "double"
5151
# Ignore `E402` (import violations) in all `__init__.py` files, and in select subdirectories.
5252
[lint.per-file-ignores]
5353
"__init__.py" = ["E402", "F401"]
54+
"__version__.py" = ["F401"]
5455
"**/__init__.py" = ["E402", "F401"]
5556
"**/{tests,docs,tools}/*" = ["E402"]

src/thread/__init__.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,20 @@
1717
```
1818
"""
1919

20+
from .version import __version__
2021

21-
__version__ = '2.0.1'
22-
23-
24-
# Export Core
25-
from .thread import Thread, ConcurrentProcessing
26-
27-
28-
from . import _types as types, exceptions
29-
22+
from . import _types as types
23+
from . import exceptions
3024

3125
# Export decorators
32-
from .decorators import threaded, processor
26+
from .decorators import processor, threaded
3327

28+
# Export Core
29+
from .thread import ConcurrentProcessing, Thread
3430

3531
# Configuration
3632
from .utils import Settings
3733

38-
3934
# Wildcard Export
4035
__all__ = [
4136
'Thread',

src/thread/__version__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .version import __version__

src/thread/utils/meta.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
3+
# compatibility for python <3.10
4+
if sys.version_info < (3, 10):
5+
import importlib_metadata as metadata
6+
else:
7+
from importlib import metadata
8+
9+
__all__ = ['metadata']

src/thread/version.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .utils.meta import metadata
2+
3+
__version__ = metadata.version('thread')
4+
__all__ = ['__version__']

tests/library/test_version.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
import thread
3+
4+
5+
def test_versionIsString():
6+
assert isinstance(thread.__version__, str), 'thread.__version__ is not a string'
7+
8+
9+
def test_versionIsSemVer():
10+
assert re.match(
11+
r'^\d+\.\d+\..+$', thread.__version__
12+
), 'thread.__version__ is not a semver'

0 commit comments

Comments
 (0)