/
_version.py
32 lines (25 loc) · 938 Bytes
/
_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Definition of the version number
try:
from ._utils import _sh
except StandardError: # pragma: no cover
_sh = None
from subprocess import STDOUT
__all__ = ["__version__"]
# major, minor, patch, -extra
version_info = 4, 9, 0
# Nice string for the version
__version__ = '.'.join(map(str, version_info))
# auto -extra based on commit hash (if not tagged as release)
if (_sh is not None) and (len(version_info) < 4): # pragma: no cover
def commit_hash(*args):
try:
res = _sh('git', 'log', '-n', '1', '--oneline', *args,
stderr=STDOUT).lstrip().split()[0]
return None if res.startswith('fatal') else res
except:
return None
cur_hash = commit_hash()
if cur_hash is not None:
last_release = commit_hash('v' + __version__)
if (last_release is None) or (cur_hash not in last_release):
__version__ += '-' + cur_hash