Skip to content

Commit 7a4fa6e

Browse files
committed
fix use of TestSPG to separate out path hacking
1 parent 63be9e0 commit 7a4fa6e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def ShowVersions():
479479
print('Warning: Python requests package not installed (required for\n'+
480480
' GSAS-II to access web pages or self-install binary modules)')
481481

482-
if not GSASIIpath.TestSPG(GSASIIpath.binaryPath):
482+
if not GSASIIpath.TestSPG():
483483
path2repo = os.path.dirname(GSASIIpath.path2GSAS2)
484484
installLoc = os.path.join(path2repo,'GSASII-bin')
485485
binarydir = GSASIIpath.getGitBinaryLoc(verbose=True)
@@ -504,7 +504,7 @@ def ShowVersions():
504504
GSASIIpath.SetBinaryPath(True)
505505
except:
506506
print('Download failed, sorry')
507-
if not GSASIIpath.TestSPG(GSASIIpath.binaryPath):
507+
if not GSASIIpath.pathhack_TestSPG(GSASIIpath.binaryPath):
508508
versionDict['errors'] += 'Error accessing GSAS-II binary files. Only limited functionality available.'
509509
else:
510510
if GSASIIpath.binaryPath:

GSASII/GSASIIpath.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,27 +1096,33 @@ def InvokeDebugOpts():
10961096
else: # not in spyder or debug enabled, hide breakpoints
10971097
os.environ['PYTHONBREAKPOINT'] = '0'
10981098

1099-
def TestSPG(fpth):
1100-
'''Test if pyspg.[so,.pyd] can be run from a location in the path
1099+
def TestSPG():
1100+
'''Test if pyspg.[so,.pyd] can be run from a location in the existing path
11011101
Do not modify the path if not.
11021102
'''
11031103
try:
11041104
from . import pyspg
11051105
pyspg
11061106
return True
1107+
except ImportError:
1108+
pass
1109+
try:
1110+
import pyspg
1111+
pyspg
11071112
except ImportError:
11081113
return False
11091114
try:
11101115
pyspg.sgforpy('P -1')
11111116
except Exception as err:
11121117
print(70*'=')
1113-
print(f'Module pyspg in {fpth!r} could not be run\nerror msg: {err}')
1118+
print(f'Module pyspg in {pyspg.__file__} could not be run\nerror msg: {err}')
11141119
print(70*'=')
11151120
return False
11161121
return True
11171122

1118-
def _old_TestSPG(fpth):
1119-
'''Test if pyspg.[so,.pyd] can be run from a location in the path
1123+
def pathhack_TestSPG(fpth):
1124+
'''Test if pyspg.[so,.pyd] can be run from a specified location. If so
1125+
modify the path to include it.
11201126
'''
11211127
try:
11221128
if not os.path.exists(fpth): return False

GSASII/pathHacking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def appendIfExists(searchpathlist,loc,subdir):
5858
searchpathlist.append(versions[vmax])
5959
for fpth in searchpathlist:
6060
if not glob.glob(os.path.join(fpth,'pyspg.*')): continue
61-
if GSASIIpath.TestSPG(fpth):
61+
if GSASIIpath.pathhack_TestSPG(fpth):
6262
binpath = fpth # got one that works, look no farther!
6363
break
6464
else:

0 commit comments

Comments
 (0)