Skip to content

Commit 5feda33

Browse files
authored
bpo-30450: Fix logic for retrying nuget.exe download (#2744)
Fix logic for retrying nuget.exe download with Python. Add support for HOST_PYTHON variable. Clear internal environment variables used in find_python.bat Use HOST_PYTHON as the actual Python if it is recent enough. Adds HOST_PYTHON variable to AppVeyor configuration
1 parent 4ed5ad7 commit 5feda33

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.github/appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ build_script:
99
- cmd: PCbuild\build.bat -e
1010
test_script:
1111
- cmd: PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 --fail-env-changed -j0
12+
environment:
13+
HOST_PYTHON: C:\Python36\python.exe
1214

1315
# Only trigger AppVeyor if actual code or its configuration changes
1416
only_commits:

PCbuild/find_python.bat

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,46 @@
3030
@rem If we have Python in externals, use that one
3131
@if exist "%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe" (set PYTHON="%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe") & (set _Py_Python_Source=found in externals directory) & goto :found
3232

33+
@rem If HOST_PYTHON is recent enough, use that
34+
@if NOT "%HOST_PYTHON%"=="" @%HOST_PYTHON% -c "import sys; assert sys.version_info[:2] >= (3, 6)" >nul 2>nul && (set PYTHON="%HOST_PYTHON%") && (set _Py_Python_Source=found as HOST_PYTHON) && goto :found
35+
3336
@rem If py.exe finds a recent enough version, use that one
3437
@py -3.6 -V >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
3538

3639
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
3740
@set _Py_NUGET=%NUGET%
3841
@set _Py_NUGET_URL=%NUGET_URL%
39-
@if "%_Py_NUGET%"=="" (set _Py_NUGET=%EXTERNALS_DIR%\nuget.exe)
42+
@set _Py_HOST_PYTHON=%HOST_PYTHON%
43+
@if "%_Py_HOST_PYTHON%"=="" set _Py_HOST_PYTHON=py
44+
@if "%_Py_NUGET%"=="" (set _Py_NUGET=%_Py_EXTERNALS_DIR%\nuget.exe)
4045
@if "%_Py_NUGET_URL%"=="" (set _Py_NUGET_URL=https://aka.ms/nugetclidl)
4146
@if NOT exist "%_Py_NUGET%" (
4247
@echo Downloading nuget...
4348
@rem NB: Must use single quotes around NUGET here, NOT double!
4449
@rem Otherwise, a space in the path would break things
4550
@rem If it fails, retry with any available copy of Python
46-
@powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%' || @py -c "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
51+
@powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%'
52+
@if errorlevel 1 (
53+
@%_Py_HOST_PYTHON% "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
54+
)
4755
)
4856
@echo Installing Python via nuget...
4957
@"%_Py_NUGET%" install pythonx86 -ExcludeVersion -OutputDirectory "%_Py_EXTERNALS_DIR%"
5058
@rem Quote it here; it's not quoted later because "py -3.6" wouldn't work
5159
@if not errorlevel 1 (set PYTHON="%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe") & (set _Py_Python_Source=found on nuget.org) & goto :found
5260

5361

62+
@set _Py_Python_Source=
63+
@set _Py_EXTERNALS_DIR=
64+
@set _Py_NUGET=
65+
@set _Py_NUGET_URL=
66+
@set _Py_HOST_PYTHON=
5467
@exit /b 1
5568

5669
:found
5770
@echo Using %PYTHON% (%_Py_Python_Source%)
5871
@set _Py_Python_Source=
72+
@set _Py_EXTERNALS_DIR=
73+
@set _Py_NUGET=
74+
@set _Py_NUGET_URL=
75+
@set _Py_HOST_PYTHON=

0 commit comments

Comments
 (0)