summaryrefslogtreecommitdiffstats
path: root/PCbuild/find_python.bat
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-07-18 17:31:51 (GMT)
committerGitHub <noreply@github.com>2017-07-18 17:31:51 (GMT)
commit5feda33a35d9413e2073411b848dc49d94c57497 (patch)
tree8feca7a57aa1a9cfc173bb83650954b82d123997 /PCbuild/find_python.bat
parent4ed5ad79ec6c6270e6018bd0a55656305ee60907 (diff)
downloadcpython-5feda33a35d9413e2073411b848dc49d94c57497.zip
cpython-5feda33a35d9413e2073411b848dc49d94c57497.tar.gz
cpython-5feda33a35d9413e2073411b848dc49d94c57497.tar.bz2
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
Diffstat (limited to 'PCbuild/find_python.bat')
-rw-r--r--PCbuild/find_python.bat21
1 files changed, 19 insertions, 2 deletions
diff --git a/PCbuild/find_python.bat b/PCbuild/find_python.bat
index 82358c8..ba3a0f5 100644
--- a/PCbuild/find_python.bat
+++ b/PCbuild/find_python.bat
@@ -30,20 +30,28 @@
@rem If we have Python in externals, use that one
@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
+@rem If HOST_PYTHON is recent enough, use that
+@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
+
@rem If py.exe finds a recent enough version, use that one
@py -3.6 -V >nul 2>&1 && (set PYTHON=py -3.6) && (set _Py_Python_Source=found with py.exe) && goto :found
@if NOT exist "%_Py_EXTERNALS_DIR%" mkdir "%_Py_EXTERNALS_DIR%"
@set _Py_NUGET=%NUGET%
@set _Py_NUGET_URL=%NUGET_URL%
-@if "%_Py_NUGET%"=="" (set _Py_NUGET=%EXTERNALS_DIR%\nuget.exe)
+@set _Py_HOST_PYTHON=%HOST_PYTHON%
+@if "%_Py_HOST_PYTHON%"=="" set _Py_HOST_PYTHON=py
+@if "%_Py_NUGET%"=="" (set _Py_NUGET=%_Py_EXTERNALS_DIR%\nuget.exe)
@if "%_Py_NUGET_URL%"=="" (set _Py_NUGET_URL=https://aka.ms/nugetclidl)
@if NOT exist "%_Py_NUGET%" (
@echo Downloading nuget...
@rem NB: Must use single quotes around NUGET here, NOT double!
@rem Otherwise, a space in the path would break things
@rem If it fails, retry with any available copy of Python
- @powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%' || @py -c "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
+ @powershell.exe -Command Invoke-WebRequest %_Py_NUGET_URL% -OutFile '%_Py_NUGET%'
+ @if errorlevel 1 (
+ @%_Py_HOST_PYTHON% "%~dp0\urlretrieve.py" "%_Py_NUGET_URL%" "%_Py_NUGET%"
+ )
)
@echo Installing Python via nuget...
@"%_Py_NUGET%" install pythonx86 -ExcludeVersion -OutputDirectory "%_Py_EXTERNALS_DIR%"
@@ -51,8 +59,17 @@
@if not errorlevel 1 (set PYTHON="%_Py_EXTERNALS_DIR%\pythonx86\tools\python.exe") & (set _Py_Python_Source=found on nuget.org) & goto :found
+@set _Py_Python_Source=
+@set _Py_EXTERNALS_DIR=
+@set _Py_NUGET=
+@set _Py_NUGET_URL=
+@set _Py_HOST_PYTHON=
@exit /b 1
:found
@echo Using %PYTHON% (%_Py_Python_Source%)
@set _Py_Python_Source=
+@set _Py_EXTERNALS_DIR=
+@set _Py_NUGET=
+@set _Py_NUGET_URL=
+@set _Py_HOST_PYTHON=