@@ -79,10 +79,12 @@ ${Using:StrFunc} StrStr
7979!define ARCH {{ arch }}
8080!define PLATFORM {{ installer_platform }}
8181!define CONSTRUCTOR_VERSION {{ constructor_version }}
82+ {%- if has_python %}
8283!define PY_VER {{ pyver_components[:2] | join(".") }}
8384!define PYVERSION_JUSTDIGITS {{ pyver_components | join("") }}
8485!define PYVERSION {{ pyver_components | join(".") }}
8586!define PYVERSION_MAJOR {{ pyver_components[0] }}
87+ {%- endif %}
8688!define DEFAULT_PREFIX {{ default_prefix }}
8789!define DEFAULT_PREFIX_DOMAIN_USER {{ default_prefix_domain_user }}
8890!define DEFAULT_PREFIX_ALL_USERS {{ default_prefix_all_users }}
@@ -304,7 +306,9 @@ FunctionEnd
304306 /InstallationType=AllUsers [default: JustMe]$\n\
305307 /AddToPath=[0|1] [default: 0]$\n\
306308 /KeepPkgCache=[0|1] [default: {{ 1 if keep_pkgs else 0 }}]$\n\
309+ {%- if has_python %}
307310 /RegisterPython=[0|1] [default: AllUsers: 1, JustMe: 0]$\n\
311+ {%- endif %}
308312 /NoRegistry=[0|1] [default: AllUsers: 0, JustMe: 0]$\n\
309313 /NoScripts=[0|1] [default: 0]$\n\
310314 /NoShortcuts=[0|1] [default: 0]$\n\
@@ -323,9 +327,14 @@ FunctionEnd
323327 Install for all users, but don't add to PATH env var:$\n\
324328 > $EXEFILE /InstallationType=AllUsers$\n\
325329 $\n\
330+ {%- if has_python %}
326331 Install for just me, add to PATH and register as system Python:$\n\
327332 > $EXEFILE /RegisterPython=1 /AddToPath=1$\n\
328333 $\n\
334+ {%- endif %}
335+ Install for just me and add to PATH:$\n\
336+ > $EXEFILE /AddToPath=1$\n\
337+ $\n\
329338 Install for just me, with no registry modification (for CI):$\n\
330339 > $EXEFILE /NoRegistry=1$\n\
331340 $\n\
@@ -349,6 +358,7 @@ FunctionEnd
349358 ${EndIf}
350359
351360 ClearErrors
361+ {%- if has_python %}
352362 ${GetOptions} $ARGV "/RegisterPython=" $ARGV_RegisterPython
353363 ${IfNot} ${Errors}
354364 ${If} $ARGV_RegisterPython = "1"
@@ -357,6 +367,7 @@ FunctionEnd
357367 StrCpy $Ana_RegisterSystemPython_State ${BST_UNCHECKED}
358368 ${EndIf}
359369 ${EndIf}
370+ {%- endif %}
360371
361372 ClearErrors
362373 ${GetOptions} $ARGV "/KeepPkgCache=" $ARGV_KeepPkgCache
@@ -1142,6 +1153,7 @@ Function OnDirectoryLeave
11421153 UnicodePathTest::UnicodePathTest $INSTDIR
11431154 Pop $R1
11441155
1156+ {%- if has_python %}
11451157 # Python 3 can be installed in a CP_ACP path until MKL is Unicode capable.
11461158 # (mkl_rt.dll calls LoadLibraryA() to load mkl_intel_thread.dll)
11471159 # Python 2 can only be installed to an ASCII path.
@@ -1159,6 +1171,7 @@ Function OnDirectoryLeave
11591171 abort
11601172
11611173 valid_path:
1174+ {%- endif %}
11621175
11631176 Push $R1
11641177 ${IsWritable} $INSTDIR $R1
@@ -1241,6 +1254,50 @@ FunctionEnd
12411254!insertmacro AbortRetryNSExecWaitMacro ""
12421255!insertmacro AbortRetryNSExecWaitMacro "un."
12431256
1257+ {%- set pathname = "$INSTDIR\\condabin" if initialize_conda == "condabin" else "$INSTDIR\\Scripts & Library\\bin" %}
1258+ !macro AddRemovePath add_remove un
1259+ {# python.exe is required if conda-standalone does not support the windows subcommand (<25.11.x) #}
1260+ {%- if needs_python_exe %}
1261+ ${If} ${add_remove} == "add"
1262+ {%- if initialize_conda == 'condabin' %}
1263+ ${Print} "Adding {{ pathname }} PATH..."
1264+ StrCpy $R0 "addcondabinpath"
1265+ {%- else %}
1266+ ${Print} "Adding {{ pathname }} to PATH..."
1267+ StrCpy $R0 "addpath ${PYVERSION} ${NAME} ${VERSION} ${ARCH}"
1268+ {%- endif %}
1269+ StrCpy $R1 "Failed to add {{ NAME }} to PATH"
1270+ ${Else}
1271+ ${Print} "Running rmpath script..."
1272+ StrCpy $R0 "rmpath"
1273+ StrCpy $R1 "Failed to remove {{ NAME }} from PATH"
1274+ ${EndIf}
1275+ ${If} ${Silent}
1276+ push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" $R0'
1277+ ${Else}
1278+ push '"$INSTDIR\python.exe" -E -s "$INSTDIR\Lib\_nsis.py" $R0'
1279+ ${EndIf}
1280+ push $R1
1281+ push 'WithLog'
1282+ call ${un}AbortRetryNSExecWait
1283+ {%- else %}
1284+ {%- set pathflag = "--condabin" if initialize_conda == "condabin" else "--classic" %}
1285+ ${If} ${add_remove} == "add"
1286+ ${Print} "Adding {{ pathname }} to PATH..."
1287+ StrCpy $R0 "prepend"
1288+ StrCpy $R1 'Failed to add {{ NAME }} to PATH'
1289+ ${Else}
1290+ ${Print} "Removing {{ pathname }} from PATH..."
1291+ StrCpy $R0 "remove"
1292+ StrCpy $R1 'Failed to remove {{ NAME }} from PATH'
1293+ ${EndIf}
1294+ push '"$INSTDIR\_conda.exe" constructor windows path --$R0=user --prefix "$INSTDIR" {{ pathflag }}'
1295+ push $R1
1296+ push 'WithLog'
1297+ call ${un}AbortRetryNSExecWait
1298+ {%- endif %}
1299+ !macroend
1300+
12441301!macro setInstdirPermissions
12451302 # To address CVE-2022-26526.
12461303 # Revoke the write permission on directory "$INSTDIR" for Users. Users are:
@@ -1338,9 +1395,11 @@ Section "Install"
13381395 # for users even during an all-users installation.
13391396 !insertmacro setInstdirPermissions
13401397
1398+ {% if needs_python_exe %}
13411399 SetOutPath "$INSTDIR\Lib"
13421400 File "{{ NSIS_DIR }}\_nsis.py"
13431401 File "{{ NSIS_DIR }}\_system_path.py"
1402+ {% endif %}
13441403
13451404{%- if has_license %}
13461405 SetOutPath "$INSTDIR"
@@ -1533,20 +1592,14 @@ Section "Install"
15331592 ${EndIf}
15341593
15351594{% if initialize_conda %}
1536- ${If} $Ana_AddToPath_State = ${BST_CHECKED}
1537- {%- if initialize_conda == 'condabin' %}
1538- ${Print} "Adding $INSTDIR\condabin to PATH..."
1539- push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" addcondabinpath'
1540- {%- else %}
1541- ${Print} "Adding $INSTDIR\Scripts & Library\bin to PATH..."
1542- push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" addpath ${PYVERSION} ${NAME} ${VERSION} ${ARCH}'
1543- {%- endif %}
1544- push 'Failed to add {{ NAME }} to PATH'
1545- push 'WithLog'
1546- call AbortRetryNSExecWait
1595+ ${If} ${FileExists} "$INSTDIR\.nonadmin"
1596+ ${If} $Ana_AddToPath_State = ${BST_CHECKED}
1597+ !insertmacro AddRemovePath "add" ""
1598+ ${EndIf}
15471599 ${EndIf}
15481600{%- endif %}
15491601
1602+ {%- if has_python %}
15501603 # Create registry entries saying this is the system Python
15511604 # (for this version)
15521605 !define PYREG "Software\Python\PythonCore\${PY_VER}"
@@ -1564,6 +1617,7 @@ Section "Install"
15641617 WriteRegStr SHCTX "${PYREG}\PythonPath" \
15651618 "" "$INSTDIR\Lib;$INSTDIR\DLLs"
15661619 ${EndIf}
1620+ {%- endif %}
15671621
15681622 ${If} $ARGV_NoRegistry == "0"
15691623 # Registry uninstall info
@@ -1594,21 +1648,6 @@ Section "Install"
15941648 ${Print} "Done!"
15951649SectionEnd
15961650
1597- !macro AbortRetryNSExecWaitLibNsisCmd cmd
1598- SetDetailsPrint both
1599- ${Print} "Running ${cmd} scripts..."
1600- SetDetailsPrint listonly
1601- ${If} ${Silent}
1602- push '"$INSTDIR\pythonw.exe" -E -s "$INSTDIR\Lib\_nsis.py" ${cmd}'
1603- ${Else}
1604- push '"$INSTDIR\python.exe" -E -s "$INSTDIR\Lib\_nsis.py" ${cmd}'
1605- ${EndIf}
1606- push "Failed to run ${cmd}"
1607- push 'WithLog'
1608- call un.AbortRetryNSExecWait
1609- SetDetailsPrint both
1610- !macroend
1611-
16121651Section "Uninstall"
16131652 ${LogSet} on
16141653 ${If} ${Silent}
@@ -1660,7 +1699,7 @@ Section "Uninstall"
16601699 System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_NAME", "${NAME}").r0'
16611700 StrCpy $0 ${VERSION}
16621701 ${If} $INSTALLER_VERSION != ""
1663- StrCpy $0 $INSTALLER_VERSION
1702+ StrCpy $0 $INSTALLER_VERSION
16641703 ${EndIf}
16651704 System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_VER", "$0").r0'
16661705 System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_PLAT", "${PLATFORM}").r0'
@@ -1671,16 +1710,18 @@ Section "Uninstall"
16711710 System::Call 'kernel32::SetEnvironmentVariable(t,t)i("INSTALLER_UNATTENDED", "0").r0'
16721711 ${EndIf}
16731712
1674- {%- if uninstall_with_conda_exe %}
16751713 ${If} ${FileExists} "$INSTDIR\pkgs\pre_uninstall.bat"
16761714 ${Print} "Running pre_uninstall scripts..."
16771715 push '"$CMD_EXE" /D /C "$INSTDIR\pkgs\pre_uninstall.bat"'
16781716 push "Failed to run pre_uninstall"
16791717 push 'WithLog'
16801718 call un.AbortRetryNSExecWait
16811719 ${EndIf}
1682- !insertmacro AbortRetryNSExecWaitLibNsisCmd "rmpath"
1720+ ${If} ${FileExists} "$INSTDIR\.nonadmin"
1721+ !insertmacro AddRemovePath "remove" "un."
1722+ ${EndIf}
16831723
1724+ {%- if uninstall_with_conda_exe %}
16841725 # Parse arguments
16851726 StrCpy $R0 ""
16861727
@@ -1727,14 +1768,6 @@ Section "Uninstall"
17271768 call un.AbortRetryNSExecWait
17281769 SetDetailsPrint both
17291770{%- endfor %}
1730- ${If} ${FileExists} "$INSTDIR\pkgs\pre_uninstall.bat"
1731- ${Print} "Running pre_uninstall scripts..."
1732- push '"$CMD_EXE" /D /C "$INSTDIR\pkgs\pre_uninstall.bat"'
1733- push "Failed to run pre_uninstall"
1734- push 'WithLog'
1735- call un.AbortRetryNSExecWait
1736- ${EndIf}
1737- !insertmacro AbortRetryNSExecWaitLibNsisCmd "rmpath"
17381771{%- if has_conda %}
17391772 ${If} ${FileExists} "$INSTDIR\.nonadmin"
17401773 StrCpy $R0 "user"
0 commit comments