@@ -207,39 +207,90 @@ def HowIsG2Installed():
207207 G2_installed_result = 'noVCS'
208208 return G2_installed_result
209209
210+ def getSavedVersionInfo ():
211+ '''Get version number information from a file written by install
212+ routines. This is faster than getting the information from git. Also,
213+ when GSAS-II is installed into Python, the files are no longer in
214+ a git repository so querying git is not possible.
215+
216+ The saved_version.py file is written by install/save_versions.py.
217+ The git_verinfo.py file is written by install/tag-version.py or
218+ by install/incr-mini-version.py. If both are present, use the
219+ saved_version.py file preferentially.
220+
221+ :returns: a reference to the version variables or None if no
222+ version info file is found.
223+ '''
224+ try :
225+ from . import saved_version as gv
226+ return gv
227+ except :
228+ pass
229+ try :
230+ from . import git_verinfo as gv
231+ return gv
232+ except :
233+ pass
234+ return None # this is unexpected as all dists should have git_verinfo.py
235+
210236def GetVersionNumber ():
211- '''Obtain a version number for GSAS-II from git or from the
212- files themselves, if no other choice.
237+ '''Obtain a numeric (sequential) version number for GSAS-II from version
238+ files, or directly from git if no other choice.
213239
214- :returns: an int value usually, but a value of 'unknown' might occur
240+ :returns: an int value normally, but unexpected error conditions could result in
241+ a value of 'unknown' or '?'.
215242 '''
243+ # look for a previously recorded tag -- this is quick
244+ gv = getSavedVersionInfo ()
245+ if gv is not None :
246+ for item in gv .git_tags + gv .git_prevtags :
247+ if item .isnumeric (): return int (item )
248+
216249 if HowIsG2Installed ().startswith ('git' ):
217- # look for a recorded tag -- this is quick
250+ # unexpected: should always find a version from getSavedVersionInfo()
251+ # from a version file, but if that fails ask Git for the most
252+ # recent tag that starts & ends with a digit and does not contain a '.'
218253 try :
219- from . import git_verinfo as gv
220- for item in gv .git_tags + gv .git_prevtags :
221- if item .isnumeric (): return int (item )
254+ g2repo = openGitRepo (path2GSAS2 )
255+ tag ,vers ,gnum = g2repo .git .describe ('--tags' ,'--match' ,'[0-9]*[0-9]' ,
256+ '--exclude' ,'*.*' ).split ('-' )
257+ if tag .isnumeric (): return int (tag )
222258 except :
223259 pass
224- # no luck, ask Git for the most recent tag (must start & end with a number)
260+ return "unknown"
261+
262+ # Not installed from git and no version file -- very strange!
263+ return "?"
264+
265+ def GetVersionTag ():
266+ '''Obtain a release (X.Y.Z) version number for GSAS-II from version
267+ files, or directly from git if no other choice.
268+
269+ :returns: a string of form <Major>.<Minor>.<mini> normally, but unexpected
270+ error conditions could result in a value of '?.?.?' or '?'.
271+ '''
272+ # look for a previously recorded tag -- this is quick
273+ gv = getSavedVersionInfo ()
274+ if gv is not None :
275+ if '?' not in gv .git_versiontag : return gv .git_versiontag
276+
277+ if HowIsG2Installed ().startswith ('git' ):
278+ # unexpected: should always find a version from getSavedVersionInfo()
279+ # from a version file, but if that fails ask Git for the most
280+ # recent tag that has the X.Y.Z format.
225281 try :
226282 g2repo = openGitRepo (path2GSAS2 )
227- tag ,vers ,gnum = g2repo .git .describe ('--tags' ,'--match' ,'[0-9]*[0-9] ' ).split ('-' )
228- if tag . isnumeric (): return int ( tag )
283+ tag ,vers ,gnum = g2repo .git .describe ('--tags' ,'--match' ,'*.*.* ' ).split ('-' )
284+ return tag
229285 except :
230286 pass
231- return "unknown "
287+ return "?.?.? "
232288
233- # No luck asking, look up version information from git_verinfo.py
234- try :
235- from . import git_verinfo as gv
236- for item in gv .git_tags + gv .git_prevtags :
237- if item .isnumeric (): return int (item )
238- except :
239- pass
240- return "unknown"
289+ # Not installed from git and no version file -- very strange!
290+ return "?"
241291
242292def getG2VersionInfo ():
293+ gv = getSavedVersionInfo ()
243294 if HowIsG2Installed ().startswith ('git' ):
244295 g2repo = openGitRepo (path2GSAS2 )
245296 commit = g2repo .head .commit
@@ -248,7 +299,7 @@ def getG2VersionInfo():
248299 tzinfo = commit .committed_datetime .tzinfo )
249300 delta = now - commit .committed_datetime
250301 age = delta .total_seconds ()/ (60 * 60 * 24. )
251- gversion = f"Tag: #{ GetVersionNumber ()} "
302+ gversion = f"Tag: #{ GetVersionNumber ()} , { GetVersionTag () } "
252303 msg = ''
253304 if g2repo .head .is_detached :
254305 msg = ("\n " +
@@ -270,16 +321,12 @@ def getG2VersionInfo():
270321 elif len (rc ) > 0 :
271322 msg += f"\n \t This GSAS-II version is ~{ len (rc )} updates behind current."
272323 return f" GSAS-II: { commit .hexsha [:8 ]} , { ctim } ({ age :.1f} days old). { gversion } { msg } "
273- else :
274- try :
275- from . import git_verinfo as gv
276- for item in gv .git_tags + gv .git_prevtags :
277- if item .isnumeric ():
278- return f"GSAS-II version: Git: { gv .git_version [:8 ]} , #{ item } (installed without update capability)"
279- except :
280- pass
324+ elif gv is not None :
325+ for item in gv .git_tags + gv .git_prevtags :
326+ if item .isnumeric ():
327+ return f"GSAS-II version: Git: { gv .git_version [:8 ]} , #{ item } (installed without update capability)"
281328 # Failed to get version info, fallback on old version number routine
282- return f"GSAS-II installed without git, last tag: { GetVersionNumber ()} "
329+ return f"GSAS-II installed without git, last tag: # { GetVersionNumber () } , { GetVersionTag ()} "
283330
284331#==============================================================================
285332#==============================================================================
0 commit comments