Skip to content

Commit 97b949d

Browse files
committed
cleanup access to git release files and note potential improvements
1 parent 11291f8 commit 97b949d

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ def ShowVersions():
488488
if not GSASIIpath.TestSPG():
489489
path2repo = os.path.dirname(GSASIIpath.path2GSAS2)
490490
installLoc = os.path.join(path2repo,'GSASII-bin')
491+
# TODO: note new code in gitstrap.py that avoids use of getGitBinaryLoc
492+
# when the desired binary exists. Better to do lookup with
493+
# getGitBinaryLoc only when an exact match is not available
491494
binarydir = GSASIIpath.getGitBinaryLoc(verbose=True)
492495
if not binarydir:
493496
versionDict['errors'] += 'GSAS-II does not have a binaries built for this version of Python. You will need to install a supported Python version or build binaries yourself. See https://gsas-ii.readthedocs.io/en/latest/packages.html#python-requirements\n\n'
@@ -513,14 +516,16 @@ def ShowVersions():
513516
if not GSASIIpath.pathhack_TestSPG(GSASIIpath.binaryPath):
514517
versionDict['errors'] += 'Error accessing GSAS-II binary files. Only limited functionality available.'
515518
else:
519+
# TODO: use GSASIIversion.txt (in binary directory) to see
520+
# if version is recent enough rather than use presence of convcell[.exe]
516521
if GSASIIpath.binaryPath:
517522
prog = os.path.join(GSASIIpath.binaryPath,"convcell")
518523
else:
519524
prog = 'convcell'
520525
if sys.platform.startswith('win'):
521526
prog += '.exe'
522527
if not shutil.which(prog):
523-
versionDict['errors'] += 'NIST*LATTICE binaries not found. You may have old binaries or an installation problem. If you built them built binaries, rerun scons or meson'
528+
versionDict['errors'] += 'NIST*LATTICE binaries not found. You may have old binaries or an installation problem. If you built these binaries, rerun scons or meson'
524529
if warn:
525530
print(70*'=')
526531
print('''You are running GSAS-II in a Python environment with either untested

GSASII/GSASIIpath.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,12 @@ def getGitBinaryReleases(cache=False):
707707
The value associated with each key contains the full URL to
708708
download a tar containing that binary distribution.
709709
'''
710-
# Get first page of releases
711710
try:
712711
import requests
713712
except:
714713
print('Unable to install binaries in getGitBinaryReleases():\n requests module not available')
715714
return
715+
# Get first page of releases. (Could there be more than one?)
716716
releases = []
717717
tries = 0
718718
while tries < 5: # this has been known to fail, so retry
@@ -722,20 +722,14 @@ def getGitBinaryReleases(cache=False):
722722
headers=BASE_HEADER
723723
).json()
724724
try:
725-
# Get assets of latest release
726-
assets = requests.get(
727-
url=f"{G2binURL}/releases/{releases[-1]['id']}/assets",
728-
headers=BASE_HEADER
729-
).json()
730-
725+
# loop over assets of latest release (will [-1] always get this?)
731726
versions = []
732727
URLs = []
733-
count = 0
734-
for asset in assets:
735-
if asset['name'].endswith('.tgz'):
736-
versions.append(asset['name'][:-4]) # Remove .tgz tail
737-
URLs.append(asset['browser_download_url'])
738-
count += 1
728+
for asset in releases[-1]['assets']:
729+
if not asset['name'].endswith('.tgz'): continue
730+
versions.append(asset['name'][:-4]) # Remove .tgz tail
731+
URLs.append(asset['browser_download_url'])
732+
count = len(versions)
739733
# Cache the binary releases for later use in case GitHub
740734
# prevents us from using a query to get them
741735
if cache and count > 4:
@@ -746,7 +740,7 @@ def getGitBinaryReleases(cache=False):
746740
fp.close()
747741
return dict(zip(versions,URLs))
748742
except:
749-
print('Attempt to list GSAS-II binary releases failed, sleeping for 10 sec and then retrying')
743+
print('Attempt to get GSAS-II binary releases/assets failed, sleeping for 10 sec and then retrying')
750744
import time
751745
time.sleep(10) # this does not seem to help when GitHub is not letting the queries through
752746

@@ -762,7 +756,7 @@ def getGitBinaryReleases(cache=False):
762756
except:
763757
raise IOError('Cache read of releases failed too.')
764758

765-
def getGitBinaryLoc(npver=None,pyver=None,verbose=True):
759+
def getGitBinaryLoc(npver=None,pyver=None,verbose=True,debug=False):
766760
'''Identify the best GSAS-II binary download location from the
767761
distributions in the latest release section of the github repository
768762
on the CPU platform, and Python & numpy versions. The CPU & Python
@@ -783,11 +777,15 @@ def getGitBinaryLoc(npver=None,pyver=None,verbose=True):
783777
inpver = intver(np.__version__)
784778
# get binaries matching the required install, approximate match for numpy
785779
URLdict = getGitBinaryReleases()
780+
if debug:
781+
print('URLdict:')
782+
for k in URLdict: print(k,URLdict[k])
786783
versions = {}
787784
for d in URLdict:
788785
if d.startswith(bindir):
789786
v = intver(d.rstrip('/').split('_')[3].lstrip('n'))
790787
versions[v] = d
788+
if debug: print('versions:',versions)
791789
intVersionsList = sorted(versions.keys())
792790
if not intVersionsList:
793791
print('No binaries located to match',bindir)
@@ -844,6 +842,7 @@ def InstallGitBinary(tarURL, instDir, nameByVersion=False, verbose=True):
844842
print('Unable to install binaries in InstallGitBinary():\n requests module not available')
845843
return
846844
# download to scratch
845+
tarobj = None
847846
tar = tempfile.NamedTemporaryFile(suffix='.tgz',delete=False)
848847
try:
849848
tar.close()
@@ -873,9 +872,11 @@ def InstallGitBinary(tarURL, instDir, nameByVersion=False, verbose=True):
873872
# set file mode and mod/access times (but not ownership)
874873
os.chmod(newfil,f.mode)
875874
os.utime(newfil,(f.mtime,f.mtime))
876-
if verbose: print(f'Created GSAS-II binary file {newfil}')
875+
if verbose: print(f'Created GSAS-II binary file {os.path.split(newfil)[1]}')
876+
if verbose: print(f'Binary files created in {os.path.split(newfil)[0]}')
877+
877878
finally:
878-
del tarobj
879+
if tarobj: del tarobj
879880
os.unlink(tar.name)
880881

881882
def GetRepoUpdatesInBackground():

0 commit comments

Comments
 (0)