Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions GSASII/GSASIIdataGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,11 @@ def ShowVersions():
break
except:
pass
print (" Image: %s (PIL or Pillow)"%version)
print (" Platform: %s %s %s"%(sys.platform,platform.architecture()[0],platform.machine()))
print (f" Image: {version} (PIL or Pillow)")
print (f" Platform: {sys.platform} {GSASIIpath.GetPlatformArchitecture()} {platform.machine()}")
try:
import mkl
print (" Max threads:%s"%mkl.get_max_threads())
print (f" Max threads:{mkl.get_max_threads()}")
except:
pass

Expand Down
3 changes: 1 addition & 2 deletions GSASII/GSASIIfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def get_python_versions(packagelist):
except:
pass
versions.append(['Platform',
sys.platform + ' ' + platform.architecture()[0] +
' ' + platform.machine()])
sys.platform + ' ' + GSASIIpath.GetPlatformArchitecture() + ' ' + platform.machine()])
return versions

ImportErrors = []
Expand Down
50 changes: 41 additions & 9 deletions GSASII/GSASIIpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ def LoadConfigFile(filename):
fp.close()
return info

def GetPlatformArchitecture():
'''Produces same result as platform.architecture()[0], but runs much
faster because struct.calcsize('P') gives the pointer size while
platform.architecture()[0] launches an external process
('file <executable>') on POSIX systems every time it is called.

:returns: '32bit' or '64bit'
'''
import struct
return f"{struct.calcsize('P')*8}bit"

def GetBinaryPrefix(pyver=None):
'''Creates the first part of the binary directory name
such as linux_64_p3.9 (where the full name will be
Expand All @@ -165,11 +176,11 @@ def GetBinaryPrefix(pyver=None):
raise Exception('Unknown platform')
if 'arm' in platform.machine() and sys.platform == "darwin":
bits = 'arm'
elif 'aarch' in platform.machine() and '64' in platform.architecture()[0]:
elif 'aarch' in platform.machine() and '64' in GSASIIpath.GetPlatformArchitecture():
bits = 'arm64'
elif 'arm' in platform.machine():
bits = 'arm32'
elif '64' in platform.architecture()[0]:
elif '64' in GSASIIpath.GetPlatformArchitecture():
bits = '64'
else:
bits = '32'
Expand Down Expand Up @@ -205,17 +216,38 @@ def HowIsG2Installed():
else:
rev = '-rev'
if g2URL in g2repo.remote().urls:
return 'github'+rev
G2_installed_result = f'github{rev}'
return G2_installed_result
elif g2URL.replace('https://github.com/',
'git@github.com:') in g2repo.remote().urls:
return 'github'+rev
G2_installed_result = f'github{rev}'
return G2_installed_result
G2_installed_result = 'git'+rev
return G2_installed_result
except:
pass
G2_installed_result = 'noVCS'
return G2_installed_result

G2_commit_hash_result = None
def getG2CommitHash():
'''Returns the hex sha for the current GSAS-II commit (HEAD) for a
git-based install. The result is cached to avoid the cost of
starting a git process for repeated calls, since the checked-out
commit will not change while GSAS-II is running.

