more explicit python_exe;
authorwenzelm
Fri, 12 Sep 2025 17:31:38 +0200
changeset 83139 c87375585b9f
parent 83138 c66d77fb729e
child 83140 9c7446adfbc6
more explicit python_exe;
src/Pure/System/isabelle_platform.scala
src/Tools/VSCode/src/component_vscodium.scala
--- a/src/Pure/System/isabelle_platform.scala	Fri Sep 12 17:07:21 2025 +0200
+++ b/src/Pure/System/isabelle_platform.scala	Fri Sep 12 17:31:38 2025 +0200
@@ -7,6 +7,9 @@
 package isabelle
 
 
+import java.util.{Map => JMap}
+
+
 object Isabelle_Platform {
   val settings: List[String] =
     List(
@@ -68,11 +71,15 @@
     def standard_path(path: Path): String =
       mingw.standard_path(File.platform_path(path))
 
-    def bash(script: String, cwd: Path = Path.current): Process_Result =
+    def bash(script: String,
+      cwd: Path = Path.current,
+      env: JMap[String, String] = Isabelle_System.Settings.env(),
+    ): Process_Result = {
       progress.bash(
         if (is_macos_arm) "arch -arch arm64 bash -c " + Bash.string(script)
         else mingw.bash_script(script),
-        cwd = cwd, echo = progress.verbose)
+        cwd = cwd, env = env, echo = progress.verbose)
+    }
   }
 }
 
--- a/src/Tools/VSCode/src/component_vscodium.scala	Fri Sep 12 17:07:21 2025 +0200
+++ b/src/Tools/VSCode/src/component_vscodium.scala	Fri Sep 12 17:31:38 2025 +0200
@@ -13,7 +13,7 @@
 import isabelle._
 
 import java.security.MessageDigest
-import java.util.Base64
+import java.util.{Map => JMap, Base64}
 
 
 object Component_VSCodium {
@@ -123,7 +123,8 @@
       platform_context: Isabelle_Platform.Context,
       node_root: Option[Path] = None,
       node_version: String = "",
-      vscodium_version: String = default_vscodium_version
+      vscodium_version: String = default_vscodium_version,
+      python_exe: Option[Path] = None
     ): Build_Context = {
       val platform = platform_context.isabelle_platform
       val env1 =
@@ -150,7 +151,8 @@
         else if (platform.is_linux) List("SKIP_LINUX_PACKAGES=True")
         else Nil
       val node_version1 = proper_string(node_version).getOrElse(default_node_version)
-      new Build_Context(platform_context, node_root, node_version1, vscodium_version, env1 ::: env2)
+      new Build_Context(
+        platform_context, node_root, node_version1, vscodium_version, python_exe, env1 ::: env2)
     }
   }
 
@@ -159,6 +161,7 @@
     node_root: Option[Path],
     node_version: String,
     vscodium_version: String,
+    python_exe: Option[Path],
     env: List[String]
   ) {
     override def toString: String = platform_name
@@ -207,6 +210,13 @@
     def environment(dir: Path): String =
       Bash.exports((build_env ::: build_upstream_env(dir) ::: env):_*)
 
+    def settings: JMap[String, String] =
+      python_exe match {
+        case None => Isabelle_System.Settings.env()
+        case Some(exe) =>
+          Isabelle_System.Settings.env(List("NODE_GYP_FORCE_PYTHON" -> File.platform_path(exe)))
+      }
+
     def patch_sources(base_dir: Path): String = {
       val dir = base_dir + Path.explode("vscode")
       Isabelle_System.with_copy_dir(dir, dir.orig) {
@@ -325,7 +335,8 @@
             "./prepare_vscode.sh",
             // enforce binary diff of code.xpm
             "cp vscode/resources/linux/code.png vscode/resources/linux/rpm/code.xpm"),
-          cwd = build_dir).check
+          cwd = build_dir,
+          env = build_context.settings).check
         Isabelle_System.make_patch(build_dir, vscode_dir.orig.base, vscode_dir.base,
           diff_options = "--exclude=.git --exclude=node_modules")
       }
@@ -340,6 +351,7 @@
     node_root: Option[Path] = None,
     node_version: String = default_node_version,
     vscodium_version: String = default_vscodium_version,
+    python_exe: Option[Path] = None,
     platform_context: Isabelle_Platform.Context = Isabelle_Platform.Context(),
   ): Unit = {
     val platform = platform_context.isabelle_platform
@@ -349,7 +361,8 @@
       Build_Context.make(platform_context,
         node_root = node_root,
         node_version = node_version,
-        vscodium_version = vscodium_version)
+        vscodium_version = vscodium_version,
+        python_exe = python_exe)
 
     platform_context.mingw.check()
 
@@ -403,7 +416,9 @@
       val environment = build_context.environment(build_dir)
       progress.echo(environment, verbose = true)
       platform_context.bash(
-        node_dir.path_setup + "\n" + environment + "./build.sh", cwd = build_dir).check
+        node_dir.path_setup + "\n" + environment + "./build.sh",
+        cwd = build_dir,
+        env = build_context.settings).check
 
       Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir.path)
 
@@ -465,8 +480,7 @@
 
 * x86_64-windows with Cygwin-Terminal, using prerequisites in typical locations:
 
-    export NODE_GYP_FORCE_PYTHON='C:\Python313\python.exe'
-    isabelle component_vscodium -M "/cygdrive/c/msys64" -n "/cygdrive/c/Program Files/nodejs"
+    isabelle component_vscodium -M "/cygdrive/c/msys64" -n "/cygdrive/c/Program Files/nodejs" -P /cygdrive/c/Python313/python.exe
 
 
         Makarius
@@ -486,6 +500,7 @@
         var node_version = default_node_version
         var vscodium_version = default_vscodium_version
         var node_root: Option[Path] = None
+        var python_exe: Option[Path] = None
         var verbose = false
 
         val getopts = Getopts("""
@@ -497,6 +512,7 @@
     -M DIR       msys/mingw root specification for Windows
     -N VERSION   download Node.js version (overrides option -n)
                  (default: """" + default_node_version + """")
+    -P FILE      Python executable (default: educated guess by node-gyp)
     -V VERSION   VSCodium version (default: """" + default_vscodium_version + """")
     -n DIR       use existing Node.js directory (overrides option -N)
     -v           verbose
@@ -535,6 +551,7 @@
           "I" -> (arg => intel = true),
           "M:" -> (arg => mingw = MinGW(Path.explode(arg))),
           "N:" -> { arg => node_version = arg; node_root = None },
+          "P:" -> (arg => python_exe = Some(Path.explode(arg))),
           "V:" -> (arg => vscodium_version = arg),
           "n:" -> { arg => node_root = Some(Path.explode(arg)); node_version = "" },
           "v" -> (_ => verbose = true))
@@ -546,7 +563,7 @@
         val platform_context = Isabelle_Platform.Context(mingw = mingw, apple = !intel, progress = progress)
 
         component_vscodium(target_dir = target_dir, node_root = node_root,
-          node_version = node_version, vscodium_version = vscodium_version,
+          node_version = node_version, python_exe = python_exe, vscodium_version = vscodium_version,
           platform_context = platform_context)
       })