Compare commits

...

2 Commits
main ... 3.17.x

Author SHA1 Message Date
Jan Tattermusch
5500c72c5b
Reintroduce setup.py changes from #8280 erased by piper import #8902 (#8981) 2021-09-23 10:02:24 -07:00
Adam Cozzette
0770434ff0
Install python38/39 on windows (#8757) (#8771)
Create install_python_interpreters.ps1
Install python38/39 on windows

Co-authored-by: Jie Luo <jieluo@google.com>
2021-06-25 21:23:59 -07:00
3 changed files with 115 additions and 0 deletions

View File

@ -62,6 +62,8 @@ SET PYTHON_VERSION=3.7
SET PYTHON_ARCH=64
CALL build_single_artifact.bat || goto :error
powershell -File kokoro/release/python/windows/install_python_interpreters.ps1
SET PYTHON=C:\python38_32bit
SET PYTHON_VERSION=3.8
SET PYTHON_ARCH=32

View File

@ -0,0 +1,97 @@
#!/usr/bin/env powershell
# Install Python 3.8 for x64 and x86 in order to build wheels on Windows.
# Originally from grpc/tools/internal_ci/helper_scripts/install_python_interpreters.ps1
Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'
trap {
$ErrorActionPreference = "Continue"
Write-Error $_
exit 1
}
# Avoid "Could not create SSL/TLS secure channel"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
function Install-Python {
Param(
[string]$PythonVersion,
[string]$PythonInstaller,
[string]$PythonInstallPath,
[string]$PythonInstallerHash
)
$PythonInstallerUrl = "https://www.python.org/ftp/python/$PythonVersion/$PythonInstaller.exe"
$PythonInstallerPath = "C:\tools\$PythonInstaller.exe"
# Downloads installer
Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath"
Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath
# Validates checksum
$HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5
if ($HashFromDownload.Hash -ne $PythonInstallerHash) {
throw "Invalid Python installer: failed checksum!"
}
Write-Host "Python installer $PythonInstallerPath validated."
# Installs Python
& $PythonInstallerPath /passive InstallAllUsers=1 PrependPath=1 Include_test=0 TargetDir=$PythonInstallPath
if (-Not $?) {
throw "The Python installation exited with error!"
}
# NOTE(lidiz) Even if the install command finishes in the script, that
# doesn't mean the Python installation is finished. If using "ps" to check
# for running processes, you might see ongoing installers at this point.
# So, we needs this "hack" to reliably validate that the Python binary is
# functioning properly.
# Wait for the installer process
Wait-Process -Name $PythonInstaller -Timeout 300
Write-Host "Installation process exits normally."
# Validate Python binary
$PythonBinary = "$PythonInstallPath\python.exe"
& $PythonBinary -c 'print(42)'
Write-Host "Python binary works properly."
# Installs pip
& $PythonBinary -m ensurepip --user
Write-Host "Python $PythonVersion installed by $PythonInstaller at $PythonInstallPath."
}
# Python 3.8
$Python38x86Config = @{
PythonVersion = "3.8.0"
PythonInstaller = "python-3.8.0"
PythonInstallPath = "C:\python38_32bit"
PythonInstallerHash = "412a649d36626d33b8ca5593cf18318c"
}
Install-Python @Python38x86Config
$Python38x64Config = @{
PythonVersion = "3.8.0"
PythonInstaller = "python-3.8.0-amd64"
PythonInstallPath = "C:\python38"
PythonInstallerHash = "29ea87f24c32f5e924b7d63f8a08ee8d"
}
Install-Python @Python38x64Config
# Python 3.9
$Python39x86Config = @{
PythonVersion = "3.9.0"
PythonInstaller = "python-3.9.0"
PythonInstallPath = "C:\python39_32bit"
PythonInstallerHash = "4a2812db8ab9f2e522c96c7728cfcccb"
}
Install-Python @Python39x86Config
$Python39x64Config = @{
PythonVersion = "3.9.0"
PythonInstaller = "python-3.9.0-amd64"
PythonInstallPath = "C:\python39"
PythonInstallerHash = "b61a33dc28f13b561452f3089c87eb63"
}
Install-Python @Python39x64Config

View File

@ -16,6 +16,7 @@ import platform
# namespace_packages option for the "google" package.
from setuptools import setup, Extension, find_packages
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean
from distutils.spawn import find_executable
@ -156,6 +157,20 @@ class build_py(_build_py):
return [(pkg, mod, fil) for (pkg, mod, fil) in modules
if not any(fnmatch.fnmatchcase(fil, pat=pat) for pat in exclude)]
class build_ext(_build_ext):
def get_ext_filename(self, ext_name):
# since python3.5, python extensions' shared libraries use a suffix that corresponds to the value
# of sysconfig.get_config_var('EXT_SUFFIX') and contains info about the architecture the library targets.
# E.g. on x64 linux the suffix is ".cpython-XYZ-x86_64-linux-gnu.so"
# When crosscompiling python wheels, we need to be able to override this suffix
# so that the resulting file name matches the target architecture and we end up with a well-formed
# wheel.
filename = _build_ext.get_ext_filename(self, ext_name)
orig_ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
new_ext_suffix = os.getenv("PROTOCOL_BUFFERS_OVERRIDE_EXT_SUFFIX")
if new_ext_suffix and filename.endswith(orig_ext_suffix):
filename = filename[:-len(orig_ext_suffix)] + new_ext_suffix
return filename
class test_conformance(_build_py):
target = 'test_python'
@ -291,6 +306,7 @@ if __name__ == '__main__':
cmdclass={
'clean': clean,
'build_py': build_py,
'build_ext': build_ext,
'test_conformance': test_conformance,
},
install_requires=install_requires,