Skip to content

Commit 0cc1c4d

Browse files
authored
Add git version suffix to package name (#547)
* Add git version suffix to package name * push
1 parent 00b76c4 commit 0cc1c4d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

setup.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
import os
77
import glob
88
from datetime import datetime
9+
import subprocess
910

1011
from setuptools import find_packages, setup
1112

1213
current_date = datetime.now().strftime("%Y.%m.%d")
1314

15+
16+
def get_git_commit_id():
17+
try:
18+
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
19+
except Exception:
20+
return ""
21+
1422
def read_requirements(file_path):
1523
with open(file_path, "r") as file:
1624
return file.read().splitlines()
@@ -21,7 +29,12 @@ def read_version(file_path="version.txt"):
2129

2230
# Determine the package name based on the presence of an environment variable
2331
package_name = "torchao-nightly" if os.environ.get("TORCHAO_NIGHTLY") else "torchao"
24-
version_suffix = os.getenv("VERSION_SUFFIX", "")
32+
33+
# Use Git commit ID if VERSION_SUFFIX is not set
34+
version_suffix = os.getenv("VERSION_SUFFIX")
35+
if version_suffix is None:
36+
version_suffix = f"+git{get_git_commit_id()}"
37+
2538
use_cpp = os.getenv('USE_CPP')
2639

2740

0 commit comments

Comments
 (0)