Skip to content

Commit 9314d05

Browse files
authored
Reuse a pre-existing version_tuple from SCM (#736)
Co-authored-by: Abhinav Singh <[email protected]>
2 parents 5de3458 + 8ca0421 commit 9314d05

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

proxy/common/_scm_version.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# This stub file is necessary because `_scm_version.py`
22
# autogenerated on build and absent on mypy checks time
3+
from typing import Tuple, Union
4+
35
version: str
6+
version_tuple: Tuple[Union[int, str], ...]

proxy/common/_version.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,34 @@
1010
1111
Version definition.
1212
"""
13+
from typing import Tuple, Union
14+
1315
try:
1416
# pylint: disable=unused-import
15-
from ._scm_version import version as __version__ # noqa: WPS433, WPS436
17+
from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436
1618
except ImportError:
1719
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
1820
__version__ = _get_dist('proxy.py').version # noqa: WPS440
1921

2022

21-
__all__ = ('__version__',)
23+
def _to_int_or_str(inp: str) -> Union[int, str]:
24+
try:
25+
return int(inp)
26+
except ValueError:
27+
return inp
28+
29+
30+
def _split_version_parts(inp: str) -> Tuple[str, ...]:
31+
public_version, _plus, local_version = inp.partition('+')
32+
return (*public_version.split('.'), local_version)
33+
34+
35+
try:
36+
VERSION = _ver_tup
37+
except NameError:
38+
VERSION = tuple(
39+
map(_to_int_or_str, _split_version_parts(__version__)),
40+
)
41+
42+
43+
__all__ = '__version__', 'VERSION'

proxy/common/version.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,7 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from typing import Tuple, Union
12-
13-
from ._version import __version__ # noqa: WPS436
14-
15-
16-
def _to_int_or_str(inp: str) -> Union[int, str]:
17-
try:
18-
return int(inp)
19-
except ValueError:
20-
return inp
21-
22-
23-
def _split_version_parts(inp: str) -> Tuple[str, ...]:
24-
public_version, _plus, local_version = inp.partition('+')
25-
return (*public_version.split('.'), local_version)
26-
27-
28-
VERSION = tuple(map(_to_int_or_str, _split_version_parts(__version__)))
11+
from ._version import __version__, VERSION # noqa: WPS436
2912

3013

3114
__all__ = '__version__', 'VERSION'

0 commit comments

Comments
 (0)