@@ -413,6 +413,35 @@ 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+ res = subprocess .run (
422+ [
423+ "bash" ,
424+ "-c" ,
425+ f"source ~/.nvm/nvm.sh && nvm install { node_version } " ,
426+ ],
427+ text = True ,
428+ capture_output = True ,
429+ check = True ,
430+ )
431+
432+ res = subprocess .run (
433+ [
434+ "bash" ,
435+ "-c" ,
436+ f"source ~/.nvm/nvm.sh && nvm which { node_version } " ,
437+ ],
438+ text = True ,
439+ capture_output = True ,
440+ check = True ,
441+ )
442+ return res .stdout .strip ()
443+
444+
416445@subdir ("host_dir" , clean_ok = True )
417446def configure_emscripten_python (context , working_dir ):
418447 """Configure the emscripten/host build."""
@@ -437,17 +466,8 @@ def configure_emscripten_python(context, working_dir):
437466 sysconfig_data += "-pydebug"
438467
439468 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 ()
469+ if host_runner is None :
470+ host_runner = calculate_node_path ()
451471 pkg_config_path_dir = (paths ["prefix_dir" ] / "lib/pkgconfig/" ).resolve ()
452472 env_additions = {
453473 "CONFIG_SITE" : config_site ,
@@ -744,10 +764,10 @@ def main():
744764 subcommand .add_argument (
745765 "--host-runner" ,
746766 action = "store" ,
747- default = default_host_runner ,
767+ default = None ,
748768 dest = "host_runner" ,
749- help = "Command template for running the emscripten host"
750- f"` { default_host_runner } ` )" ,
769+ help = "Command template for running the emscripten host "
770+ "(default: use nvm to install the node version specified in config.toml )" ,
751771 )
752772
753773 context = parser .parse_args ()
0 commit comments