Skip to content

Commit d428df6

Browse files
committed
Some environment variables may now be overriden using "settings\winpython.ini"
(currently supports PATH, PYTHONPATH and PYTHONSTARTUP).
1 parent 3a213ed commit d428df6

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

portable/launcher.nsi

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ end_workdir:
5252

5353
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("WINPYDIR", "${WINPYDIR}").r0'
5454
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("WINPYVER", "${WINPYVER}").r0'
55-
ReadEnvStr $R0 "PATH"
56-
StrCpy $R0 "${PREPATH};$R0;${POSTPATH}"
57-
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r0'
5855

56+
;================================================================
57+
; Settings directory
5958
IfFileExists "$EXEDIR\settings\*.*" 0 end_settings
6059
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("HOME", "$EXEDIR\settings").r0'
6160
StrCmp "${SETTINGSDIR}" "" end_settings
6261
CreateDirectory "$EXEDIR\settings\${SETTINGSDIR}"
62+
; Handle portability in Spyder's settings
6363
StrCpy $R5 "$EXEDIR\settings\${SETTINGSDIR}\${SETTINGSNAME}"
6464
ReadINIStr $0 $R5 "main" last_drive
6565
${GetRoot} $EXEDIR $1
@@ -69,7 +69,52 @@ ${ReplaceInFile} $R5 "$0\\" "$1\\"
6969
write_settings:
7070
WriteINIStr $R5 "main" last_drive $1
7171
end_settings:
72+
;================================================================
73+
74+
75+
; WinPython settings
76+
StrCpy $R6 "$EXEDIR\settings\winpython.ini"
77+
IfFileExists $R6 winpython_settings_done
78+
ClearErrors
79+
FileOpen $0 $R6 w
80+
IfErrors winpython_settings_done
81+
FileWrite $0 "$\r$\n[environment]"
82+
FileWrite $0 "$\r$\n## Uncomment following lines to override environment variables"
83+
FileWrite $0 "$\r$\n#path = "
84+
FileWrite $0 "$\r$\n#pythonpath = "
85+
FileWrite $0 "$\r$\n#pythonstartup = "
86+
FileClose $0
87+
winpython_settings_done:
88+
89+
90+
; PATH
91+
IfFileExists $R6 0 no_path_replacement
92+
ReadINIStr $0 $R6 "environment" path
93+
IfErrors no_path_replacement
94+
StrCpy $R0 $0
95+
Goto set_path
96+
no_path_replacement:
97+
ReadEnvStr $R0 "PATH"
98+
set_path:
99+
StrCpy $R0 "${PREPATH};$R0;${POSTPATH}"
100+
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r0'
101+
102+
; PYTHONPATH
103+
IfFileExists $R6 0 no_pythonpath_replacement
104+
ReadINIStr $R0 $R6 "environment" pythonpath
105+
IfErrors no_pythonpath_replacement
106+
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PYTHONPATH", R0).r0'
107+
no_pythonpath_replacement:
108+
109+
; PYTHONSTARTUP
110+
IfFileExists $R6 0 no_pythonstartup_replacement
111+
ReadINIStr $R0 $R6 "environment" pythonstartup
112+
IfErrors no_pythonstartup_replacement
113+
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PYTHONSTARTUP", R0).r0'
114+
no_pythonstartup_replacement:
115+
72116

117+
; Command line parameters
73118
${GetParameters} $R1
74119
StrCmp "${PARAMETERS}" "" end_param 0
75120
StrCpy $R1 "${PARAMETERS} $R1"

0 commit comments

Comments
 (0)