forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-126898 Switch to exporting an es6 module and using a node_en…
…try script We delete `node_pre.js` and `--pre-js`. Instead that logic moves to `node_entry.mjs`. In order to access `FS` from outside of `python.mjs`, we need to add `-sEXPORTED_RUNTIME_METHODS=FS`. Instead of invoking `python.js` directly, we will invoke `node_entry.mjs`. Special care has to be taken to ensure that we get `sys.executable` correct. It should point to the original path that was invoked, without symlinks resolved. I updated the generated `python.sh` to calculate it's own absolute path with `realpath -s $0` and pass that in. Then `node_entry.mjs` sets `thisProgram` to the path passed in. I manually validated this by creating a symlink to `python.sh` and invoking it. `sys.executable` and `sys._base_exectable` indeed point to the symlink, not to the build directory `python.sh` and not to `node_entry.mjs`.
- Loading branch information
Showing
5 changed files
with
59 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import EmscriptenModule from "./python.mjs"; | ||
import { dirname } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
if (process?.versions?.node) { | ||
const nodeVersion = Number(process.versions.node.split(".", 1)[0]); | ||
if (nodeVersion < 18) { | ||
process.stderr.write( | ||
`Node version must be >= 18, got version ${process.version}\n`, | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const settings = { | ||
preRun(Module) { | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
Module.FS.mkdirTree("/lib/"); | ||
Module.FS.mount(Module.FS.filesystems.NODEFS, { root: __dirname + "/lib/" }, "/lib/"); | ||
}, | ||
// The first three arguments are: "node", path to this file, path to | ||
// python.sh. After that come the arguments the user passed to python.sh. | ||
arguments: process.argv.slice(3), | ||
// Ensure that sys.executable, sys._base_executable, etc point to python.sh | ||
// not to this file. To properly handle symlinks, python.sh needs to compute | ||
// its own path. | ||
thisProgram: process.argv[2], | ||
}; | ||
|
||
await EmscriptenModule(settings); |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters