10
10
We only supply binaries for windows and macOS, but we do it very different ways for those two OSes.
11
11
12
12
Windows recipe:
13
- 1. Download the "embeddable zip file" version of python from python.org
14
- 2. Remove .pth file to work around https://bugs.python.org/issue34841
15
- 3. Download and install pywin32 in the `site-packages` directory
16
- 4 . Re-zip and upload to storage.google.com
13
+ 1. Download precompiled version of python from NuGet package manager,
14
+ either the package "python" for AMD64, or "pythonarm64" for ARM64.
15
+ 2. Set up pip and install pywin32 and psutil via pip for emrun to work.
16
+ 3 . Re-zip and upload to storage.google.com
17
17
18
18
macOS recipe:
19
19
1. Clone cpython
32
32
from subprocess import check_call
33
33
from zip import unzip_cmd , zip_cmd
34
34
35
- version = '3.9.2 '
35
+ version = '3.13.0 '
36
36
major_minor_version = '.' .join (version .split ('.' )[:2 ]) # e.g. '3.9.2' -> '3.9'
37
- download_url = 'https://www.nuget.org/api/v2/package/python/%s' % version
38
37
# This is not part of official Python version, but a repackaging number appended by emsdk
39
38
# when a version of Python needs to be redownloaded.
40
39
revision = '4'
41
40
42
- pywin32_version = '227'
43
- pywin32_base = 'https://github.com/mhammond/pywin32/releases/download/b%s/' % pywin32_version
41
+ PSUTIL = 'psutil==6.0.0'
44
42
45
43
upload_base = 'gs://webassembly/emscripten-releases-builds/deps/'
46
44
47
45
46
+ # Detects whether current python interpreter architecture is ARM64 or AMD64
47
+ # If running AMD64 python on an ARM64 Windows, this still intentionally returns AMD64
48
+ def find_python_arch ():
49
+ import sysconfig
50
+ arch = sysconfig .get_platform ().lower ()
51
+ if 'amd64' in arch :
52
+ return 'amd64'
53
+ if 'arm64' in arch :
54
+ return 'arm64'
55
+ raise f'Unknown Python sysconfig platform "{ arch } " (neither AMD64 or ARM64)'
48
56
49
57
50
58
def make_python_patch ():
51
- pywin32_filename = 'pywin32-%s.win-amd64-py%s.exe' % (pywin32_version , major_minor_version )
52
- filename = 'python-%s-amd64.zip' % (version )
53
- out_filename = 'python-%s-%s-amd64+pywin32.zip' % (version , revision )
54
- if not os .path .exists (pywin32_filename ):
55
- url = pywin32_base + pywin32_filename
56
- print ('Downloading pywin32: ' + url )
57
- urllib .request .urlretrieve (url , pywin32_filename )
59
+ python_arch = find_python_arch ()
60
+ package_name = 'pythonarm64' if python_arch == 'arm64' else 'python'
61
+ download_url = f'https://www.nuget.org/api/v2/package/{ package_name } /{ version } '
62
+ filename = f'python-{ version } -{ python_arch } .zip'
63
+ out_filename = f'python-{ version } -{ revision } -{ python_arch } .zip'
58
64
59
65
if not os .path .exists (filename ):
60
66
print (f'Downloading python: { download_url } to { filename } ' )
@@ -64,19 +70,17 @@ def make_python_patch():
64
70
check_call (unzip_cmd () + [os .path .abspath (filename )], cwd = 'python-nuget' )
65
71
os .remove (filename )
66
72
67
- os .mkdir ('pywin32' )
68
- rtn = subprocess .call (unzip_cmd () + [os .path .abspath (pywin32_filename )], cwd = 'pywin32' )
69
- assert rtn in [0 , 1 ]
73
+ src_dir = os .path .join ('python-nuget' , 'tools' )
74
+ python_exe = os .path .join (src_dir , 'python.exe' )
75
+ check_call ([python_exe , '-m' , 'ensurepip' , '--upgrade' ])
76
+ check_call ([python_exe , '-m' , 'pip' , 'install' , 'pywin32==308' ])
77
+ check_call ([python_exe , '-m' , 'pip' , 'install' , PSUTIL ])
70
78
71
- os .mkdir (os .path .join ('python-nuget' , 'lib' ))
72
- shutil .move (os .path .join ('pywin32' , 'PLATLIB' ), os .path .join ('python-nuget' , 'toolss' , 'Lib' , 'site-packages' ))
73
-
74
- check_call (zip_cmd () + [os .path .join ('..' , '..' , out_filename ), '.' ], cwd = 'python-nuget/tools' )
79
+ check_call (zip_cmd () + [os .path .join ('..' , '..' , out_filename ), '.' ], cwd = src_dir )
75
80
print ('Created: %s' % out_filename )
76
81
77
82
# cleanup if everything went fine
78
83
shutil .rmtree ('python-nuget' )
79
- shutil .rmtree ('pywin32' )
80
84
81
85
if '--upload' in sys .argv :
82
86
upload_url = upload_base + out_filename
@@ -149,7 +153,7 @@ def build_python():
149
153
150
154
# Install psutil module. This is needed by emrun to track when browser
151
155
# process quits.
152
- check_call ([pybin , pip , 'install' , 'psutil' ])
156
+ check_call ([pybin , pip , 'install' , PSUTIL ])
153
157
154
158
dirname = 'python-%s-%s' % (version , revision )
155
159
if os .path .isdir (dirname ):
0 commit comments