Skip to content

Commit 84a75ad

Browse files
authored
Merge pull request #2827 from ales-erjavec/fixes/win-installer
[FIX] Windows installers: Python lookup
2 parents 0f452d9 + 058f0ea commit 84a75ad

File tree

4 files changed

+77
-49
lines changed

4 files changed

+77
-49
lines changed

scripts/windows/PythonHelpers.nsh

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11

22
!include TextFunc.nsh
33

4-
# ${GetPythonInstall} VERSION $(user_var: INSTALL_PREFIX) $(user_var: INSTALL_MODE)
4+
# ${GetPythonInstallPEP514} COMPANY TAG $(user_var: INSTALL_PREFIX) $(user_var: INSTALL_MODE)
55
#
6-
# Retrive the registered install prefix for Python
7-
# - input: VERSION is a Major.Minor version number
6+
# Retrive the registered install prefix for Python (as documented by PEP 514)
7+
# - input: COMPANY distibutor (use PythonCore for default pyhton.org
8+
# distributed python)
9+
# - input: TAG environemnt tag (e.g 3.6 or 3.6-32; sys.winver for PythonCore)
810
# - output: INSTALL_PREFIX installation path (e.g C:\Python35) or empty if
911
# not found
1012
# - output: INSTALL_MODE
11-
# 1 if Python was installed for all users or 0 if
12-
# current user only (-1 when not installed).
13+
# 1 if Python was installed for all users, 0 if
14+
# current user only or -1 when not found.
1315
#
1416
# Example
1517
# -------
16-
# ${GetPythonInstall} 3.5 $PythonDir $InstallMode
17-
18+
# ${GetPythonInstallPEP14} PythonCore 3.5 $PythonDir $InstallMode
19+
# ${GetPythonInstallPEP14} ContinuumAnalytics Anaconda36-64 $1 $2
1820

19-
!macro __GET_PYTHON_INSTALL VERSION INSTALL_PREFIX INSTALL_MODE
21+
!macro __GET_PYTHON_INSTALL_PEP514 COMPANY TAG INSTALL_PREFIX INSTALL_MODE
2022
ReadRegStr ${INSTALL_PREFIX} \
21-
HKCU Software\Python\PythonCore\${VERSION}\InstallPath ""
23+
HKCU Software\Python\${COMPANY}\${TAG}\InstallPath ""
2224
${If} ${INSTALL_PREFIX} != ""
2325
StrCpy ${INSTALL_MODE} 0
2426
${Else}
2527
ReadRegStr ${INSTALL_PREFIX} \
26-
HKLM Software\Python\PythonCore\${VERSION}\InstallPath ""
28+
HKLM Software\Python\${COMPANY}\${TAG}\InstallPath ""
2729
${If} ${INSTALL_PREFIX} != ""
2830
StrCpy ${INSTALL_MODE} 1
2931
${Else}
@@ -43,56 +45,55 @@
4345
Pop $0
4446
${EndIf}
4547
!macroend
46-
!define GetPythonInstall "!insertmacro __GET_PYTHON_INSTALL"
48+
!define GetPythonInstallPEP514 "!insertmacro __GET_PYTHON_INSTALL_PEP514"
49+
50+
51+
# ${GetPythonInstall} VERSION BITS $(user_var: INSTALL_PREFIX) $(user_var: INSTALL_MODE)
52+
#
53+
# Retrive the registered install prefix for Python
54+
# - input: VERSION is a Major.Minor version number
55+
# - input: BITS is 32 or 64 constant speciying which python arch to lookup
56+
# - output: INSTALL_PREFIX installation path (e.g C:\Python35) or empty if
57+
# not found
58+
# - output: INSTALL_MODE
59+
# 1 if Python was installed for all users, 0 if
60+
# current user only or -1 when not found.
61+
#
62+
# Example
63+
# -------
64+
# ${GetPythonInstall} 3.5 64 $PythonDir $InstallMode
4765

66+
!macro __GET_PYTHON_INSTALL VERSION BITS INSTALL_PREFIX INSTALL_MODE
67+
!if ${VERSION} < 3.5
68+
!define __TAG ${VERSION}
69+
!else if ${BITS} == 64
70+
!define __TAG ${VERSION}
71+
!else
72+
!define __TAG ${VERSION}-${BITS}
73+
!endif
74+
${GetPythonInstallPEP514} PythonCore ${__TAG} ${INSTALL_PREFIX} ${INSTALL_MODE}
75+
!undef __TAG
76+
!macroend
77+
!define GetPythonInstall "!insertmacro __GET_PYTHON_INSTALL"
4878

