|
1 | 1 | import os |
2 | 2 | import re |
| 3 | +import subprocess |
3 | 4 | import sys |
4 | 5 | from functools import lru_cache |
5 | 6 | from io import open |
|
15 | 16 | except Exception as error: |
16 | 17 | assert False, "Error: Could not open '%s' due %s\n" % (filepath, error) |
17 | 18 |
|
18 | | -version = __version__ |
19 | | - |
20 | 19 | # All BUILD_* flags are initially set to `False`` and |
21 | 20 | # will be updated to `True` if the corresponding environment check passes. |
22 | 21 | PYPI_RELEASE = os.environ.get("PYPI_RELEASE", None) |
23 | 22 | BUILD_HPU_ONLY = os.environ.get("BUILD_HPU_ONLY", "0") == "1" |
24 | 23 |
|
25 | 24 |
|
| 25 | +def is_commit_on_tag(): |
| 26 | + try: |
| 27 | + result = subprocess.run( |
| 28 | + ["git", "describe", "--exact-match", "--tags"], capture_output=True, text=True, check=True |
| 29 | + ) |
| 30 | + tag_name = result.stdout.strip() |
| 31 | + return tag_name |
| 32 | + except subprocess.CalledProcessError: |
| 33 | + return False |
| 34 | + |
| 35 | + |
| 36 | +def get_build_version(): |
| 37 | + if is_commit_on_tag(): |
| 38 | + return __version__ |
| 39 | + try: |
| 40 | + result = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True, check=True) |
| 41 | + distance = result.stdout.strip().split("-")[-2] |
| 42 | + commit = result.stdout.strip().split("-")[-1] |
| 43 | + return f"{__version__}.dev{distance}+{commit}" |
| 44 | + except subprocess.CalledProcessError: |
| 45 | + return __version__ |
| 46 | + |
| 47 | + |
26 | 48 | @lru_cache(None) |
27 | 49 | def is_habana_framework_installed(): |
28 | 50 | """Check if Habana framework is installed. |
@@ -143,7 +165,7 @@ def fetch_requirements(path): |
143 | 165 | setup( |
144 | 166 | name=package_name, |
145 | 167 | author="Intel AIPT Team", |
146 | | - version=version, |
| 168 | + version=get_build_version(), |
147 | 169 | author_email="wenhua.cheng@intel.com, weiwei1.zhang@intel.com, heng.guo@intel.com", |
148 | 170 | description="Repository of AutoRound: Advanced Weight-Only Quantization Algorithm for LLMs", |
149 | 171 | long_description=open("README.md", "r", encoding="utf-8").read(), |
|
0 commit comments