Skip to content

Commit ff12b2a

Browse files
author
jax authors
committed
Merge pull request #20685 from olupton:no-git-describe
PiperOrigin-RevId: 623515694
2 parents c7b7b01 + b27b774 commit ff12b2a

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

jax/version.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,15 @@ def _version_from_git_tree(base_version: str) -> str | None:
4747
try:
4848
root_directory = os.path.dirname(os.path.realpath(__file__))
4949

50-
# Get date string from date of most recent git commit.
51-
p = subprocess.Popen(["git", "show", "-s", "--format=%at", "HEAD"],
50+
# Get date string from date of most recent git commit, and the abbreviated
51+
# hash of that commit.
52+
p = subprocess.Popen(["git", "show", "-s", "--format=%at-%h", "HEAD"],
5253
cwd=root_directory,
5354
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
5455
stdout, _ = p.communicate()
55-
timestamp = int(stdout.decode().strip())
56-
datestring = datetime.date.fromtimestamp(timestamp).strftime("%Y%m%d")
56+
timestamp, commit_hash = stdout.decode().strip().split('-', 1)
57+
datestring = datetime.date.fromtimestamp(int(timestamp)).strftime("%Y%m%d")
5758
assert datestring.isnumeric()
58-
59-
# Get commit hash from most recent git commit.
60-
p = subprocess.Popen(["git", "describe", "--long", "--always"],
61-
cwd=root_directory,
62-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
63-
stdout, _ = p.communicate()
64-
commit_hash = stdout.decode().strip().rsplit('-g', 1)[-1]
6559
assert commit_hash.isalnum()
6660
except:
6761
return None

0 commit comments

Comments
 (0)