@@ -413,15 +413,46 @@ def make_mpdec(context, working_dir):
413413 write_library_config (prefix , "mpdec" , mpdec_config , context .quiet )
414414
415415
416- def make_dependencies (context , working_dir ):
417- make_emscripten_libffi (context , working_dir )
418- make_mpdec (context , working_dir )
416+ def make_dependencies (context ):
417+ make_emscripten_libffi (context )
418+ make_mpdec (context )
419+
420+
421+ def calculate_node_path ():
422+ node_version = os .environ .get ("PYTHON_NODE_VERSION" , None )
423+ if node_version is None :
424+ node_version = load_config_toml ()["node-version" ]
425+
426+ subprocess .run (
427+ [
428+ "bash" ,
429+ "-c" ,
430+ f"source ~/.nvm/nvm.sh && nvm install { node_version } " ,
431+ ],
432+ check = True ,
433+ )
434+
435+ res = subprocess .run (
436+ [
437+ "bash" ,
438+ "-c" ,
439+ f"source ~/.nvm/nvm.sh && nvm which { node_version } " ,
440+ ],
441+ text = True ,
442+ capture_output = True ,
443+ check = True ,
444+ )
445+ return res .stdout .strip ()
419446
420447
421448@subdir ("host_dir" , clean_ok = True )
422449def configure_emscripten_python (context , working_dir ):
423450 """Configure the emscripten/host build."""
424451 validate_emsdk_version (context .emsdk_cache )
452+ host_runner = context .host_runner
453+ if host_runner is None :
454+ host_runner = calculate_node_path ()
455+
425456 paths = context .build_paths
426457 config_site = os .fsdecode (EMSCRIPTEN_DIR / "config.site-wasm32-emscripten" )
427458
@@ -440,19 +471,6 @@ def configure_emscripten_python(context, working_dir):
440471 )
441472 if pydebug :
442473 sysconfig_data += "-pydebug"
443-
444- host_runner = context .host_runner
445- if node_version := os .environ .get ("PYTHON_NODE_VERSION" , None ):
446- res = subprocess .run (
447- [
448- "bash" ,
449- "-c" ,
450- f"source ~/.nvm/nvm.sh && nvm which { node_version } " ,
451- ],
452- text = True ,
453- capture_output = True ,
454- )
455- host_runner = res .stdout .strip ()
456474 pkg_config_path_dir = (paths ["prefix_dir" ] / "lib/pkgconfig/" ).resolve ()
457475 env_additions = {
458476 "CONFIG_SITE" : config_site ,
@@ -618,8 +636,6 @@ def add_cross_build_dir_option(subcommand):
618636
619637
620638def main ():
621- default_host_runner = "node"
622-
623639 parser = argparse .ArgumentParser ()
624640 subcommands = parser .add_subparsers (dest = "subcommand" )
625641
@@ -755,10 +771,10 @@ def main():
755771 subcommand .add_argument (
756772 "--host-runner" ,
757773 action = "store" ,
758- default = default_host_runner ,
774+ default = None ,
759775 dest = "host_runner" ,
760- help = "Command template for running the emscripten host"
761- f"` { default_host_runner } ` )" ,
776+ help = "Command template for running the emscripten host "
777+ "(default: use nvm to install the node version specified in config.toml )" ,
762778 )
763779
764780 context = parser .parse_args ()
0 commit comments