__init__.py 684 Bytes
Newer Older
1
import subprocess
Shaoshuai Shi's avatar
Shaoshuai Shi committed
2
from pathlib import Path
3

4
5
from packaging import version

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from .version import __version__

__all__ = [
    '__version__'
]


def get_git_commit_number():
    if not (Path(__file__).parent / '../.git').exists():
        return '0000000'

    cmd_out = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
    git_commit_number = cmd_out.stdout.decode('utf-8')[:7]
    return git_commit_number


script_version = get_git_commit_number()


if script_version not in __version__:
    __version__ = __version__ + '+py%s' % script_version
27
28
29
30


def v1_is_lower_than_v2(version1: str, version2: str):
    return version.parse(version1) < version.parse(version2)