Skip to content

Commit 0286251

Browse files
committed
Improve version tracking; remove unneeded menu items if installed into Python w/o git
1 parent 7ec0540 commit 0286251

File tree

9 files changed

+178
-126
lines changed

9 files changed

+178
-126
lines changed

GSASII/GSASIIGUI.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
try:
1616
from . import git_verinfo
1717
__version__ = git_verinfo.git_tags[0]
18+
if not __version__: __version__ = git_verinfo.git_prevtags[0]
1819
except ImportError:
1920
pass
2021

GSASII/GSASIIctrlGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,7 @@ def __init__(self,frame,includeTree=False,morehelpitems=[]):
56485648
self.Append(wx.ID_ABOUT,'&About GSAS-II',
56495649
'Shows version and citation info')
56505650
frame.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
5651-
if GSASIIpath.HowIsG2Installed():
5651+
if GSASIIpath.HowIsG2Installed().startswith('git'):
56525652
helpobj = self.Append(wx.ID_ANY,'&Check for updates\tCtrl+U',
56535653
'Updates to latest GSAS-II version')
56545654
if os.access(GSASIIpath.path2GSAS2, os.W_OK):

GSASII/GSASIIdataGUI.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def compareVersions(version1,version2):
362362
'versions of modules that are known to have bugs'
363363
versionDict['tooNewWarn'] = {}
364364
'module versions newer than what we have tested & where problems are suspected'
365-
versionDict['tooNewUntested'] = {'Python':'3.12','wx': '4.2.3'}
365+
versionDict['tooNewUntested'] = {'Python':'3.14','wx': '4.2.3'}
366366
'module versions newer than what we have tested but no problems are suspected'
367367

368368
def ShowVersions():
@@ -454,20 +454,21 @@ def ShowVersions():
454454
print(GSASIIpath.getG2VersionInfo())
455455

456456
# warn if problems with Git
457-
try:
458-
import git
459-
except ImportError as msg:
460-
if 'Failed to initialize' in msg.msg:
461-
print('The gitpython package is unable to locate a git installation.')
462-
print('See https://gsas-ii.readthedocs.io/en/latest/packages.html for more information.')
463-
elif 'No module' in msg.msg:
464-
print('Warning: Python gitpython module not installed')
465-
else:
466-
print(f'gitpython failed to import, but why? Error:\n{msg}')
467-
print('Note: git and gitpython are required for GSAS-II to self-update')
468-
except Exception as msg:
469-
print(f'git import failed with unexpected error:\n{msg}')
470-
print('Note: git and gitpython are required for GSAS-II to self-update')
457+
if GSASIIpath.HowIsG2Installed().startswith('git'):
458+
try:
459+
import git
460+
except ImportError as msg:
461+
if 'Failed to initialize' in msg.msg:
462+
print('The gitpython package is unable to locate a git installation.')
463+
print('See https://gsas-ii.readthedocs.io/en/latest/packages.html for more information.')
464+
elif 'No module' in msg.msg:
465+
print('Warning: Python gitpython module not installed')
466+
else:
467+
print(f'gitpython failed to import, but why? Error:\n{msg}')
468+
print('Note: git and gitpython are required for GSAS-II to self-update')
469+
except Exception as msg:
470+
print(f'git import failed with unexpected error:\n{msg}')
471+
print('Note: git and gitpython are required for GSAS-II to self-update')
471472

472473
# warn if problems with requests package
473474
try:
@@ -656,8 +657,10 @@ def OnwxInspect(event):
656657
item = parent.Append(wx.ID_ANY,'Reopen current\tCtrl+0','Reread the current GSAS-II project (.gpx) file')
657658
self.Bind(wx.EVT_MENU, self.OnFileReread, id=item.GetId())
658659

