refac: migrated to pyodide from pyscript

This commit is contained in:
Timothy J. Baek
2024-05-16 19:21:08 -10:00
parent 0a9092156c
commit 8f8ce26948
60 changed files with 273 additions and 255 deletions

134
static/pyodide/package.json Normal file
View File

@@ -0,0 +1,134 @@
{
"name": "pyodide",
"version": "0.25.1",
"description": "The Pyodide JavaScript package",
"keywords": [
"python",
"webassembly"
],
"homepage": "https://github.com/pyodide/pyodide",
"repository": {
"type": "git",
"url": "https://github.com/pyodide/pyodide"
},
"bugs": {
"url": "https://github.com/pyodide/pyodide/issues"
},
"license": "Apache-2.0",
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/expect": "^24.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^20.8.4",
"@types/ws": "^8.5.3",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"dts-bundle-generator": "^8.1.1",
"error-stack-parser": "^2.1.4",
"esbuild": "^0.17.12",
"express": "^4.17.3",
"mocha": "^9.0.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"ts-mocha": "^9.0.2",
"tsd": "^0.24.1",
"typedoc": "^0.25.1",
"typescript": "^4.6.4",
"wabt": "^1.0.32"
},
"main": "pyodide.js",
"exports": {
".": {
"require": "./pyodide.js",
"import": "./pyodide.mjs",
"types": "./pyodide.d.ts"
},
"./ffi": {
"types": "./ffi.d.ts"
},
"./pyodide.asm.wasm": "./pyodide.asm.wasm",
"./pyodide.asm.js": "./pyodide.asm.js",
"./python_stdlib.zip": "./python_stdlib.zip",
"./pyodide.mjs": "./pyodide.mjs",
"./pyodide.js": "./pyodide.js",
"./package.json": "./package.json",
"./pyodide-lock.json": "./pyodide-lock.json"
},
"files": [
"pyodide.asm.js",
"pyodide.asm.wasm",
"python_stdlib.zip",
"pyodide.mjs",
"pyodide.js.map",
"pyodide.mjs.map",
"pyodide.d.ts",
"ffi.d.ts",
"pyodide-lock.json",
"console.html"
],
"browser": {
"child_process": false,
"crypto": false,
"fs": false,
"fs/promises": false,
"path": false,
"url": false,
"vm": false,
"ws": false
},
"scripts": {
"build": "tsc --noEmit && node esbuild.config.mjs",
"test": "npm-run-all test:*",
"test:unit": "cross-env TEST_NODE=1 ts-mocha --node-option=experimental-loader=./test/loader.mjs --node-option=experimental-wasm-stack-switching -p tsconfig.test.json test/unit/**/*.test.*",
"test:node": "cross-env TEST_NODE=1 mocha test/integration/**/*.test.js",
"test:browser": "mocha test/integration/**/*.test.js",
"tsc": "tsc --noEmit",
"coverage": "cross-env TEST_NODE=1 npm-run-all coverage:*",
"coverage:build": "nyc npm run test:node"
},
"mocha": {
"bail": false,
"timeout": 30000,
"full-trace": true,
"inline-diffs": true,
"check-leaks": false,
"global": [
"pyodide",
"page",
"chai"
]
},
"nyc": {
"reporter": [
"html",
"text-summary"
],
"include": [
"*.ts"
],
"all": true,
"clean": true,
"cache": false,
"instrument": false,
"checkCoverage": true,
"statements": 95,
"functions": 95,
"branches": 80,
"lines": 95
},
"tsd": {
"compilerOptions": {
"lib": [
"ES2017",
"DOM"
]
}
},
"dependencies": {
"base-64": "^1.0.0",
"ws": "^8.5.0"
},
"types": "./pyodide.d.ts"
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -653,10 +653,36 @@ declare class PyCallableMethods {
*/
call(thisArg: any, ...jsargs: any): any;
/**
* Call the function with key word arguments. The last argument must be an
* Call the function with keyword arguments. The last argument must be an
* object with the keyword arguments.
*/
callKwargs(...jsargs: any): any;
/**
* Call the function in a "relaxed" manner. Any extra arguments will be
* ignored. This matches the behavior of JavaScript functions more accurately.
*
* Any extra arguments will be ignored. This matches the behavior of
* JavaScript functions more accurately. Missing arguments are **NOT** filled
* with `None`. If too few arguments are passed, this will still raise a
* TypeError.
*
* This uses :py:func:`pyodide.code.relaxed_call`.
*/
callRelaxed(...jsargs: any): any;
/**
* Call the function with keyword arguments in a "relaxed" manner. The last
* argument must be an object with the keyword arguments. Any extra arguments
* will be ignored. This matches the behavior of JavaScript functions more
* accurately.
*
* Missing arguments are **NOT** filled with `None`. If too few arguments are
* passed, this will still raise a TypeError. Also, if the same argument is
* passed as both a keyword argument and a positional argument, it will raise
* an error.
*
* This uses :py:func:`pyodide.code.relaxed_call`.
*/
callKwargsRelaxed(...jsargs: any): any;
/**
* Call the function with stack switching enabled. Functions called this way
* can use
@@ -911,7 +937,7 @@ interface CanvasInterface {
declare class PythonError extends Error {
/**
* The address of the error we are wrapping. We may later compare this
* against sys.last_value.
* against sys.last_exc.
* WARNING: we don't own a reference to this pointer, dereferencing it
* may be a use-after-free error!
* @private
@@ -1128,36 +1154,6 @@ declare class PyodideAPI {
locals?: PyProxy;
filename?: string;
}): Promise<any>;
/**
* Runs a Python code string like :js:func:`pyodide.runPython` but with stack
* switching enabled. Code executed in this way can use
* :py:meth:`PyodideFuture.syncify() <pyodide.webloop.PyodideFuture.syncify>`
* to block until a :py:class:`~asyncio.Future` or :js:class:`Promise` is
* resolved. Only works in runtimes with JS Promise Integration enabled.
*
* .. admonition:: Experimental
* :class: warning
*
* This feature is not yet stable.
*
* @experimental
* @param code The Python code to run
* @param options
* @param options.globals An optional Python dictionary to use as the globals.
* Defaults to :js:attr:`pyodide.globals`.
* @param options.locals An optional Python dictionary to use as the locals.
* Defaults to the same as ``globals``.
* @param options.filename An optional string to use as the file name.
* Defaults to ``"<exec>"``. If a custom file name is given, the
* traceback for any exception that is thrown will show source lines
* (unless the given file name starts with ``<`` and ends with ``>``).
* @returns The result of the Python code translated to JavaScript.
*/
static runPythonSyncifying(code: string, options?: {
globals?: PyProxy;
locals?: PyProxy;
filename?: string;
}): Promise<any>;
/**
* Registers the JavaScript object ``module`` as a JavaScript module named
* ``name``. This module can then be imported from Python using the standard
@@ -1232,30 +1228,25 @@ declare class PyodideAPI {
/**
* Imports a module and returns it.
*
* .. admonition:: Warning
* :class: warning
*
* This function has a completely different behavior than the old removed pyimport function!
*
* ``pyimport`` is roughly equivalent to:
*
* .. code-block:: js
*
* pyodide.runPython(`import ${pkgname}; ${pkgname}`);
*
* except that the global namespace will not change.
*
* Example:
*
* .. code-block:: js
*
* let sysmodule = pyodide.pyimport("sys");
* let recursionLimit = sysmodule.getrecursionlimit();
* If `name` has no dot in it, then `pyimport(name)` is approximately
* equivalent to:
* ```js
* pyodide.runPython(`import ${name}; ${name}`)
* ```
* except that `name` is not introduced into the Python global namespace. If
* the name has one or more dots in it, say it is of the form `path.name`
* where `name` has no dots but path may have zero or more dots. Then it is
* approximately the same as:
* ```js
* pyodide.runPython(`from ${path} import ${name}; ${name}`);
* ```
*
* @param mod_name The name of the module to import
* @returns A PyProxy for the imported module
*
* @example
* pyodide.pyimport("math.comb")(4, 2) // returns 4 choose 2 = 6
*/
static pyimport(mod_name: string): PyProxy;
static pyimport(mod_name: string): any;
/**
* Unpack an archive into a target directory.
*
@@ -1277,14 +1268,26 @@ declare class PyodideAPI {
}): void;
/**
* Mounts a :js:class:`FileSystemDirectoryHandle` into the target directory.
* Currently it's only possible to acquire a
* :js:class:`FileSystemDirectoryHandle` in Chrome.
*
* @param path The absolute path in the Emscripten file system to mount the
* native directory. If the directory does not exist, it will be created. If it
* does exist, it must be empty.
* @param fileSystemHandle A handle returned by :js:func:`navigator.storage.getDirectory() <getDirectory>`
* or :js:func:`window.showDirectoryPicker() <showDirectoryPicker>`.
* native directory. If the directory does not exist, it will be created. If
* it does exist, it must be empty.
* @param fileSystemHandle A handle returned by
* :js:func:`navigator.storage.getDirectory() <getDirectory>` or
* :js:func:`window.showDirectoryPicker() <showDirectoryPicker>`.
*/
static mountNativeFS(path: string, fileSystemHandle: FileSystemDirectoryHandle): Promise<NativeFS>;
/**
* Mounts a host directory into Pyodide file system. Only works in node.
*
* @param emscriptenPath The absolute path in the Emscripten file system to
* mount the native directory. If the directory does not exist, it will be
* created. If it does exist, it must be empty.
* @param hostPath The host path to mount. It must be a directory that exists.
*/
static mountNodeFS(emscriptenPath: string, hostPath: string): void;
/**
* Tell Pyodide about Comlink.
* Necessary to enable importing Comlink proxies into Python.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.