@@ -2642,6 +2642,7 @@ def ShowScrolledInfo(parent,txt,width=600,height=400,header='Warning info',
26422642 btn = wx .Button (dlg , b )
26432643 btn .Bind (wx .EVT_BUTTON ,lambda event : dlg .EndModal (event .Id ))
26442644 btnsizer .Add (btn )
2645+ btnsizer .Add ((6 ,- 1 ))
26452646 mainSizer .Add (btnsizer , 0 , wx .ALIGN_CENTER | wx .ALL , 5 )
26462647 dlg .SetSizer (mainSizer )
26472648 mainSizer .Fit (dlg )
@@ -5973,6 +5974,13 @@ def OnCheckUpdates(self,event):
59735974 and perform that update if requested.
59745975 '''
59755976 if GSASIIpath .HowIsG2Installed ().startswith ('git' ):
5977+ # Patch: switch from master to main
5978+ # if GSASIIpath.getG2Branch() == 'master':
5979+ # DEBUG code (TODO remove when ready to switch branches)
5980+ # for now testing by user toby in debug mode only
5981+ if GSASIIpath .GetConfigValue ('debug' ) and GSASIIpath .getG2Branch () == 'master' and os .environ .get ('USER' ,'?' ) == 'toby' :
5982+ gitSwitchMaster2Main ()
5983+ return
59765984 gitCheckUpdates (self .frame )
59775985 else :
59785986 dlg = wx .MessageDialog (self .frame ,
@@ -9745,49 +9753,58 @@ def gitSelectBranch(event):
97459753 print ('exiting GSAS-II' )
97469754 sys .exit ()
97479755
9748- def gitSwitch2DevBranch ( event ):
9756+ def gitSwitchMaster2Main ( ):
97499757 '''This is "patch" code to switch from the master branch
9750- to the main branch.
9751- Complication here is that the GSASII.py file gets renamed
9752- to G2.py so "shortcuts" need to be re-created to reference that.
9753-
9754- This is not yet "plumbed" into the current code, but it has been
9755- tested with Windows and Mac. At some point this will be made part of the
9756- update process in the master branch, but this routine is not needed in
9758+ to the main branch. At some point this will be made part of the
9759+ update process in the master branch. This routine is not needed in
97579760 the main branch.
9761+
9762+ Switching is a bit complicated as additional Python packages are needed
9763+ and becuase the GSASII.py file gets renamed to G2.py so "shortcuts" need
9764+ to be re-created to reference that.
97589765 '''
97599766 G2frame = wx .App .GetMainTopWindow ()
97609767 gitInst = GSASIIpath .HowIsG2Installed ()
97619768 if not gitInst .startswith ('github-rev' ):
97629769 G2MessageBox (G2frame ,
9763- 'Unable to switch branches unless GSAS-II has been installed from GitHub; installed as: ' + gitInst ,
9770+ 'Unable to update to new branch because GSAS-II was not installed from GitHub; installed as: ' + gitInst ,
97649771 'Not a git install' )
97659772 return
97669773 if not os .path .exists (GSASIIpath .path2GSAS2 ):
9767- print (f'Warning: Directory { GSASIIpath .path2GSAS2 } not found' )
9774+ msg = f'Warning: Directory { GSASIIpath .path2GSAS2 } not found; not installed properly'
9775+ print (msg )
9776+ G2MessageBox (G2frame ,msg )
97689777 return
97699778 if os .path .exists (os .path .join (GSASIIpath .path2GSAS2 ,'..' ,'.git' )):
97709779 path2repo = os .path .join (path2GSAS2 ,'..' ) # expected location
97719780 elif os .path .exists (os .path .join (GSASIIpath .path2GSAS2 ,'.git' )):
97729781 path2repo = GSASIIpath .path2GSAS2
97739782 else :
9774- print (f'Warning: Repository { path2GSAS2 } not found' )
9783+ msg = f'Warning: Repository { path2GSAS2 } not found; Update not possible if not installed with git.'
9784+ print (msg )
9785+ G2MessageBox (G2frame ,msg )
97759786 return
97769787 try :
97779788 g2repo = GSASIIpath .openGitRepo (path2repo )
97789789 except Exception as msg :
9779- print (f'Warning: Failed to open repository. Error: { msg } ' )
9790+ msg = f'Warning: Failed to open repository. Error: { msg } '
9791+ print (msg )
9792+ G2MessageBox (G2frame ,msg )
97809793 return
97819794 if g2repo .is_dirty () or g2repo .index .diff ("HEAD" ): # changed or staged files
9782- G2MessageBox (G2frame ,
9783- 'You have local changes. They must be reset, committed or stashed before switching branches' ,
9784- 'Local changes' )
9795+ msg = 'You have local changes. They must be reset, committed or stashed before an update is possible'
9796+ print (msg )
9797+ G2MessageBox (G2frame ,msg ,'Local changes' )
9798+
97859799 return
9800+ # Should not get here with detached head (regressed version) need to be on latest (last) version
9801+ # go get into this routine
97869802 if g2repo .head .is_detached :
97879803 G2MessageBox (G2frame ,
9788- 'You have a old previous version loaded; you must be on a branch head to switching branches' ,
9804+ 'You have a old previous version loaded; you must be on a branch head to updateswitching branches' ,
97899805 'Detached head' )
97909806 return
9807+ # this also should not happen
97919808 if g2repo .active_branch .name != "master" :
97929809 G2MessageBox (G2frame ,
97939810 f'You are on the { g2repo .active_branch .name } branch. This can only be run from master.' ,
@@ -9806,23 +9823,59 @@ def gitSwitch2DevBranch(event):
98069823 if b not in choices :
98079824 G2MessageBox (G2frame ,
98089825 f'You are on the { g2repo .active_branch .name !r} branch, but branch { b !r} was not found.' ,
9809- f'No { b } branch' )
9826+ f'Unexpected: No { b } branch' )
98109827 return
9811- msg = f'''Confirm switching from git branch { g2repo .active_branch .name !r} to { b !r} .
9828+ if not GSASIIpath .condaTest ():
9829+ msg = '''In April 2025, GSAS-II switched to a new branch ("main")
9830+ that has significant internal reorganization requested by several users. All
9831+ future updates will be on this branch. It appears you have installed Python
9832+ manually, so an automatic update is not possible.
98129833
9813- If confirmed here, GSAS-II will restart.
9834+ You can install the recommended Python packages and manually use git
9835+ commands to switch from the "master" branch to the "main" branch, but
9836+ it may be easier to simply reinstall GSAS-II.
98149837
9815- Do you want to save your project before restarting?
9816- Select "Yes" to save, "No" to skip the save, or "Cancel"
9817- to discontinue the restart process.
9838+ See web page GSASII.github.io for information on how to install GSAS-II.
9839+ '''
9840+ res = ShowScrolledInfo (G2frame ,msg ,header = 'Please Note' ,
9841+ height = 250 )
9842+ return
98189843
9819- If "Yes", GSAS-II will reopen the project after the update.
9844+ # all checks passed, check with user and then get started
9845+ msg = f'''In April 2025, GSAS-II GSAS-II switched to a new branch ("main")
9846+ that has significant internal reorganization requested by several users. All
9847+ future updates will be on this branch. If you continue here, GSAS-II will
9848+ make the changes needed to move your installation to the new branch:
98209849
9821- The switch will be made unless Cancel is pressed.'''
9822- dlg = wx .MessageDialog (G2frame , msg , 'Confirm branch switch?' ,
9823- wx .YES_NO | wx .CANCEL | wx .YES_DEFAULT | wx .CENTRE | wx .ICON_QUESTION )
9824- ans = dlg .ShowModal ()
9825- dlg .Destroy ()
9850+ 1) Additional Python packages needed by GSAS-II will be installed.
9851+ 2) Git will be used to install the latest GSAS-II files
9852+ 3) Shortcuts to the latest GSAS-II version will be installed; shortcuts
9853+ previously installed will fail if not replaced.
9854+
9855+ If the update fails, please reinstall GSAS-II from https://bit.ly/G2download
9856+ (https://github.com/AdvancedPhotonSource/GSAS-II-buildtools/releases/latest)
9857+ See web page GSASII.github.io for information on how to install.
9858+
9859+ Confirm switching from git branch { g2repo .active_branch .name !r} to { b !r} by
9860+ selecting "Save" or "Skip" below ("Cancel" will quit the update).
9861+
9862+ If confirmed here, GSAS-II will restart after the update.
9863+
9864+ Do you want to save your project before restarting?
9865+ Select "Save" to save, "Skip" to skip the save, or "Cancel"
9866+ to discontinue the update process.
9867+
9868+ The update will be made unless Cancel is pressed.'''
9869+ ans = ShowScrolledInfo (G2frame ,msg ,header = 'Please Note' ,
9870+ height = 400 ,
9871+ buttonlist = [
9872+ ('Save project and update' ,
9873+ lambda event : event .GetEventObject ().GetParent ().EndModal (wx .ID_OK )),
9874+ ('Skip save and update' ,
9875+ lambda event : event .GetEventObject ().GetParent ().EndModal (wx .ID_NO )),
9876+ ('Cancel' ,
9877+ lambda event : event .GetEventObject ().GetParent ().EndModal (wx .ID_CANCEL ))
9878+ ])
98269879 if ans == wx .ID_CANCEL :
98279880 return
98289881 elif ans == wx .ID_YES :
@@ -9833,21 +9886,52 @@ def gitSwitch2DevBranch(event):
98339886 else :
98349887 print ("Restarting GSAS-II without a project file " )
98359888 project = None
9836- # I hope that it is possible to do a checkout on Windows
9837- # (source files are not locked). If this is not the case
9838- # then another approach will be needed, where a .bat file is used
9839- # or GSASIIpath is used, as is the case for updates
9840- a = g2repo .git .checkout (b )
9889+
9890+ # 1) install the needed Python packages
9891+ #=======================================
9892+ # listing of GSAS-II packages here; TODO: should be unified into a single location
9893+ #ReqPackages = ['git','numpy','matplotlib','wx','OpenGL','scipy'] # assume present
9894+ NewReqPackages = ['CifFile' , 'conda' ] # make sure installed
9895+ # packages that are optional but should be present for all of GSAS-II to function:
9896+ RunOptPackages = ['PIL' ,'requests' ,'h5py' ,'imageio' ,'zarr' ,'xmltodict' ,'pybaselines' ,'seekpath' ]
9897+ # where the import name is not the package name, translate with:
9898+ pkgnames = {'wx' :'wxpython' , 'OpenGL' :'pyopengl' ,'CifFile' :'PyCifRW' ,'PIL' :'pillow' ,
9899+ 'git' :'gitpython' }
9900+ install = ['PyCifRW' ,'pybaselines' ] # these need to be reinstalled as they are no longer "vendored"
9901+ for pkglist in NewReqPackages ,RunOptPackages : # Packages
9902+ for pkg in pkglist :
9903+ try :
9904+ exec ('import ' + pkg )
9905+ except :
9906+ install .append (pkgnames .get (pkg ,pkg ))
9907+ #install = [] # TODO: skip on testing
9908+ if install :
9909+ print ('Installing packages: ' ,' ,' .join (install ))
9910+ dlg = wx .ProgressDialog ('Installing Python packages' ,
9911+ f'Please wait while conda downloads and installs { len (install )} package(s). This can take a while.' ,10 ,
9912+ style = wx .PD_AUTO_HIDE )
9913+ dlg .Update (1 )
9914+ GSASIIpath .condaInstall (install )
9915+ dlg .Destroy ()
9916+
9917+
9918+ # 2) switch to the main branch
9919+ #=======================================
9920+ print ('Starting checkout of new branch' )
9921+ a = g2repo .git .checkout ("main" )
98419922 if 'Your branch is behind' in a :
98429923 print ('updating local copy of branch' )
98439924 print (g2repo .git .pull ())
9844- # post-install stuff (following gitstrap.py)
9925+
9926+ # post-install stuff
98459927 print (f'Byte-compiling all .py files in { GSASIIpath .path2GSAS2 !r} ... ' ,end = '' )
98469928 import compileall
98479929 compileall .compile_dir (GSASIIpath .path2GSAS2 ,quiet = True )
98489930 print ('done' )
9849- #
9850- print ('start system-specific install' )
9931+
9932+ # now run the replaced system-specific installers to create shortcuts
9933+ # pointing to G2.py
9934+ print ('\n Start system-specific install' )
98519935 for k ,s in {'win' :"makeBat.py" , 'darwin' :"makeMacApp.py" ,
98529936 'linux' :"makeLinux.py" }.items ():
98539937 if sys .platform .startswith (k ):
@@ -9876,11 +9960,15 @@ def gitSwitch2DevBranch(event):
98769960 with open (sys .argv [0 ]) as source_file :
98779961 exec (source_file .read ())
98789962
9879- print ('system-specific install done' )
9963+ print ('system-specific install done, restarting \n \n ' )
98809964
9881- G2fil .openInNewTerm (project )
9882- print ('exiting GSAS-II' )
9883- sys .exit ()
9965+ g2script = os .path .join (GSASIIpath .path2GSAS2 ,'G2.py' )
9966+ if os .path .exists (g2script ):
9967+ G2fil .openInNewTerm (project ,g2script )
9968+ print ('exiting this session after update completed' )
9969+ sys .exit ()
9970+ else :
9971+ print (f'Unexpected error: file { g2script !r} not found' )
98849972
98859973#===========================================================================
98869974# Importer GUI stuff
0 commit comments