Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e13a634

Browse filesBrowse files
joaocgreisBridgeAR
authored andcommitted
build,win: accept Python 3 if 2 is not available
If there is no Python 2 available, use Python 3. This allows to test running configure with Python 3. PR-URL: #29236 Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8baca8e commit e13a634
Copy full SHA for e13a634

File tree

Expand file treeCollapse file tree

2 files changed

+67
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+67
-21
lines changed
Open diff view settings
Collapse file

‎tools/msvs/find_python.cmd‎

Copy file name to clipboard
+64-21Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,62 @@
11
@IF NOT DEFINED DEBUG_HELPER @ECHO OFF
22

3-
echo Looking for Python 2.x
3+
echo Looking for Python
44
setlocal enabledelayedexpansion
55

6-
:: If python.exe is in %Path%, just validate
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
710
FOR /F "delims=" %%a IN ('where python.exe 2^> NUL') DO (
811
SET need_path=0
912
SET p=%%~dpa
10-
IF NOT ERRORLEVEL 1 GOTO :validate
13+
CALL :validate-v2
14+
IF NOT ERRORLEVEL 1 GOTO :found-python2
15+
GOTO :done-path-v2
1116
)
17+
:done-path-v2
1218

13-
:: Query the 3 locations mentioned in PEP 514 for a python2 InstallPath
19+
:: Python 2: Query the 3 locations mentioned in PEP 514 for a python2 InstallPath
1420
FOR %%K IN ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") DO (
1521
SET need_path=1
1622
CALL :find-versions-v2 %%K
17-
:: If validate returns 0 just jump to the end
18-
IF NOT ERRORLEVEL 1 GOTO :validate
23+
IF NOT ERRORLEVEL 1 CALL :validate-v2
24+
IF NOT ERRORLEVEL 1 GOTO :found-python2
25+
)
26+
27+
:: Use python.exe if in %PATH%
28+
set need_path=0
29+
for /f "delims=" %%a in ('where python.exe 2^> nul') do (
30+
set p=%%~dpa
31+
goto :found-python
32+
)
33+
34+
:: Query the 3 locations mentioned in PEP 514 for a Python InstallPath
35+
set need_path=1
36+
for %%k in ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") do (
37+
call :find-versions %%k
38+
if not errorlevel 1 goto :found-python
1939
)
2040

2141
goto :no-python
2242

2343

24-
:: Find Python 2 installations in a registry location
44+
:: Python 2: Find Python 2 installations in a registry location
2545
:find-versions-v2
2646
for /f "delims=" %%a in ('reg query "%~1\Python\PythonCore" /f * /k 2^> nul ^| findstr /r ^^HK ^| findstr "\\2\."') do (
2747
call :read-installpath %%a
2848
if not errorlevel 1 exit /b 0
2949
)
3050
exit /b 1
3151

52+
:: Find Python installations in a registry location
53+
:find-versions
54+
for /f "delims=" %%a in ('reg query "%~1\Python\PythonCore" /f * /k 2^> nul ^| findstr /r ^^HK') do (
55+
call :read-installpath %%a
56+
if not errorlevel 1 exit /b 0
57+
)
58+
exit /b 1
59+
3260
:: Read the InstallPath of a given Environment Key to %p%
3361
:: https://www.python.org/dev/peps/pep-0514/#installpath
3462
:read-installpath
@@ -44,22 +72,37 @@ for /f "skip=2 tokens=3*" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^>
4472
exit /b 1
4573

4674

47-
:: Check if %p% holds a path to a real python2 executable
48-
:validate
49-
IF NOT EXIST "%p%python.exe" goto :no-python
75+
:: Python 2: Check if %p% holds a path to a real python2 executable
76+
:validate-v2
77+
IF NOT EXIST "%p%\python.exe" EXIT /B 1
5078
:: Check if %p% is python2
51-
"%p%python.exe" -V 2>&1 | findstr /R "^Python.2.*" > NUL
52-
IF ERRORLEVEL 1 goto :no-python2
53-
:: We can wrap it up
54-
ENDLOCAL & SET pt=%p%& SET need_path_ext=%need_path%
55-
SET VCBUILD_PYTHON_LOCATION=%pt%python.exe
56-
IF %need_path_ext%==1 SET Path=%Path%;%pt%
57-
SET need_path_ext=
79+
"%p%\python.exe" -V 2>&1 | findstr /R "^Python.2.*" > NUL
5880
EXIT /B %ERRORLEVEL%
5981

60-
:no-python2
61-
echo Python found in %p%, but it is not v2.x.
62-
exit /B 1
82+
83+
:: Python 2:
84+
:found-python2
85+
echo Python 2 found in %p%\python.exe
86+
set pyver=2
87+
goto :done
88+
89+
:found-python
90+
echo Python found in %p%\python.exe
91+
echo WARNING: Python 3 is not yet fully supported, to avoid issues Python 2 should be installed.
92+
set pyver=3
93+
goto :done
94+
95+
:done
96+
endlocal ^
97+
& set "pt=%p%" ^
98+
& set "need_path_ext=%need_path%" ^
99+
& set "VCBUILD_PYTHON_VERSION=%pyver%"
100+
set "VCBUILD_PYTHON_LOCATION=%pt%\python.exe"
101+
if %need_path_ext%==1 set "PATH=%pt%;%PATH%"
102+
set "pt="
103+
set "need_path_ext="
104+
exit /b 0
105+
63106
:no-python
64107
echo Could not find Python.
65-
exit /B 1
108+
exit /b 1
Collapse file

‎vcbuild.bat‎

Copy file name to clipboardExpand all lines: vcbuild.bat
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,9 @@ goto exit
689689

690690
:create-msvs-files-failed
691691
echo Failed to create vc project files.
692+
if %VCBUILD_PYTHON_VERSION%==3 (
693+
echo Python 3 is not yet fully supported, to avoid issues Python 2 should be installed.
694+
)
692695
del .used_configure_flags
693696
goto exit
694697

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.