659-
item = parent.Append(wx.ID_ANY,"Install GSASIIscriptable shortcut",'')
660-
self.Bind(wx.EVT_MENU,
660+
# if Git install assume GSAS-II was not installed into Python
661+
if GSASIIpath.HowIsG2Installed().startswith('git'):
662+
item = parent.Append(wx.ID_ANY,"Install GSASIIscriptable shortcut",'')
663+
self.Bind(wx.EVT_MENU,
661664
lambda event: GSASIIpath.makeScriptShortcut(),
662665
item)
663666

GSASII/GSASIImiscGUI.py

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

GSASII/GSASIIpath.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,9 @@ def GetVersionNumber():
208208
if HowIsG2Installed().startswith('git'):
209209
# look for a recorded tag -- this is quick
210210
try:
211-
import git_verinfo as gv
212-
try:
213-
for item in gv.git_tags:
214-
if item.isnumeric(): return int(item)
215-
except:
216-
pass
217-
try:
218-
for item in gv.git_prevtags:
219-
if item.isnumeric(): return int(item)
220-
except:
221-
pass
211+
from . import git_verinfo as gv
212+
for item in gv.git_tags+gv.git_prevtags:
213+
if item.isnumeric(): return int(item)
222214
except:
223215
pass
224216
# no luck, ask Git for the most recent tag (must start & end with a number)
@@ -232,20 +224,11 @@ def GetVersionNumber():
232224

233225
# No luck asking, look up version information from git_verinfo.py
234226
try:
235-
import git_verinfo as gv
236-
try:
237-
for item in gv.git_tags:
238-
if item.isnumeric(): return int(item)
239-
except:
240-
pass
241-
try:
242-
for item in gv.git_prevtags:
243-
if item.isnumeric(): return int(item)
244-
except:
245-
pass
227+
from . import git_verinfo as gv
228+
for item in gv.git_tags+gv.git_prevtags:
229+
if item.isnumeric(): return int(item)
246230
except:
247231
pass
248-
249232
return "unknown"
250233

251234
def getG2VersionInfo():
@@ -278,21 +261,17 @@ def getG2VersionInfo():
278261
msg += f"\n\t**** Please consider updating. >= {len(rc)} updates have been posted"
279262
elif len(rc) > 0:
280263
msg += f"\n\tThis GSAS-II version is ~{len(rc)} updates behind current."
281-
return f" GSAS-II: {commit.hexsha[:6]}, {ctim} ({age:.1f} days old). {gversion}{msg}"
264+
return f" GSAS-II: {commit.hexsha[:8]}, {ctim} ({age:.1f} days old). {gversion}{msg}"
282265
else:
283266
try:
284-
import git_verinfo as gv
285-
if gv.git_tags:
286-
msg = f"{' '.join(gv.git_tags)}, Git: {gv.git_version[:6]}"
287-
else:
288-
msg = (f"{gv.git_version[:6]}; "+
289-
f"Prev ver: {' '.join(gv.git_prevtags)}"+
290-
f", {gv.git_prevtaggedversion[:6]}")
291-
return f"GSAS-II version: {msg} (Manual update)"
267+
from . import git_verinfo as gv
268+
for item in gv.git_tags+gv.git_prevtags:
269+
if item.isnumeric():
270+
return f"GSAS-II version: Git: {gv.git_version[:8]}, #{item} (installed without update capability)"
292271
except:
293272
pass
294-
# all else fails, use the old version number routine
295-
return f"GSAS-II installed manually, last revision: {GetVersionNumber()}"
273+
# Failed to get version info, fallback on old version number routine
274+
return f"GSAS-II installed without git, last tag: {GetVersionNumber()}"
296275

297276
#==============================================================================
298277
#==============================================================================
@@ -1495,6 +1474,9 @@ def makeScriptShortcut():
14951474
indicates an error.
14961475
'''
14971476
import datetime as dt
1477+
if not HowIsG2Installed().startswith('git'):
1478+
print('GSAS-II installed directly, shortcut likely not needed')
1479+
return None
14981480
for p in sys.path:
14991481
if 'site-packages' in p: break
15001482
else:

GSASII/GSASIIpwd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
try:
3232
import git_verinfo
3333
filversion = git_verinfo.git_tags[0]
34+
if not filversion: filversion = git_verinfo.git_prevtags[0]
3435
except:
3536
pass
3637
from . import GSASIIlattice as G2lat

GSASII/GSASIIscriptable.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,16 @@ def save(self, filename=None):
907907
controls_data['PythonVersions'] = G2fil.get_python_versions(modList)
908908
# G2 version info
909909
controls_data['LastSavedUsing'] = str(GSASIIpath.GetVersionNumber())
910-
if GSASIIpath.HowIsG2Installed().startswith('git'):
911-
try:
910+
try:
911+
if GSASIIpath.HowIsG2Installed().startswith('git'):
912912
g2repo = GSASIIpath.openGitRepo(GSASIIpath.path2GSAS2)
913913
commit = g2repo.head.commit
914-
controls_data['LastSavedUsing'] += f" git {commit.hexsha[:6]} script"
915-
except:
916-
pass
914+
controls_data['LastSavedUsing'] += f" git {commit.hexsha[:8]} script"
915+
else:
916+
from . import git_verinfo as gv
917+
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
918+
except:
919+
pass
917920
# .gpx name
918921
if filename:
919922
filename = os.path.abspath(os.path.expanduser(filename))

GSASII/install/save-versions.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# record tag number and git hash into the git_version.py file.
2+
#
3+
import os
4+
import sys
5+
import datetime as dt
6+
import git
7+
8+
# get location of the GSAS-II files
9+
# assumed to be the parent of location of this file
10+
path2GSAS2 = os.path.dirname(os.path.dirname(
11+
os.path.abspath(os.path.expanduser(__file__))))
12+
# and the repo is in the parent of that
13+
path2repo = os.path.dirname(path2GSAS2)
14+
15+
if __name__ == '__main__':
16+
17+
g2repo = git.Repo(path2repo)
18+
# if g2repo.active_branch.name != 'master':
19+
# print(f'Not on master branch {commit0[:6]!r}')
20+
# sys.exit()
21+
if g2repo.head.is_detached:
22+
print(f'Detached head {commit0[:6]!r}')
23+
sys.exit()
24+
# create a file with GSAS-II version information
25+
try:
26+
g2repo = git.Repo(path2repo)
27+
except:
28+
print('Launch of gitpython for version file failed'+
29+
f' with path {path2repo}')
30+
sys.exit()
31+
commit = g2repo.head.commit
32+
ctim = commit.committed_datetime.strftime('%d-%b-%Y %H:%M')
33+
now = dt.datetime.now().replace(
34+
tzinfo=commit.committed_datetime.tzinfo)
35+
commit0 = commit.hexsha
36+
tags0 = g2repo.git.tag('--points-at',commit).split('\n')
37+
history = list(g2repo.iter_commits('HEAD'))
38+
for i in history[1:]:
39+
tags = g2repo.git.tag('--points-at',i)
40+
if not tags: continue
41+
commitm1 = i.hexsha
42+
tagsm1 = tags.split('\n')
43+
break
44+
pyfile = os.path.join(path2GSAS2,'git_verinfo.py')
45+
try:
46+
fp = open(pyfile,'w')
47+
except:
48+
print(f'Creation of git version file {pyfile} failed')
49+
sys.exit()
50+
fp.write('# -*- coding: utf-8 -*-\n')
51+
fp.write(f'# {os.path.split(pyfile)[1]} - GSAS-II version info from git\n')
52+
fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} script\n')
53+
fp.write(f'# Created {now}\n\n')
54+
fp.write(f'git_version = {commit0!r}\n')
55+
if tags:
56+
fp.write(f'git_tags = {tags0}\n')
57+
else:
58+
fp.write('git_tags = []\n')
59+
fp.write(f'git_prevtaggedversion = {commitm1!r}\n')
60+
fp.write(f'git_prevtags = {tagsm1}\n')
61+
fp.close()
62+
print(f'Created git version file {pyfile} at {now} for {commit0[:6]!r}')

GSASII/install/tag-version.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# version #
77

88
# perhaps someday include as a clean (run on git add) or smudge
9-
# step (run on git pull).
9+
# step (run on git pull).
1010
# Alternately, on commit/pull might get a count of how many untagged
11-
# check-ins there have been.
11+
# check-ins there have been.
1212
#
1313
# [filter "createVersionFile"]
1414
# clean = python git_filters.py --tag-version
@@ -30,12 +30,12 @@
3030
path2repo = os.path.dirname(path2GSAS2)
3131

3232
if __name__ == '__main__':
33-
33+
3434
g2repo = git.Repo(path2repo)
3535
if g2repo.active_branch.name != 'master':
3636
print(f'Not on master branch {commit0[:6]!r}')
3737
sys.exit()
38-
if g2repo.head.is_detached:
38+
if g2repo.head.is_detached:
3939
print(f'Detached head {commit0[:6]!r}')
4040
sys.exit()
4141
# make a list of tags without a dash; get the largest numeric tag
@@ -66,7 +66,7 @@
6666
print(f'created tag {tagnum} for {i.hexsha[:6]}')
6767
break
6868

69-
# create a file with GSAS-II version infomation
69+
# create a file with GSAS-II version information
7070
try:
7171
g2repo = git.Repo(path2repo)
7272
except:
@@ -94,7 +94,7 @@
9494
sys.exit()
9595
fp.write('# -*- coding: utf-8 -*-\n')
9696
fp.write(f'# {os.path.split(pyfile)[1]} - GSAS-II version info from git\n')
97-
fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} command\n')
97+
fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} script\n')
9898
fp.write(f'# Created {now}\n\n')
9999
fp.write(f'git_version = {commit0!r}\n')
100100
if tags:

0 commit comments

Comments
 (0)