mirror of https://github.com/pyodide/pyodide.git
Export PATH and ERRNO_CODES from Emscripten (#2582)
BrowserFS can mount custom filesystems into Emscripten. However it requires the PATH and ERRNO_CODES exports from Emscripten in addition to FS. This exports `PATH` and `ERRNO_CODES` from `Module` into the `pyodide` Javascript API so they can be used with BrowserFS.
This commit is contained in:
parent
829023c9af
commit
7d3c724665
|
@ -113,7 +113,8 @@ export MAIN_MODULE_LDFLAGS= $(LDFLAGS_BASE) \
|
|||
--exclude-file "*/tests/*" \
|
||||
--exclude-file "*/distutils/*" \
|
||||
--pre-js src/core/pre.js \
|
||||
--pre-js src/js/_pyodide.out.js
|
||||
--pre-js src/js/_pyodide.out.js \
|
||||
--post-js src/core/post.js
|
||||
|
||||
|
||||
export SIDE_MODULE_CXXFLAGS = $(CXXFLAGS_BASE)
|
||||
|
|
|
@ -86,6 +86,9 @@ substitutions:
|
|||
`clear_interval`, `add_event_listener` and `remove_event_listener` for the corresponding JavaScript functions.
|
||||
{pr}`2456`
|
||||
|
||||
- {{ Enhancement }} Pyodide now directly exposes the Emscripten `PATH` and `ERRNO_CODES` APIs.
|
||||
{pr}`2582`
|
||||
|
||||
### micropip
|
||||
|
||||
- {{ Fix }} micropip now correctly handles package names that include dashes
|
||||
|
|
|
@ -90,13 +90,6 @@ static struct PyModuleDef core_module_def = {
|
|||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
EM_ASM({
|
||||
// For some reason emscripten doesn't make UTF8ToString available on Module
|
||||
// by default...
|
||||
Module.UTF8ToString = UTF8ToString;
|
||||
Module.wasmTable = wasmTable;
|
||||
});
|
||||
|
||||
// This exits and prints a message to stderr on failure,
|
||||
// no status code to check.
|
||||
initialize_python();
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// Emscripten doesn't make UTF8ToString or wasmTable available on Module by default...
|
||||
Module.UTF8ToString = UTF8ToString;
|
||||
Module.wasmTable = wasmTable;
|
||||
// Emscripten has a bug where it accidentally exposes an empty object as Module.ERRNO_CODES
|
||||
Module.ERRNO_CODES = ERRNO_CODES;
|
|
@ -449,6 +449,8 @@ export function checkInterrupt() {
|
|||
export type PyodideInterface = {
|
||||
globals: typeof globals;
|
||||
FS: typeof FS;
|
||||
PATH: typeof PATH;
|
||||
ERRNO_CODES: typeof ERRNO_CODES;
|
||||
pyodide_py: typeof pyodide_py;
|
||||
version: typeof version;
|
||||
loadPackage: typeof loadPackage;
|
||||
|
@ -486,14 +488,32 @@ export type PyodideInterface = {
|
|||
*/
|
||||
export let FS: any;
|
||||
|
||||
/**
|
||||
* An alias to the `Emscripten Path API
|
||||
* <https://github.com/emscripten-core/emscripten/blob/main/src/library_path.js>`_.
|
||||
*
|
||||
* This provides a variety of operations for working with file system paths, such as
|
||||
* ``dirname``, ``normalize``, and ``splitPath``.
|
||||
*/
|
||||
export let PATH: any;
|
||||
|
||||
/**
|
||||
* An alias to the Emscripten ERRNO_CODES map of standard error codes.
|
||||
*/
|
||||
export let ERRNO_CODES: any;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
API.makePublicAPI = function (): PyodideInterface {
|
||||
FS = Module.FS;
|
||||
PATH = Module.PATH;
|
||||
ERRNO_CODES = Module.ERRNO_CODES;
|
||||
let namespace = {
|
||||
globals,
|
||||
FS,
|
||||
PATH,
|
||||
ERRNO_CODES,
|
||||
pyodide_py,
|
||||
version,
|
||||
loadPackage,
|
||||
|
|
|
@ -25,3 +25,24 @@ describe("FS", () => {
|
|||
chai.assert.isTrue(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PATH", () => {
|
||||
it("exists", async () => {
|
||||
chai.assert.exists(pyodide.PATH);
|
||||
});
|
||||
it("has expected keys", async () => {
|
||||
chai.assert.exists(pyodide.PATH.dirname);
|
||||
chai.assert.exists(pyodide.PATH.normalize);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ERRNO_CODES", () => {
|
||||
it("exists", async () => {
|
||||
chai.assert.exists(pyodide.ERRNO_CODES);
|
||||
});
|
||||
it("has expected keys", async () => {
|
||||
chai.assert.exists(pyodide.ERRNO_CODES.ENOENT);
|
||||
chai.assert.exists(pyodide.ERRNO_CODES.EPERM);
|
||||
chai.assert.exists(pyodide.ERRNO_CODES.EEXIST);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue