Switch to nuget python package for windows (#1001)
This allows us to use pip and install other packages. Fixes #16466
This commit is contained in:
@@ -420,6 +420,15 @@
|
|||||||
"activated_env": "EMSDK_PYTHON=%installation_dir%/bin/python3;SSL_CERT_FILE=%installation_dir%/lib/python3.7/site-packages/certifi/cacert.pem",
|
"activated_env": "EMSDK_PYTHON=%installation_dir%/bin/python3;SSL_CERT_FILE=%installation_dir%/lib/python3.7/site-packages/certifi/cacert.pem",
|
||||||
"is_old": true
|
"is_old": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "python",
|
||||||
|
"version": "3.9.2-nuget",
|
||||||
|
"bitness": 64,
|
||||||
|
"arch": "x86_64",
|
||||||
|
"windows_url": "python-3.9.2-4-amd64+pywin32.zip",
|
||||||
|
"activated_cfg": "PYTHON='%installation_dir%/python.exe'",
|
||||||
|
"activated_env": "EMSDK_PYTHON=%installation_dir%/python.exe"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "python",
|
"id": "python",
|
||||||
"version": "3.9.2",
|
"version": "3.9.2",
|
||||||
@@ -644,7 +653,7 @@
|
|||||||
{
|
{
|
||||||
"version": "upstream-main",
|
"version": "upstream-main",
|
||||||
"bitness": 64,
|
"bitness": 64,
|
||||||
"uses": ["python-3.9.2-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
|
"uses": ["python-3.9.2-nuget-64bit", "llvm-git-main-64bit", "node-14.18.2-64bit", "emscripten-main-64bit", "binaryen-main-64bit"],
|
||||||
"os": "win"
|
"os": "win"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -727,7 +736,7 @@
|
|||||||
{
|
{
|
||||||
"version": "releases-upstream-%releases-tag%",
|
"version": "releases-upstream-%releases-tag%",
|
||||||
"bitness": 64,
|
"bitness": 64,
|
||||||
"uses": ["node-14.18.2-64bit", "python-3.9.2-64bit", "java-8.152-64bit", "releases-upstream-%releases-tag%-64bit"],
|
"uses": ["node-14.18.2-64bit", "python-3.9.2-nuget-64bit", "java-8.152-64bit", "releases-upstream-%releases-tag%-64bit"],
|
||||||
"os": "win",
|
"os": "win",
|
||||||
"custom_install_script": "emscripten_npm_install"
|
"custom_install_script": "emscripten_npm_install"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ from subprocess import check_call
|
|||||||
|
|
||||||
version = '3.9.2'
|
version = '3.9.2'
|
||||||
major_minor_version = '.'.join(version.split('.')[:2]) # e.g. '3.9.2' -> '3.9'
|
major_minor_version = '.'.join(version.split('.')[:2]) # e.g. '3.9.2' -> '3.9'
|
||||||
base = 'https://www.python.org/ftp/python/%s/' % version
|
download_url = 'https://www.nuget.org/api/v2/package/python/%s' % version
|
||||||
revision = '3'
|
revision = '4'
|
||||||
|
|
||||||
pywin32_version = '227'
|
pywin32_version = '227'
|
||||||
pywin32_base = 'https://github.com/mhammond/pywin32/releases/download/b%s/' % pywin32_version
|
pywin32_base = 'https://github.com/mhammond/pywin32/releases/download/b%s/' % pywin32_version
|
||||||
@@ -44,7 +44,7 @@ upload_base = 'gs://webassembly/emscripten-releases-builds/deps/'
|
|||||||
|
|
||||||
def unzip_cmd():
|
def unzip_cmd():
|
||||||
# Use 7-Zip if available (https://www.7-zip.org/)
|
# Use 7-Zip if available (https://www.7-zip.org/)
|
||||||
sevenzip = os.path.join(os.getenv('ProgramFiles'), '7-Zip', '7z.exe')
|
sevenzip = os.path.join(os.getenv('ProgramFiles', ''), '7-Zip', '7z.exe')
|
||||||
if os.path.isfile(sevenzip):
|
if os.path.isfile(sevenzip):
|
||||||
return [sevenzip, 'x']
|
return [sevenzip, 'x']
|
||||||
# Fall back to 'unzip' tool
|
# Fall back to 'unzip' tool
|
||||||
@@ -53,52 +53,49 @@ def unzip_cmd():
|
|||||||
|
|
||||||
def zip_cmd():
|
def zip_cmd():
|
||||||
# Use 7-Zip if available (https://www.7-zip.org/)
|
# Use 7-Zip if available (https://www.7-zip.org/)
|
||||||
sevenzip = os.path.join(os.getenv('ProgramFiles'), '7-Zip', '7z.exe')
|
sevenzip = os.path.join(os.getenv('ProgramFiles', ''), '7-Zip', '7z.exe')
|
||||||
if os.path.isfile(sevenzip):
|
if os.path.isfile(sevenzip):
|
||||||
return [sevenzip, 'a', '-mx9']
|
return [sevenzip, 'a', '-mx9']
|
||||||
# Fall back to 'zip' tool
|
# Fall back to 'zip' tool
|
||||||
return ['zip', '-rq']
|
return ['zip', '-rq']
|
||||||
|
|
||||||
|
|
||||||
def make_python_patch(arch):
|
def make_python_patch():
|
||||||
if arch == 'amd64':
|
pywin32_filename = 'pywin32-%s.win-amd64-py%s.exe' % (pywin32_version, major_minor_version)
|
||||||
pywin32_filename = 'pywin32-%s.win-%s-py%s.exe' % (pywin32_version, arch, major_minor_version)
|
filename = 'python-%s-amd64.zip' % (version)
|
||||||
else:
|
out_filename = 'python-%s-%s-amd64+pywin32.zip' % (version, revision)
|
||||||
pywin32_filename = 'pywin32-%s.%s-py%s.exe' % (pywin32_version, arch, major_minor_version)
|
|
||||||
filename = 'python-%s-embed-%s.zip' % (version, arch)
|
|
||||||
out_filename = 'python-%s-%s-embed-%s+pywin32.zip' % (version, revision, arch)
|
|
||||||
if not os.path.exists(pywin32_filename):
|
if not os.path.exists(pywin32_filename):
|
||||||
download_url = pywin32_base + pywin32_filename
|
url = pywin32_base + pywin32_filename
|
||||||
print('Downloading pywin32: ' + download_url)
|
print('Downloading pywin32: ' + url)
|
||||||
urllib.request.urlretrieve(download_url, pywin32_filename)
|
urllib.request.urlretrieve(url, pywin32_filename)
|
||||||
|
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
download_url = base + filename
|
|
||||||
print('Downloading python: ' + download_url)
|
print('Downloading python: ' + download_url)
|
||||||
urllib.request.urlretrieve(download_url, filename)
|
urllib.request.urlretrieve(download_url, filename)
|
||||||
|
|
||||||
os.mkdir('python-embed')
|
os.mkdir('python-nuget')
|
||||||
check_call(unzip_cmd() + [os.path.abspath(filename)], cwd='python-embed')
|
check_call(unzip_cmd() + [os.path.abspath(filename)], cwd='python-nuget')
|
||||||
os.remove(os.path.join('python-embed', 'python%s._pth' % major_minor_version.replace('.', '')))
|
|
||||||
|
|
||||||
os.mkdir('pywin32')
|
os.mkdir('pywin32')
|
||||||
rtn = subprocess.call(unzip_cmd() + [os.path.abspath(pywin32_filename)], cwd='pywin32')
|
rtn = subprocess.call(unzip_cmd() + [os.path.abspath(pywin32_filename)], cwd='pywin32')
|
||||||
assert rtn in [0, 1]
|
assert rtn in [0, 1]
|
||||||
|
|
||||||
os.mkdir(os.path.join('python-embed', 'lib'))
|
os.mkdir(os.path.join('python-nuget', 'lib'))
|
||||||
shutil.move(os.path.join('pywin32', 'PLATLIB'), os.path.join('python-embed', 'lib', 'site-packages'))
|
shutil.move(os.path.join('pywin32', 'PLATLIB'), os.path.join('python-nuget', 'toolss', 'Lib', 'site-packages'))
|
||||||
|
|
||||||
check_call(zip_cmd() + [os.path.join('..', out_filename), '.'], cwd='python-embed')
|
check_call(zip_cmd() + [os.path.join('..', '..', out_filename), '.'], cwd='python-nuget/tools')
|
||||||
|
|
||||||
# cleanup if everything went fine
|
# cleanup if everything went fine
|
||||||
shutil.rmtree('python-embed')
|
shutil.rmtree('python-nuget')
|
||||||
shutil.rmtree('pywin32')
|
shutil.rmtree('pywin32')
|
||||||
|
|
||||||
upload_url = upload_base + out_filename
|
print('Created: %s' % out_filename)
|
||||||
print('Uploading: ' + upload_url)
|
if '--upload' in sys.argv:
|
||||||
cmd = ['gsutil', 'cp', '-n', out_filename, upload_url]
|
upload_url = upload_base + out_filename
|
||||||
print(' '.join(cmd))
|
print('Uploading: ' + upload_url)
|
||||||
check_call(cmd)
|
cmd = ['gsutil', 'cp', '-n', out_filename, upload_url]
|
||||||
|
print(' '.join(cmd))
|
||||||
|
check_call(cmd)
|
||||||
|
|
||||||
|
|
||||||
def build_python():
|
def build_python():
|
||||||
@@ -169,14 +166,16 @@ def build_python():
|
|||||||
for lib in glob.glob(os.path.join(dirname, 'lib', 'lib*.a')):
|
for lib in glob.glob(os.path.join(dirname, 'lib', 'lib*.a')):
|
||||||
os.remove(lib)
|
os.remove(lib)
|
||||||
check_call(['tar', 'zcvf', tarball, dirname])
|
check_call(['tar', 'zcvf', tarball, dirname])
|
||||||
print('Uploading: ' + upload_base + tarball)
|
|
||||||
check_call(['gsutil', 'cp', '-n', tarball, upload_base + tarball])
|
print('Created: %s' % tarball)
|
||||||
|
if '--upload' in sys.argv:
|
||||||
|
print('Uploading: ' + upload_base + tarball)
|
||||||
|
check_call(['gsutil', 'cp', '-n', tarball, upload_base + tarball])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win') or '--win32' in sys.argv:
|
||||||
for arch in ('amd64', 'win32'):
|
make_python_patch()
|
||||||
make_python_patch(arch)
|
|
||||||
else:
|
else:
|
||||||
build_python()
|
build_python()
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Reference in New Issue
Block a user