33echo Looking for Python
44setlocal enabledelayedexpansion
55
6- :: To remove the preference for Python 2, but still support it, just remove
7- :: the 5 blocks marked with "Python 2:" and the support warnings
8-
9- :: Python 2: If python.exe is in %Path%, use if it's Python 2
10- FOR /F " delims=" %%a IN ('where python.exe 2^ > NUL ') DO (
11- SET need_path = 0
12- SET p = %%~dpa
13- CALL :validate-v2
14- IF NOT ERRORLEVEL 1 GOTO :found-python2
15- GOTO :done-path-v2
16- )
17- :done-path-v2
18-
19- :: Python 2: Query the 3 locations mentioned in PEP 514 for a python2 InstallPath
20- FOR %%K IN ( " HKCU\Software" , " HKLM\SOFTWARE" , " HKLM\Software\Wow6432Node" ) DO (
21- SET need_path = 1
22- CALL :find-versions-v2 %%K
23- IF NOT ERRORLEVEL 1 CALL :validate-v2
24- IF NOT ERRORLEVEL 1 GOTO :found-python2
25- )
26-
276:: Use python.exe if in %PATH%
287set need_path = 0
298for /f " delims=" %%a in ('where python.exe 2^ > nul ') do (
@@ -41,14 +20,6 @@ for %%k in ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") do (
4120goto :no-python
4221
4322
44- :: Python 2: Find Python 2 installations in a registry location
45- :find-versions-v2
46- for /f " delims=" %%a in ('reg query " %~1 \Python\PythonCore" /f * /k 2^ > nul ^ | findstr /r ^^ HK ^ | findstr " \\2\." ') do (
47- call :read-installpath %%a
48- if not errorlevel 1 exit /b 0
49- )
50- exit /b 1
51-
5223:: Find Python installations in a registry location
5324:find-versions
5425for /f " delims=" %%a in ('reg query " %~1 \Python\PythonCore" /f * /k 2^ > nul ^ | findstr /r ^^ HK') do (
@@ -73,32 +44,11 @@ for /f "skip=2 tokens=1* delims=)" %%a in ('reg query "%1\InstallPath" /ve /t RE
7344)
7445exit /b 1
7546
76-
77- :: Python 2: Check if %p% holds a path to a real python2 executable
78- :validate-v2
79- IF NOT EXIST " %p% \python.exe" EXIT /B 1
80- :: Check if %p% is python2
81- " %p% \python.exe" -V 2 >& 1 | findstr /R " ^Python.2.*" > NUL
82- EXIT /B %ERRORLEVEL%
83-
84-
85- :: Python 2:
86- :found-python2
87- echo Python 2 found in %p% \python.exe
88- set pyver = 2
89- goto :done
90-
9147:found-python
9248echo Python found in %p% \python.exe
93- echo WARNING: Python 3 is not yet fully supported, to avoid issues Python 2 should be installed.
94- set pyver = 3
95- goto :done
96-
97- :done
9849endlocal ^
9950 & set " pt = %p% " ^
100- & set " need_path_ext = %need_path% " ^
101- & set " VCBUILD_PYTHON_VERSION = %pyver% "
51+ & set " need_path_ext = %need_path% "
10252set " VCBUILD_PYTHON_LOCATION = %pt% \python.exe"
10353if %need_path_ext% == 1 set " PATH = %pt% ;%PATH% "
10454set " pt = "
0 commit comments