3636intver = lambda vs : sum ([int (i ) for i in vs .split ('.' )[0 :2 ]]* np .array ((1000 ,1 )))
3737
3838def GetConfigValue (key ,default = None ,getDefault = False ):
39- '''Return the configuration file value for key or a default value
39+ '''Return the configuration file value for key or a default value
4040 if not specified.
41-
41+
4242 :param str key: a value to be found in the configuration settings
43- :param any default: a value to be supplied if a value for key is
44- not specified in the config file or the config file is not found.
43+ :param any default: a value to be supplied if a value for key is
44+ not specified in the config file or the config file is not found.
4545 Defaults to None.
46- :param bool getDefault: If True looks up the default value from the
47- config_example.py file (default value is False). Do not specify a
48- getDefault=True if a value is provided for default.
46+ :param bool getDefault: If True looks up the default value from the
47+ config_example.py file (default value is False). Do not specify a
48+ getDefault=True if a value is provided for default.
4949 :returns: the value found or the default.
5050 '''
5151 if getDefault :
@@ -58,11 +58,11 @@ def GetConfigValue(key,default=None,getDefault=False):
5858 return None
5959
6060def SetConfigValue (parmdict ):
61- '''Set configuration variables. Note that parmdict is a dictionary
62- from :func:`GSASIIctrlGUI.GetConfigValsDocs` where each element is a
63- lists. The first item in list is the default value, the second is
64- the value to use for that configuration variable. Most of the
65- information gathered in GetConfigValsDocs is no longer used.
61+ '''Set configuration variables. Note that parmdict is a dictionary
62+ from :func:`GSASIIctrlGUI.GetConfigValsDocs` where each element is a
63+ lists. The first item in list is the default value, the second is
64+ the value to use for that configuration variable. Most of the
65+ information gathered in GetConfigValsDocs is no longer used.
6666 '''
6767 global configDict
6868 for var in parmdict :
@@ -924,7 +924,7 @@ def runScript(cmds=[], wait=False, G2frame=None):
924924 projectfile = ''
925925 if G2frame .GSASprojectfile :
926926 projectfile = os .path .realpath (G2frame .GSASprojectfile )
927- main = os .path .join (path2GSAS2 ,'GSASII .py' )
927+ main = os .path .join (path2GSAS2 ,'G2 .py' )
928928 ex = sys .executable
929929 if sys .platform == "darwin" : # mac requires pythonw which is not always reported as sys.executable
930930 if os .path .exists (ex + 'w' ): ex += 'w'
@@ -946,7 +946,7 @@ def runScript(cmds=[], wait=False, G2frame=None):
946946
947947def IPyBreak_base (userMsg = None ):
948948 '''A routine that invokes an IPython session at the calling location
949- This routine is only used when debug=True is set in the configuration
949+ This routine is only used when debug=True is set in the configuration
950950 settings
951951 '''
952952 savehook = sys .excepthook # save the exception hook
@@ -979,7 +979,7 @@ def exceptHook(*args):
979979 '''A routine to be called when an exception occurs. It prints the traceback
980980 with fancy formatting and then calls an IPython shell with the environment
981981 of the exception location.
982-
982+
983983 This routine is only used when debug=True is set in the configuration settings
984984 '''
985985 try :
@@ -1026,7 +1026,7 @@ def DoNothing():
10261026 pass
10271027
10281028def InvokeDebugOpts ():
1029- 'Called in GSASII.py to set up debug options'
1029+ 'Called to set up debug options'
10301030 if any ('SPYDER' in name for name in os .environ ):
10311031 print ('Running from Spyder, keeping breakpoint() active & skipping exception trapping' )
10321032 elif GetConfigValue ('debug' ):
@@ -1136,13 +1136,13 @@ def SetBinaryPath(showConfigMsg=False):
11361136 BinaryPathFailed = pathHacking ._path_discovery (showConfigMsg )
11371137
11381138def WriteConfig (configDict ):
1139- '''Write the configDict information to the GSAS-II ini settings
1140- into file ~/.GSASII/config.ini. Called from
1139+ '''Write the configDict information to the GSAS-II ini settings
1140+ into file ~/.GSASII/config.ini. Called from
11411141 :func:`GSASIIctrlGUI.SaveConfigVars`.
11421142 '''
11431143 import configparser
1144-
1145- localdir = os .path .expanduser ('~/.GSASII' )
1144+
1145+ localdir = os .path .expanduser (os . path . normpath ( '~/.GSASII' ) )
11461146 if not os .path .exists (localdir ):
11471147 try :
11481148 os .mkdir (g2local )
@@ -1166,13 +1166,37 @@ def LoadConfig(printInfo=True):
11661166 :param bool printInfo: if printInfo is True (default) then a message
11671167 is shown with the number of settings read (upon startup).
11681168 '''
1169+ def XferConfigIni ():
1170+ '''copy the contents of the config.py file to file ~/.GSASII/config.ini.
1171+ This "patch code" used for master->develop transition and can eventually
1172+ be removed.
1173+ '''
1174+ import types
1175+ configDict = {}
1176+ try :
1177+ import config
1178+ #import config_example as config
1179+ for i in config .__dict__ :
1180+ if i .startswith ('__' ) and i .endswith ('__' ): continue
1181+ if isinstance (config .__dict__ [i ],types .ModuleType ): continue
1182+ configDict .update ({i :str (config .__dict__ [i ])})
1183+ except ImportError as err :
1184+ print ("Error importing config.py file\n " ,err )
1185+ return
1186+ except Exception as err :
1187+ print ("Error reading config.py file\n " ,err )
1188+ return
1189+ print (f"Contents of { config .__file__ } to be written..." )
1190+ WriteIniConfi (configDict )
1191+
11691192 import configparser
11701193 global configDict
11711194 configDict = {}
1172- cfgfile = os .path .expanduser ('~/.GSASII/config.ini' )
1195+ cfgfile = os .path .expanduser (os . path . normpath ( '~/.GSASII/config.ini' ) )
11731196 if not os .path .exists (cfgfile ):
11741197 print (f'N.B. Configuration file { cfgfile } does not exist' )
1175- return
1198+ # patch 2/7/25: transform GSAS-II config.py contents to config.ini
1199+ XferConfigIni ()
11761200 try :
11771201 from . import config_example
11781202 except ImportError as err :
@@ -1201,7 +1225,7 @@ def LoadConfig(printInfo=True):
12011225 try :
12021226 if cfgG [key ] == 'None' :
12031227 configDict [capKey ] = None
1204- elif key .endswith ('_pos' ) or key .endswith ('_size' ): # list of integers
1228+ elif key .endswith ('_pos' ) or key .endswith ('_size' ): # list of integers
12051229 configDict [capKey ] = tuple ([int (i ) for i in
12061230 cfgG [key ].strip ('()' ).split (',' )])
12071231 elif key .endswith ('_location' ) or key .endswith ('_directory' ) or key .endswith ('_exec' ): # None (above) or str
@@ -1212,7 +1236,7 @@ def LoadConfig(printInfo=True):
12121236 res = []
12131237 else :
12141238 res = [i .strip ("'" ).replace (r'\\' ,'\\ ' ) for i in s .split (', ' )]
1215- configDict [capKey ] = res
1239+ configDict [capKey ] = res
12161240 elif isinstance (config_example .__dict__ [capKey ],bool ):
12171241 configDict [capKey ] = cfgG .getboolean (key )
12181242 elif isinstance (config_example .__dict__ [capKey ],float ):
@@ -1230,41 +1254,6 @@ def LoadConfig(printInfo=True):
12301254 print (f'{ len (configDict )} values read from { cfgfile } ' )
12311255 # make sure this value is set
12321256 configDict ['Clip_on' ] = configDict .get ('Clip_on' ,True )
1233-
1234- # def MacStartGSASII(g2script,project=''):
1235- # '''Start a new instance of GSAS-II by opening a new terminal window and starting
1236- # a new GSAS-II process. Used on Mac OS X only.
1237-
1238- # :param str g2script: file name for the GSASII.py script
1239- # :param str project: GSAS-II project (.gpx) file to be opened, default is blank
1240- # which opens a new project
1241- # '''
1242- # if project and os.path.splitext(project)[1] != '.gpx':
1243- # print(f'file {project} cannot be used. Not GSAS-II project (.gpx) file')
1244- # return
1245- # if project and not os.path.exists(project):
1246- # print(f'file {project} cannot be found.')
1247- # return
1248- # elif project:
1249- # project = os.path.abspath(project)
1250- # if not os.path.exists(project):
1251- # print(f'lost project {project} with abspath')
1252- # raise Exception(f'lost project {project} with abspath')
1253- # g2script = os.path.abspath(g2script)
1254- # pythonapp = sys.executable
1255- # if os.path.exists(pythonapp+'w'): pythonapp += 'w'
1256- # script = f'''
1257- # set python to "{pythonapp}"
1258- # set appwithpath to "{g2script}"
1259- # set filename to "{project}"
1260- # set filename to the quoted form of the POSIX path of filename
1261-
1262- # tell application "Terminal"
1263- # activate
1264- # do script python & " " & appwithpath & " " & filename & "; exit"
1265- # end tell
1266- # '''
1267- # subprocess.Popen(["osascript","-e",script])
12681257
12691258def MacRunScript (script ):
12701259 '''Start a bash script in a new terminal window.
@@ -1944,7 +1933,7 @@ def postURL(URL,postdict,getcookie=None,usecookie=None,
19441933
19451934 if gitUpdate :
19461935 # now restart GSAS-II with the new version
1947- # G2scrpt = os.path.join(path2GSAS2,'GSASII .py')
1936+ # G2scrpt = os.path.join(path2GSAS2,'G2 .py')
19481937 if project :
19491938 print (f"Restart GSAS-II with project file { project !r} " )
19501939 # subprocess.Popen([sys.executable,G2scrpt,project])
0 commit comments