4979
# ${GetAnacondaInstall} VERSIONTAG BITS $(user_var: INSTALL_PREFIX) $(user_var: INSTALL_MODE)
5080
#
5181
# Retrive the registered install prefix for Python
5282
# - input: VERSIONTAG is a MajorMinor version number (no dots)
53-
# - input: BITS 34 or 64 (constant!)
83+
# - input: BITS 34 or 64 (constant)
5484
# - output: INSTALL_PREFIX installation path (e.g C:\Python35)
5585
# - output: INSTALL_MODE
5686
# 1 if Python was installed for all users or 0 if
5787
# current user only (-1 when not installed).
5888
#
5989
# Example
6090
# -------
61-
# ${GetPythonInstall} 3.5 $PythonDir $InstallMode
91+
# ${GetAnacondaInstall} 35 64 $PythonDir $InstallMode
6292

6393
!macro __GET_CONDA_INSTALL VERSION_TAG BITS INSTALL_PREFIX INSTALL_MODE
64-
!define __CONDA_REG_PREFIX \
65-
Software\Python\ContinuumAnalytics\Anaconda${VERSION_TAG}-${BITS}
66-
67-
!if "${BITS}" != 32
68-
!if "${BITS}" != 64
69-
!error "BITS must be a 32 or 64 constant"
70-
!endif
71-
!endif
72-
ReadRegStr ${INSTALL_PREFIX} HKCU ${__CONDA_REG_PREFIX}\InstallPath ""
73-
${If} ${INSTALL_PREFIX} != ""
74-
StrCpy ${INSTALL_MODE} 0
75-
${Else}
76-
ReadRegStr ${INSTALL_PREFIX} HKLM ${__CONDA_REG_PREFIX}\InstallPath ""
77-
${If} ${INSTALL_PREFIX} != ""
78-
StrCpy ${INSTALL_MODE} 1
79-
${Else}
80-
StrCpy ${INSTALL_MODE} 0
81-
${EndIf}
82-
${EndIf}
83-
84-
${If} ${INSTALL_PREFIX} != ""
85-
# Strip (single) trailing '\' if present
86-
Push $0
87-
StrCpy $0 ${INSTALL_PREFIX} "" -1
88-
${If} $0 == "\"
89-
StrLen $0 ${INSTALL_PREFIX}
90-
IntOp $0 $0 - 1
91-
StrCpy ${INSTALL_PREFIX} ${INSTALL_PREFIX} $0 0
92-
${EndIf}
93-
Pop $0
94-
${EndIf}
95-
!undef __CONDA_REG_PREFIX
94+
!define __TAG Anaconda${VERSION_TAG}-${BITS}
95+
${GetPythonInstallPEP514} ContinuumAnalytics ${__TAG} ${INSTALL_PREFIX} ${INSTALL_MODE}
96+
!undef __TAG
9697
!macroend
9798
!define GetAnacondaInstall "!insertmacro __GET_CONDA_INSTALL"
9899

@@ -118,6 +119,8 @@
118119
ReadRegStr $2 ${ROOT_KEY} \
119120
"${__CONDA_REG_PREFIX}\$1\InstallPath" ""
120121
${If} $2 != ""
122+
${AndIf} ${FileExists} "$2\python.exe"
123+
${AndIf} ${FileExists} "$2\Scripts\conda.exe"
121124
${LogWrite} "${ROOT_KEY} ${__CONDA_REG_PREFIX}\$1\InstallPath: $2"
122125
Exch $2 # <stack> $0, $1, $2, "prefix"
123126
${EndIf}

scripts/windows/condainstall.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ rem # with a local package, we need to create it manually.
3030
echo @echo off > "%PREFIX%\Scripts\conda.bat"
3131
echo call "%CONDA%" %%* >> "%PREFIX%\Scripts\conda.bat"
3232

33+
rem # same for activate.bat
34+
rem #
35+
for %%f in ( "%CONDA%" ) do ( set "CONDA_DIR=%%~dpf" )
36+
echo @echo off > "%PREFIX%\Scripts\activate.bat"
37+
echo call "%CONDA_DIR%\activate.bat" %%* >> "%PREFIX%\Scripts\activate.bat"
38+
set CONDA_DIR=
39+
3340
rem # Create .condarc file that includes conda-forge channel
3441
rem # We need it so add-ons can be installed from conda-forge
3542
echo Appending conda-forge channel

scripts/windows/orange-conda.nsi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ Var StartMenuFolder
171171
# - no check box to enable/disable start menu creation
172172
# (is controled by the Components Page)
173173
!define MUI_STARTMENUPAGE_NODISABLE
174+
# Registry key path where the selected start folder name is stored
175+
!define MUI_STARTMENUPAGE_REGISTRY_ROOT SHELL_CONTEXT
176+
!define MUI_STARTMENUPAGE_REGISTRY_KEY ${INSTALL_SETTINGS_KEY}
177+
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuFolder
174178
!insertmacro MUI_PAGE_STARTMENU StartMenuPageID $StartMenuFolder
175179

