@@ -12,13 +12,17 @@ import subprocess
1212import tempfile
1313
1414
15- def get_version (ref ):
15+ def get_version (ref , prefer_recomputation = False ):
16+ branch , hash , git_version = None , None , None
17+
1618 if os .path .exists ("VERSION" ):
1719 with open ("VERSION" , "r" ) as info :
18- hash = info .readline ().split ("=" )[1 ].strip ()
1920 branch = info .readline ().split ("=" )[1 ].strip ()
21+ hash = info .readline ().split ("=" )[1 ].strip ()
2022 git_version = info .readline ().split ("=" )[1 ].strip ()
21- return hash , branch , git_version
23+
24+ if not prefer_recomputation :
25+ return hash , branch , git_version
2226
2327 if subprocess .call (
2428 ["git" , "rev-parse" , "--git-dir" ],
@@ -51,10 +55,12 @@ def get_version(ref):
5155 git_version = re .sub (
5256 r"-([0-9]*)-g[0-9a-z]*" , r".\1" , re .sub (r"^v" , "" , raw_git_version )
5357 ).strip ()
54- return hash , branch , git_version
5558
56- print ("Cannot extract version information: neither VERSION file nor git repository present" )
57- exit (1 )
59+ if not any ([hash , branch , git_version ]):
60+ print ("Cannot extract version information: neither VERSION file nor git repository present" )
61+ exit (1 )
62+
63+ return hash , branch , git_version
5864
5965
6066def write_if_changed (target , txt ):
@@ -110,7 +116,8 @@ os.chdir(
110116 if options .git_root
111117 else os .path .join (os .path .dirname (__file__ ), ".." )
112118)
113- chash , branch , git_version = get_version (options .commit )
119+ chash , branch , git_version = get_version (
120+ ref = options .commit , prefer_recomputation = options .store )
114121
115122# When running from CI, for geting the branch name we prefer what
116123# might be passed in through environment variables as we may not
@@ -137,7 +144,6 @@ elif re.match("release.*", branch) or not branch:
137144 prerelease = commit
138145else :
139146 prerelease = "branch"
140- chash = ""
141147
142148on_release_tag = subprocess .call (
143149 ["git" , "describe" , "--tags" , "--match" , "v*" , "--exact-match" ],
0 commit comments