@@ -413,10 +413,41 @@ def make_mpdec(context, working_dir):
413413 write_library_config (prefix , "mpdec" , mpdec_config , context .quiet )
414414
415415
416+ def calculate_node_path ():
417+ node_version = os .environ .get ("PYTHON_NODE_VERSION" , None )
418+ if node_version is None :
419+ node_version = load_config_toml ()["node-version" ]
420+
421+ subprocess .run (
422+ [
423+ "bash" ,
424+ "-c" ,
425+ f"source ~/.nvm/nvm.sh && nvm install { node_version } " ,
426+ ],
427+ check = True ,
428+ )
429+
430+ res = subprocess .run (
431+ [
432+ "bash" ,
433+ "-c" ,
434+ f"source ~/.nvm/nvm.sh && nvm which { node_version } " ,
435+ ],
436+ text = True ,
437+ capture_output = True ,
438+ check = True ,
439+ )
440+ return res .stdout .strip ()
441+
442+
416443@subdir ("host_dir" , clean_ok = True )
417444def configure_emscripten_python (context , working_dir ):
418445 """Configure the emscripten/host build."""
419446 validate_emsdk_version (context .emsdk_cache )
447+ host_runner = context .host_runner
448+ if host_runner is None :
449+ host_runner = calculate_node_path ()
450+
420451 paths = context .build_paths
421452 config_site = os .fsdecode (EMSCRIPTEN_DIR / "config.site-wasm32-emscripten" )
422453
@@ -435,19 +466,6 @@ def configure_emscripten_python(context, working_dir):
435466 )
436467 if pydebug :
437468 sysconfig_data += "-pydebug"
438-
439- host_runner = context .host_runner
440- if node_version := os .environ .get ("PYTHON_NODE_VERSION" , None ):
441- res = subprocess .run (
442- [
443- "bash" ,
444- "-c" ,
445- f"source ~/.nvm/nvm.sh && nvm which { node_version } " ,
446- ],
447- text = True ,
448- capture_output = True ,
449- )
450- host_runner = res .stdout .strip ()
451469 pkg_config_path_dir = (paths ["prefix_dir" ] / "lib/pkgconfig/" ).resolve ()
452470 env_additions = {
453471 "CONFIG_SITE" : config_site ,
@@ -613,8 +631,6 @@ def add_cross_build_dir_option(subcommand):
613631
614632
615633def main ():
616- default_host_runner = "node"
617-
618634 parser = argparse .ArgumentParser ()
619635 subcommands = parser .add_subparsers (dest = "subcommand" )
620636
@@ -744,10 +760,10 @@ def main():
744760 subcommand .add_argument (
745761 "--host-runner" ,
746762 action = "store" ,
747- default = default_host_runner ,
763+ default = None ,
748764 dest = "host_runner" ,
749- help = "Command template for running the emscripten host"
750- f"` { default_host_runner } ` )" ,
765+ help = "Command template for running the emscripten host "
766+ "(default: use nvm to install the node version specified in config.toml )" ,
751767 )
752768
753769 context = parser .parse_args ()
0 commit comments