From 2887a2409004c2ffb889fe50da91a33352267196 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Fri, 7 Apr 2023 04:28:36 -0700 Subject: [PATCH] Add an environment variable to mount extra directories into pyodide python command (#3742) Helpful for build systems which place stuff in temp folders. I'm working on cibuildwheel support which needs this. --- src/templates/python | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/templates/python b/src/templates/python index 128f6f163..752002dba 100755 --- a/src/templates/python +++ b/src/templates/python @@ -57,7 +57,7 @@ const fs = require("fs"); * names it is possible this could break. The most surprising one here is tmp, I * am not sure why but if we link tmp then the process silently fails. */ -function nativeDirsToLink() { +function rootDirsToMount() { const skipDirs = ["dev", "lib", "proc", "tmp"]; return fs .readdirSync("/") @@ -65,14 +65,18 @@ function nativeDirsToLink() { .map((dir) => "/" + dir); } +function dirsToMount() { + extra_mounts = process.env["_PYODIDE_EXTRA_MOUNTS"] || ""; + return rootDirsToMount().concat(extra_mounts.split(":").filter(s => s)) +} + async function main() { let args = process.argv.slice(2); - const _node_mounts = nativeDirsToLink(); try { py = await loadPyodide({ args, fullStdLib: false, - _node_mounts, + _node_mounts: dirsToMount(), homedir: process.cwd(), // Strip out messages written to stderr while loading // After Pyodide is loaded we will replace stdstreams with setupStreams.