Skip to content

Commit aef9ec2

Browse files
committed
more improvements to .bat files created during windows install
1 parent 1656661 commit aef9ec2

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

GSASII/install/makeBat.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,48 +77,60 @@
7777
fp.write("@REM created by run of makeBat.py on {:%d %b %Y %H:%M}\n".format(
7878
datetime.datetime.now()))
7979
#activate = os.path.join(os.path.split(pythonexe)[0],'Scripts','activate')
80-
activate = os.path.join(os.path.split(pythonexe)[0],'condabin','conda.bat')
80+
installloc = os.path.split(pythonexe)[0]
81+
activate = os.path.join(installloc,'condabin','conda.bat')
8182
print("Looking for",activate)
8283
# for a non-base conda install, it might be better to use the activate in
8384
# the base, but for now let's use the one we find relative to our python
8485
if os.path.exists(activate):
8586
activate = os.path.realpath(activate)
86-
if ' ' in activate:
87-
activate = f'call "{activate}" activate\n'
88-
else:
89-
activate = f'call {activate} activate\n'
90-
print(f'adding activate command to .bat file\n({activate})')
87+
if ' ' in activate: activate = f'"{activate}"'
88+
if ' ' in installloc: installloc = f'"{installloc}"'
89+
actcmd = f'''@echo {activate} activate
90+
@call {activate} activate
91+
@REM In case the previous did not work because a different conda is active, the
92+
@REM next command should fix that. If it did work, it will not change anything
93+
@echo call conda activate {installloc}
94+
@call conda activate {installloc}
95+
'''
96+
print(f'adding activate command to .bat file\n({actcmd})')
9197
else:
9298
print('Note: conda activate not found')
93-
activate = '@REM no activate command found'
99+
actcmd = '@REM no activate command found\n'
94100
#pexe = pythonexe
95101
#if ' ' in pythonexe: pexe = '"'+pythonexe+'"'
96102
G2s = G2script
97103
if ' ' in G2s: G2s = '"'+G2script+'"'
98-
fp.write(Script.format(activate,'python.exe',G2s))
104+
fp.write(Script.format(actcmd,'python.exe',G2s))
99105
fp.close()
100106
print(f'\nCreated GSAS-II batch file {G2bat}')
101107

102108
# create a reset script
103109
gitstrap = os.path.abspath(
104110
os.path.normpath(os.path.join(path2repo,'..','gitstrap.py')))
111+
G2s = gitstrap
112+
if ' ' in G2s: G2s = '"'+gitstrap+'"'
105113
if not os.path.exists:
106114
print(f'the installation script was not found: {gitstrap!r}')
107115
else:
108116
G2reset = os.path.normpath(os.path.join(path2repo,'..','2Reset2FreshGSASII.bat'))
109117
fp = open(G2reset,'w')
110118
fp.write("@REM created by run of makeBat.py on {:%d %b %Y %H:%M}\n".format(
111119
datetime.datetime.now()))
112-
fp.write("REM This script will reset GSAS-II to the latest version, even if the program can't be started\n")
120+
fp.write("@echo This script will reset GSAS-II to the latest version, even if the program can't be started\n")
121+
if os.path.exists(activate): fp.write(f"{actcmd}")
122+
113123
pexe = pythonexe
114124
if ' ' in pythonexe: pexe = '"'+pythonexe+'"'
115-
G2s = gitstrap
116-
if ' ' in G2s: G2s = '"'+gitstrap+'"'
117-
if activate: fp.write(f"{activate}")
118125
fp.write('choice /c yn /n /m "Reset any local changes and install latest GSAS-II version? (y/n)"\n')
119126
fp.write(f"goto %ERRORLEVEL%\n")
120127
fp.write(f":1\n")
128+
fp.write("@echo Updating to the current version of the gitstrap script\n")
129+
fp.write(f"curl -L -o {G2s} https://github.com/AdvancedPhotonSource/GSAS-II-buildtools/raw/main/install/gitstrap.py\n")
130+
fp.write("@echo Now running gitstrap to update downloaded files (--reset)...\n")
121131
fp.write(f"{pexe} {G2s} --reset\n")
132+
fp.write("@echo Now running gitstrap to create .bat files (--nodownload)...\n")
133+
fp.write(f"{pexe} {G2s} --nodownload\n")
122134
fp.write(f":2\n")
123135
fp.write(f"pause\n")
124136
fp.close()

0 commit comments

Comments
 (0)