@@ -9518,7 +9518,144 @@ def gitSelectBranch(event):
95189518 G2fil .openInNewTerm (project )
95199519 print ('exiting GSAS-II' )
95209520 sys .exit ()
9521+
9522+ def gitSwitch2DevBranch (event ):
9523+ '''This is "patch" code to switch from the master branch
9524+ to the develop (eventually to be renamed main) branch.
9525+ Complication here is that the GSASII.py file gets renamed
9526+ to G2.py so "shortcuts" need to be re-created to reference that.
9527+
9528+ This is not yet "plumbed" into the current code, but it has been
9529+ tested with Windows and Mac. At some point this will be made part of the
9530+ update process in the master branch, but this routine is not needed in
9531+ the develop (or eventially main) branch.
9532+ '''
9533+ G2frame = wx .App .GetMainTopWindow ()
9534+ gitInst = GSASIIpath .HowIsG2Installed ()
9535+ if not gitInst .startswith ('github-rev' ):
9536+ G2MessageBox (G2frame ,
9537+ 'Unable to switch branches unless GSAS-II has been installed from GitHub; installed as: ' + gitInst ,
9538+ 'Not a git install' )
9539+ return
9540+ if not os .path .exists (GSASIIpath .path2GSAS2 ):
9541+ print (f'Warning: Directory { GSASIIpath .path2GSAS2 } not found' )
9542+ return
9543+ if os .path .exists (os .path .join (GSASIIpath .path2GSAS2 ,'..' ,'.git' )):
9544+ path2repo = os .path .join (path2GSAS2 ,'..' ) # expected location
9545+ elif os .path .exists (os .path .join (GSASIIpath .path2GSAS2 ,'.git' )):
9546+ path2repo = GSASIIpath .path2GSAS2
9547+ else :
9548+ print (f'Warning: Repository { path2GSAS2 } not found' )
9549+ return
9550+ try :
9551+ g2repo = GSASIIpath .openGitRepo (path2repo )
9552+ except Exception as msg :
9553+ print (f'Warning: Failed to open repository. Error: { msg } ' )
9554+ return
9555+ if g2repo .is_dirty () or g2repo .index .diff ("HEAD" ): # changed or staged files
9556+ G2MessageBox (G2frame ,
9557+ 'You have local changes. They must be reset, committed or stashed before switching branches' ,
9558+ 'Local changes' )
9559+ return
9560+ if g2repo .head .is_detached :
9561+ G2MessageBox (G2frame ,
9562+ 'You have a old previous version loaded; you must be on a branch head to switching branches' ,
9563+ 'Detached head' )
9564+ return
9565+ if g2repo .active_branch .name != "master" :
9566+ G2MessageBox (G2frame ,
9567+ f'You are on the { g2repo .active_branch .name } branch. This can only be run from master.' ,
9568+ 'Not on master' )
9569+ return
9570+
9571+ # make sure that branches are accessible & get updates
9572+ print ('getting updates...' ,end = '' )
9573+ g2repo .git .remote ('set-branches' ,'origin' ,'*' )
9574+ print ('..' ,end = '' )
9575+ g2repo .git .fetch ()
9576+ print ('.done' )
9577+ branchlist = [i .strip () for i in g2repo .git .branch ('-r' ).split ('\n ' ) if '->' not in i ]
9578+ choices = [i for i in [os .path .split (i )[1 ] for i in branchlist ] if i != g2repo .active_branch .name ]
9579+ b = "develop"
9580+ if b not in choices :
9581+ G2MessageBox (G2frame ,
9582+ f'You are on the { g2repo .active_branch .name !r} branch, but branch { b !r} was not found.' ,
9583+ f'No { b } branch' )
9584+ return
9585+ msg = f'''Confirm switching from git branch { g2repo .active_branch .name !r} to { b !r} .
9586+
9587+ If confirmed here, GSAS-II will restart.
9588+
9589+ Do you want to save your project before restarting?
9590+ Select "Yes" to save, "No" to skip the save, or "Cancel"
9591+ to discontinue the restart process.
9592+
9593+ If "Yes", GSAS-II will reopen the project after the update.
9594+
9595+ The switch will be made unless Cancel is pressed.'''
9596+ dlg = wx .MessageDialog (G2frame , msg , 'Confirm branch switch?' ,
9597+ wx .YES_NO | wx .CANCEL | wx .YES_DEFAULT | wx .CENTRE | wx .ICON_QUESTION )
9598+ ans = dlg .ShowModal ()
9599+ dlg .Destroy ()
9600+ if ans == wx .ID_CANCEL :
9601+ return
9602+ elif ans == wx .ID_YES :
9603+ ans = G2frame .OnFileSave (None )
9604+ if not ans : return
9605+ project = os .path .abspath (G2frame .GSASprojectfile )
9606+ print (f"Restarting GSAS-II with project file { project !r} " )
9607+ else :
9608+ print ("Restarting GSAS-II without a project file " )
9609+ project = None
9610+ # I hope that it is possible to do a checkout on Windows
9611+ # (source files are not locked). If this is not the case
9612+ # then another approach will be needed, where a .bat file is used
9613+ # or GSASIIpath is used, as is the case for updates
9614+ a = g2repo .git .checkout (b )
9615+ if 'Your branch is behind' in a :
9616+ print ('updating local copy of branch' )
9617+ print (g2repo .git .pull ())
9618+ # post-install stuff (following gitstrap.py)
9619+ print (f'Byte-compiling all .py files in { GSASIIpath .path2GSAS2 !r} ... ' ,end = '' )
9620+ import compileall
9621+ compileall .compile_dir (GSASIIpath .path2GSAS2 ,quiet = True )
9622+ print ('done' )
9623+ #
9624+ print ('start system-specific install' )
9625+ for k ,s in {'win' :"makeBat.py" , 'darwin' :"makeMacApp.py" ,
9626+ 'linux' :"makeLinux.py" }.items ():
9627+ if sys .platform .startswith (k ):
9628+ script = os .path .join (GSASIIpath .path2GSAS2 ,'install' ,s )
9629+ if not os .path .exists (script ):
9630+ print (f'Platform-specific script { script !r} not found' )
9631+ script = ''
9632+ break
9633+ else :
9634+ print (f'Unknown platform { sys .platform } ' )
9635+ # on a Mac, make an applescript
9636+ if script and sys .platform .startswith ('darwin' ):
9637+ print (f'running { script } ' )
9638+ import subprocess
9639+ out = subprocess .run ([sys .executable ,script ],cwd = GSASIIpath .path2GSAS2 )
9640+ # On windows make a batch file with hard-coded paths to Python and GSAS-II
9641+ elif script and sys .platform .startswith ('win' ):
9642+ script = os .path .normpath (os .path .join (GSASIIpath .path2GSAS2 ,'install' ,s ))
9643+ print (f'running { script !r} ' )
9644+ import subprocess
9645+ out = subprocess .run ([sys .executable ,script ],cwd = GSASIIpath .path2GSAS2 )
9646+ # On linux, make a desktop icon with hard-coded paths to Python and GSAS-II
9647+ elif script :
9648+ sys .argv = [script ]
9649+ print (f'running { sys .argv [0 ]} ' )
9650+ with open (sys .argv [0 ]) as source_file :
9651+ exec (source_file .read ())
9652+
9653+ print ('system-specific install done' )
95219654
9655+ G2fil .openInNewTerm (project )
9656+ print ('exiting GSAS-II' )
9657+ sys .exit ()
9658+
95229659#===========================================================================
95239660# Importer GUI stuff
95249661def ImportMsg (parent ,msgs ):
@@ -9577,25 +9714,34 @@ def SelectPkgInstall(event):
95779714 if sel is None : return
95789715 if not any (sel ): return
95799716 pkgs = [choices [i ][0 ] for i ,f in enumerate (sel ) if f ]
9717+ wx .BeginBusyCursor ()
9718+ pdlg = wx .ProgressDialog ('Updating' ,'Installing Python packages; this can take a while' ,
9719+ parent = G2frame )
95809720 if GSASIIpath .condaTest ():
95819721 patch_condarc ()
95829722 if not GSASIIpath .condaTest (True ):
95839723 GSASIIpath .addCondaPkg ()
95849724 err = GSASIIpath .condaInstall (pkgs )
95859725 if err :
95869726 print (f'Error from conda: { err } ' )
9727+ wx .EndBusyCursor ()
9728+ pdlg .Destroy ()
95879729 return
95889730 else :
95899731 err = GSASIIpath .pipInstall (pkgs )
95909732 if err :
95919733 print (f'Error from pip: { err } ' )
9734+ wx .EndBusyCursor ()
9735+ pdlg .Destroy ()
95929736 return
9593- msg = '''You must restart GSAS-II to access the importer(s)
9594- requiring the installed package(s).
9595-
9596- Select "Yes" to save, "No" to skip the save, or "Cancel"
9597- to discontinue the restart process and continue GSAS-II
9598- without the importer(s).
9737+ wx .EndBusyCursor ()
9738+ pdlg .Destroy ()
9739+ msg = '''You must restart GSAS-II to access the importer(s)
9740+ requiring the package(s) just installed.
9741+
9742+ Select "Yes" to save and restart, "No" to restart without
9743+ the save, or "Cancel" to discontinue the restart process
9744+ and continue use of GSAS-II without the importer(s).
95999745
96009746If "Yes", GSAS-II will reopen the project after the update.
96019747'''
0 commit comments