176180
# Install Files page:
@@ -574,6 +578,11 @@ Section "Start Menu Shortcuts" SectionStartMenu
574578
"$SMPROGRAMS\$StartMenuFolder\${LAUNCHER_SHORTCUT_NAME}.lnk" \
575579
"$PythonExecPrefix\pythonw.exe" "-m Orange.canvas" \
576580
"$PythonPrefix\share\orange3\icons\orange.ico" 0
581+
582+
# A utility shortcut for activating the environment
583+
CreateShortCut \
584+
"$SMPROGRAMS\$StartMenuFolder\${APPNAME} Command Prompt.lnk" \
585+
"%COMSPEC%" '/S /K ""$PythonScriptsPrefix\activate.bat" "$InstDir""'
577586
${EndIf}
578587
!insertmacro MUI_STARTMENU_WRITE_END
579588
SectionEnd
@@ -604,6 +613,7 @@ Function un.Shortcuts
604613
${LogWrite} "Removing Start Menu Shortcuts (from $SMPROGRAMS\$0)"
605614
DetailPrint "Removing Start Menu shortcuts"
606615
Delete "$SMPROGRAMS\$0\${LAUNCHER_SHORTCUT_NAME}.lnk"
616+
Delete "$SMPROGRAMS\$0\${APPNAME} Command Prompt.lnk"
607617
RMDir "$SMPROGRAMS\$0"
608618
${EndIf}
609619
${LogWrite} "Removing Desktop shortcurt"
@@ -743,8 +753,8 @@ Section Uninstall
743753
${LogWrite} " PythonPrefix: $PythonPrefix"
744754
${LogWrite} " BasePythonPrefix: $BasePythonPrefix"
745755
746-
Call un.Register
747756
Call un.Shortcuts
757+
Call un.Register
748758
Call un.Launchers
749759
Call un.InstallPackages
750760
Call un.Environment

scripts/windows/orange-install.nsi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ Var StartMenuFolder
189189
# - no check box to enable/disable start menu creation
190190
# (is controled by the Components Page)
191191
!define MUI_STARTMENUPAGE_NODISABLE
192+
# Registry key path where the selected start folder name is stored
193+
!define MUI_STARTMENUPAGE_REGISTRY_ROOT SHELL_CONTEXT
194+
!define MUI_STARTMENUPAGE_REGISTRY_KEY ${INSTALL_SETTINGS_KEY}
195+
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuFolder
192196
!insertmacro MUI_PAGE_STARTMENU StartMenuPageID $StartMenuFolder
193197

194198
# Install Files page:
@@ -446,7 +450,7 @@ Section "Python ${PYTHON_VERSION} (${BITS} bit)" SectionPython
446450
Abort "Python installation failed (error value: $0)"
447451
${EndIf}
448452
${GetPythonInstall} \
449-
"${PYMAJOR}.${PYMINOR}" $BasePythonPrefix $PythonInstallMode
453+
"${PYMAJOR}.${PYMINOR}" ${BITS} $BasePythonPrefix $PythonInstallMode
450454
${If} $BasePythonPrefix == ""
451455
Abort "Python installation failed (cannot determine Python \
452456
installation prefix)."
@@ -639,6 +643,9 @@ Function un.Shortcuts
639643
${LogWrite} "Removing Start Menu Shortcuts (from $SMPROGRAMS\$0)"
640644
DetailPrint "Removing Start Menu shortcuts"
641645
Delete "$SMPROGRAMS\$0\${LAUNCHER_SHORTCUT_NAME}.lnk"
646+
!if ${PYINSTALL_TYPE} == Normal
647+
Delete "$SMPROGRAMS\$0\${APPNAME} Command Prompt.lnk"
648+
!endif
642649
RMDir "$SMPROGRAMS\$0"
643650
${EndIf}
644651
${LogWrite} "Removing Desktop shortcurt"
@@ -780,8 +787,8 @@ Section Uninstall
780787
${LogWrite} " PythonPrefix: $PythonPrefix"
781788
${LogWrite} " BasePythonPrefix: $BasePythonPrefix"
782789
783-
Call un.Register
784790
Call un.Shortcuts
791+
Call un.Register
785792
Call un.Launchers
786793
Call un.InstallPackages
787794
Call un.Environment
@@ -811,7 +818,8 @@ Function .onInit
811818
!insertmacro MULTIUSER_INIT
812819
813820
!if ${PYINSTALL_TYPE} == Normal
814-
${GetPythonInstall} ${PYMAJOR}.${PYMINOR} $BasePythonPrefix $PythonInstallMode
821+
${GetPythonInstall} ${PYMAJOR}.${PYMINOR} ${BITS} \
822+
$BasePythonPrefix $PythonInstallMode
815823
${LogWrite} "Python Prefix: $BasePythonPrefix"
816824
${LogWrite} "Python Install Type: $PythonInstallMode"
817825
${If} $BasePythonPrefix != ""

0 commit comments

Comments
 (0)