1818
1919
2020CHECKOUT = pathlib .Path (__file__ ).parent .parent .parent .parent
21- assert (CHECKOUT / "configure" ).is_file (), "Please update the location of the file"
21+ assert (CHECKOUT / "configure" ).is_file (), (
22+ "Please update the location of the file"
23+ )
2224
2325CROSS_BUILD_DIR = CHECKOUT / "cross-build"
2426# Build platform can also be found via `config.guess`.
@@ -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.
@@ -84,7 +88,11 @@ def wrapper(context):
8488 terminal_width = int (tput_output .strip ())
8589 print ("⎯" * terminal_width )
8690 print ("📁" , working_dir )
87- if clean_ok and getattr (context , "clean" , False ) and working_dir .exists ():
91+ if (
92+ clean_ok
93+ and getattr (context , "clean" , False )
94+ and working_dir .exists ()
95+ ):
8896 print ("🚮 Deleting directory (--clean)..." )
8997 shutil .rmtree (working_dir )
9098
@@ -134,7 +142,9 @@ def build_python_path():
134142 if not binary .is_file ():
135143 binary = binary .with_suffix (".exe" )
136144 if not binary .is_file ():
137- raise FileNotFoundError ("Unable to find `python(.exe)` in " f"{ BUILD_DIR } " )
145+ raise FileNotFoundError (
146+ f"Unable to find `python(.exe)` in { BUILD_DIR } "
147+ )
138148
139149 return binary
140150
@@ -178,7 +188,8 @@ def make_build_python(context, working_dir):
178188 cmd = [
179189 binary ,
180190 "-c" ,
181- "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
191+ "import sys; "
192+ "print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
182193 ]
183194 version = subprocess .check_output (cmd , encoding = "utf-8" ).strip ()
184195
@@ -239,9 +250,10 @@ def wasi_sdk_env(context):
239250 env ["WASI_SDK_PATH" ] = os .fsdecode (wasi_sdk_path )
240251 env ["WASI_SYSROOT" ] = os .fsdecode (sysroot )
241252
242- env ["PATH" ] = os .pathsep .join (
243- [os .fsdecode (wasi_sdk_path / "bin" ), os .environ ["PATH" ]]
244- )
253+ env ["PATH" ] = os .pathsep .join ([
254+ os .fsdecode (wasi_sdk_path / "bin" ),
255+ os .environ ["PATH" ],
256+ ])
245257
246258 return env
247259
@@ -265,12 +277,14 @@ def configure_wasi_python(context, working_dir):
265277
266278 python_build_dir = BUILD_DIR / "build"
267279 lib_dirs = list (python_build_dir .glob ("lib.*" ))
268- assert (
269- len ( lib_dirs ) == 1
270- ), f"Expected a single lib.* directory in { python_build_dir } "
280+ assert len ( lib_dirs ) == 1 , (
281+ f"Expected a single lib.* directory in { python_build_dir } "
282+ )
271283 lib_dir = os .fsdecode (lib_dirs [0 ])
272284 python_version = lib_dir .rpartition ("-" )[- 1 ]
273- sysconfig_data_dir = f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
285+ sysconfig_data_dir = (
286+ f"{ wasi_build_dir } /build/lib.wasi-wasm32-{ python_version } "
287+ )
274288
275289 # Use PYTHONPATH to include sysconfig data which must be anchored to the
276290 # WASI guest's `/` directory.
@@ -326,7 +340,9 @@ def configure_wasi_python(context, working_dir):
326340def make_wasi_python (context , working_dir ):
327341 """Run `make` for the WASI/host build."""
328342 call (
329- ["make" , "--jobs" , str (cpu_count ()), "all" ], env = updated_env (), context = context
343+ ["make" , "--jobs" , str (cpu_count ()), "all" ],
344+ env = updated_env (),
345+ context = context ,
330346 )
331347
332348 exec_script = working_dir / "python.sh"
@@ -394,11 +410,19 @@ def main():
394410 "are inferred from the build "
395411 "Python)" ,
396412 )
397- make_host = subcommands .add_parser ("make-host" , help = "Run `make` for the host/WASI" )
413+ make_host = subcommands .add_parser (
414+ "make-host" , help = "Run `make` for the host/WASI"
415+ )
398416 subcommands .add_parser (
399417 "clean" , help = "Delete files and directories created by this script"
400418 )
401- for subcommand in build , configure_build , make_build , configure_host , make_host :
419+ for subcommand in (
420+ build ,
421+ configure_build ,
422+ make_build ,
423+ configure_host ,
424+ make_host ,
425+ ):
402426 subcommand .add_argument (
403427 "--quiet" ,
404428 action = "store_true" ,
@@ -410,7 +434,7 @@ def main():
410434 "--logdir" ,
411435 type = pathlib .Path ,
412436 default = default_logdir ,
413- help = "Directory to store log files; " f" defaults to { default_logdir } " ,
437+ help = f "Directory to store log files; defaults to { default_logdir } " ,
414438 )
415439 for subcommand in configure_build , configure_host :
416440 subcommand .add_argument (
0 commit comments