Skip to content

Commit 995b152

Browse files
committed
adapt versioning info to use saved_version.py when present, git_verinfo.py when not
1 parent d35bb5b commit 995b152

File tree

8 files changed

+151
-59
lines changed

8 files changed

+151
-59
lines changed

GSASII/GSASIIGUI.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
#GSASII
3+
#GSASIIGUI
44
'''
5+
This provides a short file that is used to start the GSAS-II GUI
6+
57
A single class, :class:`G2App`, is defined here to create
6-
an wxPython application. This is only used on
8+
a wxPython application. This is only used on
79
MacOS. For other platforms ``wx.App()`` is called directly.
810
'''
911

@@ -12,15 +14,12 @@
1214
from . import GSASIIpath
1315

1416
__version__ = '5.0.0'
15-
try:
16-
from . import git_verinfo
17-
if len(git_verinfo.git_tags):
18-
__version__ = git_verinfo.git_tags[0]
19-
elif len(git_verinfo.git_prevtags):
20-
__version__ = git_verinfo.git_prevtags[0]
21-
except ImportError:
22-
pass
23-
17+
gv = GSASIIpath.getSavedVersionInfo()
18+
if gv is not None:
19+
if len(gv.git_tags):
20+
__version__ = gv.git_tags[0]
21+
elif len(gv.git_prevtags):
22+
__version__ = gv.git_prevtags[0]
2423

2524
def main():
2625
import scipy.optimize # loading here addresses problem with build for wx on Pi

GSASII/GSASIImiscGUI.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,20 +695,21 @@ def ProjFileSave(G2frame):
695695
return
696696
print ('save to file: '+G2frame.GSASprojectfile)
697697
# stick the file name into the tree and version info into tree so they are saved.
698-
# (Controls should always be created at this point)
698+
# (Controls should always have been created in tree at this point)
699699
try:
700700
Controls = G2frame.GPXtree.GetItemPyData(
701701
G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
702702
Controls['PythonVersions'] = G2frame.PackageVersions
703703
Controls['LastSavedAs'] = os.path.abspath(G2frame.GSASprojectfile)
704-
Controls['LastSavedUsing'] = str(GSASIIpath.GetVersionNumber())
704+
Controls['LastSavedUsing'] = f"#{GSASIIpath.GetVersionNumber()}, {GSASIIpath.GetVersionTag()}"
705705
if GSASIIpath.HowIsG2Installed().startswith('git'):
706706
g2repo = GSASIIpath.openGitRepo(GSASIIpath.path2GSAS2)
707707
commit = g2repo.head.commit
708708
Controls['LastSavedUsing'] += f" git {commit.hexsha[:8]}"
709709
else:
710-
from . import git_verinfo as gv
711-
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
710+
gv = getSavedVersionInfo()
711+
if gv is not None:
712+
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
712713
except:
713714
pass
714715
wx.BeginBusyCursor()

GSASII/GSASIIpath.py

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
210236
def 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

242292
def 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\tThis 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
#==============================================================================

GSASII/GSASIIpwd.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@
2727
from . import GSASIIpath
2828
GSASIIpath.SetBinaryPath()
2929

30-
filversion = "?"
31-
try:
32-
import git_verinfo
33-
filversion = git_verinfo.git_tags[0]
34-
if not filversion: filversion = git_verinfo.git_prevtags[0]
35-
except:
36-
pass
30+
filversion = str(GSASIIpath.GetVersionNumber())
3731
from . import GSASIIlattice as G2lat
3832
from . import GSASIIspc as G2spc
3933
from . import GSASIIElem as G2elem

GSASII/GSASIIscriptable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,9 @@ def save(self, filename=None):
913913
commit = g2repo.head.commit
914914
controls_data['LastSavedUsing'] += f" git {commit.hexsha[:8]} script"
915915
else:
916-
from . import git_verinfo as gv
917-
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
916+
gv = getSavedVersionInfo()
917+
if gv is not None:
918+
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
918919
except:
919920
pass
920921
# .gpx name
File renamed without changes.

docs/source/versioning.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ To assign a new integer tag number (and increment the minor version number), use
3636

3737
This script is used when there are significant changes (possibly cumulative) to the
3838
code and a new release should be tagged both with a new integer tag number and
39-
minor version number. It updates the `git_verinfo.py` version file so that non-git
40-
installs of GSAS-II can report the currect version number.
39+
minor version number. It updates the `git_verinfo.py` version file so that
40+
GSAS-II can quickly report the current version numbers.
4141

4242
To increment only the mini version number, use script:
4343

4444
`.../GSASII/install/incr-mini-version.py`
4545

4646
This script is used when the have been minor changes made in GSAS-II and
4747
the changes warrent an update (for example, due to a bug fix). This cannot be used
48-
when an integer tag number has been assigned to the
49-
current GSAS-II commit code.
48+
when a new integer tag number has been assigned to the
49+
current GSAS-II commit.
50+
It also updates the `git_verinfo.py` version file so that
51+
GSAS-II can quickly report the current version numbers.
5052

5153
`.../GSASII/install/save-versions.py`
5254

53-
This script is used to save the latest version info in the `git_verinfo.py` file.
54-
No tags or release version numbers are created.
55+
This script is used to save the latest version info in the `saved_version.py` file.
56+
This file is created when a non-git install is made for GSAS-II so that the
57+
hash number for the current git version (which cannot be
58+
placed into the `git_verinfo.py` file) is recorded.
59+
The `save-versions.py` script does not change any tags or release version numbers.
5560

5661

5762
History

tests/run_pypowder.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# compute a single peak with pypowder
2+
import os
3+
import sys
4+
import importlib.util
5+
import numpy as np
6+
7+
home = os.path.dirname(__file__)
8+
G2loc = None
9+
try:
10+
G2loc = importlib.util.find_spec('GSASII.GSASIIscriptable')
11+
except ModuleNotFoundError:
12+
print('ModuleNotFound for GSASII.GSASIIscriptable')
13+
14+
if G2loc is None: # fixup path if GSASII not installed into Python
15+
print('GSAS-II not installed in Python; Hacking sys.path')
16+
sys.path.append(os.path.dirname(home))
17+
18+
from GSASII import GSASIIpath
19+
GSASIIpath.SetBinaryPath()
20+
21+
if GSASIIpath.binaryPath:
22+
import pypowder as pyd
23+
else:
24+
from . import pypowder as pyd
25+
26+
# these values generate a nearly symmetric peak
27+
xdata = np.arange(18,22,.05)
28+
pos = 20.
29+
sig = 525.9994695543994
30+
gam = 2.1444606947716025
31+
shl = 0.002
32+
ydata = pyd.pypsvfcjo(len(xdata),xdata-pos,pos,sig,gam,shl)
33+
34+
# these values generate a peak with significant low-angle broadening
35+
#xdata = np.arange(0.1,5,.05)
36+
#pos = 2
37+
#sig = 525.9994695543994
38+
#gam = 2.1444606947716025
39+
#shl = 0.035
40+
#ydata = pyd.pypsvfcjo(len(xdata),xdata-pos,pos,sig,gam,shl)
41+
42+
import matplotlib.pyplot as plt
43+
plt.plot(xdata,ydata)
44+
plt.show()
45+

0 commit comments

Comments
 (0)