:returns: the hexsha string for the current commit, or None if it
cannot be determined (e.g. not installed via git).
'''
global G2_commit_hash_result
if G2_commit_hash_result is not None: return G2_commit_hash_result
try:
g2repo = openGitRepo(path2GSAS2)
G2_commit_hash_result = g2repo.head.commit.hexsha
except:
pass
return G2_commit_hash_result

def getSavedVersionInfo():
'''Get version number information from a file written by install
routines. This is faster than getting the information from git. Also,
Expand Down Expand Up @@ -2133,7 +2165,7 @@ def testLLamaModel():
Returns the name of the most recently installed model
or None if the model needs to be installed.
'''
modelDir = os.path.expanduser("~/.GSASII/llama_models")
modelDir = os.path.join(LocalG2Dir(),"llama_models")
if not os.path.exists(modelDir):
return None
fileList = glob.glob(os.path.join(modelDir,'*.gguf'))
Expand All @@ -2147,7 +2179,7 @@ def testLLamaModel():

def installLLamaModel():
'''Download the Qwen2.5-3B-Instruct llama model'''
modelDir = os.path.expanduser("~/.GSASII/llama_models")
modelDir = os.path.join(LocalG2Dir(),"llama_models")
os.makedirs(modelDir, exist_ok=True)
print('Downloading a model...')
from huggingface_hub import hf_hub_download
Expand Down Expand Up @@ -2179,7 +2211,7 @@ def ageLLMindex():
'''
import datetime
f = 'chroma_db'
dbdir = os.path.expanduser('~/.GSASII/query_gsas2')
dbdir = os.path.join(LocalG2Dir(),"query_gsas2")
db = os.path.join(dbdir,f)
if os.path.exists(db):
m_time_timestamp = os.path.getmtime(db)
Expand Down Expand Up @@ -2228,9 +2260,9 @@ def getLLMindex():
#print("Saved to:", tmp.name)
# create the files in a new location and then move them to the final location
f = 'chroma_db'
finaldir = os.path.expanduser('~/.GSASII/query_gsas2')
finaldir = os.path.join(LocalG2Dir(),"query_gsas2")
finaldb = os.path.join(finaldir,f)
newdir = os.path.expanduser('~/.GSASII/new_query_gsas2')
newdir = os.path.join(LocalG2Dir(),"new_query_gsas2")
newdb = os.path.join(newdir,f)
os.makedirs(newdir, exist_ok=True)
os.makedirs(finaldir, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion GSASII/GSASIIpwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,7 @@ def fullrmcDownload():
import os
import requests
import platform
if platform.architecture()[0] != '64bit':
if GSASIIpath.GetPlatformArchitecture() != '64bit':
return "fullrmc is only available for 64 bit machines. This is 32 bit"
setXbit = True
if sys.platform == "darwin":
Expand Down
20 changes: 13 additions & 7 deletions GSASII/GSASIIscriptable.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ class variables:
:param str filename: To be deprecated. Serves the same function as newgpx,
which has a somewhat more clear name.
(Do not specify both newgpx and filename).
:param bool fastsave: When specified as True, the version number
is taken from the git_verinfo.py file rather than using git.
This saves a bit of time.

There are two ways to initialize this object:

Expand Down Expand Up @@ -956,7 +959,9 @@ class variables:
:meth:`~G2Project.set_refinement`, :meth:`~G2Project.iter_refinements` and
:meth:`~G2Project.do_refinements`.
"""
def __init__(self, gpxfile=None, author=None, filename=None, newgpx=None):
def __init__(self, gpxfile=None, author=None, filename=None, newgpx=None,
fastsave=False):
self.fastsave = fastsave
if filename is not None and newgpx is not None:
raise G2ScriptException('Do not use filename and newgpx together')
elif filename is not None:
Expand Down Expand Up @@ -1005,7 +1010,9 @@ def from_dict_and_names(cls, gpxdict, names, filename=None):
def save(self, filename=None):
"""Saves the project, either to the current filename, or to a new file.

Updates self.filename if a new filename provided"""
:param str filename: a file name to be used to save the .gpx file.
Updates self.filename if this is provided
"""
controls_data = self.data['Controls']['data']
# place info in .gpx about GSAS-II
# report versions of modules; ignore what has not been used
Expand All @@ -1022,10 +1029,9 @@ def save(self, filename=None):
# G2 version info
controls_data['LastSavedUsing'] = str(GSASIIpath.GetVersionNumber())
try:
if GSASIIpath.HowIsG2Installed().startswith('git'):
g2repo = GSASIIpath.openGitRepo(GSASIIpath.path2GSAS2)
commit = g2repo.head.commit
controls_data['LastSavedUsing'] += f" git {commit.hexsha[:8]} script"
if GSASIIpath.HowIsG2Installed().startswith('git') and not self.fastsave:
commit = GSASIIpath.getG2CommitHash()
controls_data['LastSavedUsing'] += f" git {commit[:8]} script"
else:
gv = GSASIIpath.getSavedVersionInfo()
if gv is not None:
Expand Down Expand Up @@ -2795,7 +2801,7 @@ def add_image(self, imagefile, fmthint=None, defaultImage=None,
Data['DetDepthRef'] = False
else:
Data['type'] = 'PWDR'
Data['color'] = GSASIIpath.GetConfigValue('Contour_color','Paired')
Data['color'] = GSASIIpath.GetConfigValue('Contour_color','GSPaired')
if 'tilt' not in Data: #defaults if not preset in e.g. Bruker importer
Data['tilt'] = 0.0
Data['rotation'] = 0.0
Expand Down
Loading