3333PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix"
3434
3535LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
36- LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n " .encode ("utf-8" )
36+ LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n " .encode (
37+ "utf-8"
38+ )
3739
3840
3941def updated_env (updates = {}):
@@ -45,7 +47,9 @@ def updated_env(updates={}):
4547 # https://reproducible-builds.org/docs/source-date-epoch/
4648 git_epoch_cmd = ["git" , "log" , "-1" , "--pretty=%ct" ]
4749 try :
48- epoch = subprocess .check_output (git_epoch_cmd , encoding = "utf-8" ).strip ()
50+ epoch = subprocess .check_output (
51+ git_epoch_cmd , encoding = "utf-8"
52+ ).strip ()
4953 env_defaults ["SOURCE_DATE_EPOCH" ] = epoch
5054 except subprocess .CalledProcessError :
5155 pass # Might be building from a tarball.
@@ -79,7 +83,11 @@ def wrapper(context):
7983 terminal_width = 80
8084 print ("⎯" * terminal_width )
8185 print ("📁" , working_dir )
82- if clean_ok and getattr (context , "clean" , False ) and working_dir .exists ():
86+ if (
87+ clean_ok
88+ and getattr (context , "clean" , False )
89+ and working_dir .exists ()
90+ ):
8391 print ("🚮 Deleting directory (--clean)..." )
8492 shutil .rmtree (working_dir )
8593
@@ -128,7 +136,9 @@ def build_python_path():
128136 if not binary .is_file ():
129137 binary = binary .with_suffix (".exe" )
130138 if not binary .is_file ():
131- raise FileNotFoundError ("Unable to find `python(.exe)` in " f"{ NATIVE_BUILD_DIR } " )
139+ raise FileNotFoundError (
140+ f"Unable to find `python(.exe)` in { NATIVE_BUILD_DIR } "
141+ )
132142
133143 return binary
134144
@@ -158,7 +168,8 @@ def make_build_python(context, working_dir):
158168 cmd = [
159169 binary ,
160170 "-c" ,
161- "import sys; " "print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
171+ "import sys; "
172+ "print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
162173 ]
163174 version = subprocess .check_output (cmd , encoding = "utf-8" ).strip ()
164175
@@ -173,7 +184,9 @@ def check_shasum(file: str, expected_shasum: str):
173184
174185
175186def download_and_unpack (working_dir : Path , url : str , expected_shasum : str ):
176- with tempfile .NamedTemporaryFile (suffix = ".tar.gz" , delete_on_close = False ) as tmp_file :
187+ with tempfile .NamedTemporaryFile (
188+ suffix = ".tar.gz" , delete_on_close = False
189+ ) as tmp_file :
177190 with urlopen (url ) as response :
178191 shutil .copyfileobj (response , tmp_file )
179192 tmp_file .close ()
@@ -186,7 +199,11 @@ def make_emscripten_libffi(context, working_dir):
186199 ver = "3.4.6"
187200 libffi_dir = working_dir / f"libffi-{ ver } "
188201 shutil .rmtree (libffi_dir , ignore_errors = True )
189- download_and_unpack (working_dir , f"https://github.com/libffi/libffi/releases/download/v{ ver } /libffi-{ ver } .tar.gz" , "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e" )
202+ download_and_unpack (
203+ working_dir ,
204+ f"https://github.com/libffi/libffi/releases/download/v{ ver } /libffi-{ ver } .tar.gz" ,
205+ "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e" ,
206+ )
190207 call (
191208 [EMSCRIPTEN_DIR / "make_libffi.sh" ],
192209 env = updated_env ({"PREFIX" : PREFIX_DIR }),
@@ -200,7 +217,11 @@ def make_mpdec(context, working_dir):
200217 ver = "4.0.1"
201218 mpdec_dir = working_dir / f"mpdecimal-{ ver } "
202219 shutil .rmtree (mpdec_dir , ignore_errors = True )
203- download_and_unpack (working_dir , f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ ver } .tar.gz" , "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8" )
220+ download_and_unpack (
221+ working_dir ,
222+ f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ ver } .tar.gz" ,
223+ "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8" ,
224+ )
204225 call (
205226 [
206227 "emconfigure" ,
@@ -214,10 +235,7 @@ def make_mpdec(context, working_dir):
214235 quiet = context .quiet ,
215236 )
216237 call (
217- [
218- "make" ,
219- "install"
220- ],
238+ ["make" , "install" ],
221239 cwd = mpdec_dir ,
222240 quiet = context .quiet ,
223241 )
@@ -226,17 +244,15 @@ def make_mpdec(context, working_dir):
226244@subdir (HOST_DIR , clean_ok = True )
227245def configure_emscripten_python (context , working_dir ):
228246 """Configure the emscripten/host build."""
229- config_site = os .fsdecode (
230- EMSCRIPTEN_DIR / "config.site-wasm32-emscripten"
231- )
247+ config_site = os .fsdecode (EMSCRIPTEN_DIR / "config.site-wasm32-emscripten" )
232248
233249 emscripten_build_dir = working_dir .relative_to (CHECKOUT )
234250
235251 python_build_dir = NATIVE_BUILD_DIR / "build"
236252 lib_dirs = list (python_build_dir .glob ("lib.*" ))
237- assert (
238- len ( lib_dirs ) == 1
239- ), f"Expected a single lib.* directory in { python_build_dir } "
253+ assert len ( lib_dirs ) == 1 , (
254+ f"Expected a single lib.* directory in { python_build_dir } "
255+ )
240256 lib_dir = os .fsdecode (lib_dirs [0 ])
241257 pydebug = lib_dir .endswith ("-pydebug" )
242258 python_version = lib_dir .removesuffix ("-pydebug" ).rpartition ("-" )[- 1 ]
@@ -290,7 +306,9 @@ def configure_emscripten_python(context, working_dir):
290306 quiet = context .quiet ,
291307 )
292308
293- shutil .copy (EMSCRIPTEN_DIR / "node_entry.mjs" , working_dir / "node_entry.mjs" )
309+ shutil .copy (
310+ EMSCRIPTEN_DIR / "node_entry.mjs" , working_dir / "node_entry.mjs"
311+ )
294312
295313 node_entry = working_dir / "node_entry.mjs"
296314 exec_script = working_dir / "python.sh"
@@ -383,13 +401,15 @@ def main():
383401 subcommands = parser .add_subparsers (dest = "subcommand" )
384402 build = subcommands .add_parser ("build" , help = "Build everything" )
385403 configure_build = subcommands .add_parser (
386- "configure-build-python" , help = "Run `configure` for the " " build Python"
404+ "configure-build-python" , help = "Run `configure` for the build Python"
387405 )
388406 make_mpdec_cmd = subcommands .add_parser (
389- "make-mpdec" , help = "Clone mpdec repo, configure and build it for emscripten"
407+ "make-mpdec" ,
408+ help = "Clone mpdec repo, configure and build it for emscripten" ,
390409 )
391410 make_libffi_cmd = subcommands .add_parser (
392- "make-libffi" , help = "Clone libffi repo, configure and build it for emscripten"
411+ "make-libffi" ,
412+ help = "Clone libffi repo, configure and build it for emscripten" ,
393413 )
394414 make_build = subcommands .add_parser (
395415 "make-build-python" , help = "Run `make` for the build Python"
@@ -457,7 +477,11 @@ def main():
457477
458478 if not context .subcommand :
459479 # No command provided, display help and exit
460- print ("Expected one of" , ", " .join (sorted (dispatch .keys ())), file = sys .stderr )
480+ print (
481+ "Expected one of" ,
482+ ", " .join (sorted (dispatch .keys ())),
483+ file = sys .stderr ,
484+ )
461485 parser .print_help (sys .stderr )
462486 sys .exit (1 )
463487 dispatch [context .subcommand ](context )
0 commit comments