diff --git a/src/core/pyproxy.ts b/src/core/pyproxy.ts index 3a4b4091454..7671075f8a1 100644 --- a/src/core/pyproxy.ts +++ b/src/core/pyproxy.ts @@ -18,7 +18,7 @@ declare var Tests: any; declare var Module: any; declare var Hiwire: any; -import { TypedArray } from "lib"; +import { TypedArray } from "types"; import { warnOnce } from "pyodide_util"; // pyodide-skip diff --git a/src/js/api.ts b/src/js/api.ts index dec12552fa6..89736341ccf 100644 --- a/src/js/api.ts +++ b/src/js/api.ts @@ -11,7 +11,7 @@ import { loadBinaryFile } from "./compat"; import { version } from "./version"; import "./error_handling.gen.js"; import { setStdin, setStdout, setStderr } from "./streams"; -import { TypedArray } from "./lib"; +import { TypedArray } from "./types"; // Exported for micropip API.loadBinaryFile = loadBinaryFile; diff --git a/src/js/ffi.ts b/src/js/ffi.ts index ee538f6edc9..de1746b7b7e 100644 --- a/src/js/ffi.ts +++ b/src/js/ffi.ts @@ -19,7 +19,7 @@ export type { PyMutableSequence, } from "./pyproxy.gen"; -export type { TypedArray } from "./lib"; +export type { TypedArray } from "./types"; export type { PythonError } from "./error_handling.gen"; diff --git a/src/js/lib.ts b/src/js/lib.ts deleted file mode 100644 index be534a55454..00000000000 --- a/src/js/lib.ts +++ /dev/null @@ -1,330 +0,0 @@ -export {}; -import { type PyProxy } from "./pyproxy.gen"; -import { type PyodideInterface } from "./api"; -import { type ConfigType } from "./pyodide"; -import { type InFuncType } from "./streams"; -import { type PackageData } from "./load-package"; - -export type TypedArray = - | Int8Array - | Uint8Array - | Int16Array - | Uint16Array - | Int32Array - | Uint32Array - | Uint8ClampedArray - | Float32Array - | Float64Array; - -declare global { - export var Module: Module; - export var API: API; -} - -// Emscripten runtime methods - -// These should be declared with EM_JS_DEPS so that when linking libpyodide it's -// not necessary to put them in `-s EXPORTED_RUNTIME_METHODS`. -declare global { - export const stringToNewUTF8: (str: string) => number; - export const UTF8ToString: (ptr: number) => string; - export const FS: FS; - export const stackAlloc: (sz: number) => number; - export const stackSave: () => number; - export const stackRestore: (ptr: number) => void; - export const HEAPU32: Uint32Array; -} - -// Library functions that are used in JS. To link with dce, these all need to be -// passed to -sEXPORTED_FUNCTIONS. -// TODO: Figure out how to avoid needing to do this. -declare global { - // also need: - // _hiwire_new, _hiwire_intern, _hiwire_num_refs, _hiwire_get, - // _hiwire_incref, _hiwire_decref, and _hiwire_pop - // - // _PyUnicode_New, - // __PyLong_FromByteArray, _PyLong_FromDouble, _PyFloat_FromDouble, - // _PyList_New, _PyDict_New, _PyDict_SetItem, _PySet_New, _PySet_Add - // _PyEval_SaveThread, _PyEval_RestoreThread, - // _PyErr_CheckSignals, _PyErr_SetString - export const _free: (a: number) => void; - export const __PyTraceback_Add: (a: number, b: number, c: number) => void; - export const _PyRun_SimpleString: (ptr: number) => number; - export const _PyErr_Occurred: () => number; - export const _PyErr_Print: () => void; - export const _Py_IncRef: (ptr: number) => void; - export const _Py_DecRef: (ptr: number) => void; - export const _PyObject_GetIter: (ptr: number) => number; - export const _PyObject_GetAIter: (ptr: number) => number; - export const _PyObject_Size: (ptr: number) => number; - export const _PyBuffer_Release: (ptr: number) => number; - export const _PyMem_Free: (ptr: number) => number; - export const _PyGILState_Check: () => number; - export const __PyErr_CheckSignals: () => number; -} - -// Our own functions we use from JavaScript. These all need to be labeled with -// EMSCRIPTEN_KEEPALIVE -declare global { - // also: _JsString_FromId, _wrap_exception, _PyUnicode_Data, __js2python_none, - // __js2python_true, __js2python_false, __js2python_pyproxy, _JsBuffer_CopyIntoMemoryView - export const _check_gil: () => void; - export const _dump_traceback: () => void; - export const _pythonexc2js: () => void; - export const _restore_sys_last_exception: (err: number) => boolean; - export const _set_error: (hwidx: number) => void; - - export const _JsProxy_create: (hwidx: number) => number; - export const _JsProxy_Check: (ptr: number) => number; - - export const _python2js: (pyobj: number) => number; - export const _python2js_custom: ( - obj: number, - depth: number, - proxies: number, - dict_converter: number, - default_converter: number, - ) => number; - - export const _pyproxy_getflags: (ptr: number) => number; - export const __pyproxy_type: (ptr: number) => number; - export const __pyproxy_repr: (ptr: number) => number; - export const __pyproxy_getitem: (obj: number, item: number) => number; - export const __pyproxy_setitem: ( - ptr: number, - item: number, - value: number, - ) => number; - export const __pyproxy_delitem: (ptr: number, item: number) => number; - export const __pyproxy_contains: (ptr: number, item: number) => number; - export const __pyproxy_GetIter: (ptr: number) => number; - export const __pyproxy_GetAIter: (ptr: number) => number; - export const __pyproxy_aiter_next: (ptr: number) => number; - export const __pyproxy_iter_next: (ptr: number) => number; - export const __pyproxyGen_Send: ( - ptr: number, - idarg: number, - res_ptr: number, - ) => number; - export const __pyproxyGen_return: ( - ptr: number, - idarg: number, - res_ptr: number, - ) => number; - export const __pyproxyGen_throw: ( - ptr: number, - idarg: number, - res_ptr: number, - ) => number; - export const __pyproxyGen_asend: (ptr: number, idarg: number) => number; - export const __pyproxyGen_areturn: (ptr: number) => number; - export const __pyproxyGen_athrow: (ptr: number, idarg: number) => number; - export const __pyproxy_getattr: ( - ptr: number, - attr: number, - cache: number, - ) => number; - export const __pyproxy_setattr: ( - ptr: number, - attr: number, - value: number, - ) => number; - export const __pyproxy_delattr: (ptr: number, attr: number) => number; - export const __pyproxy_hasattr: (ptr: number, attr: number) => number; - export const __pyproxy_slice_assign: ( - ptr: number, - start: number, - stop: number, - val: number, - ) => number; - export const __pyproxy_pop: (ptr: number, popstart: boolean) => number; - export const __pyproxy_ownKeys: (ptr: number) => number; - export const __pyproxy_ensure_future: ( - ptr: number, - resolve: number, - reject: number, - ) => number; - export const _buffer_struct_size: number; - export const __pyproxy_get_buffer: (ptr: number, this_: number) => number; - export const __pyproxy_apply: ( - a: number, - b: number, - c: number, - d: number, - e: number, - ) => number; - export const __iscoroutinefunction: (a: number) => number; -} - -export type FSNode = { - timestamp: number; - rdev: number; - contents: Uint8Array; -}; - -export type FSStream = { - tty?: boolean; - seekable?: boolean; - stream_ops: FSStreamOps; - node: FSNode; -}; - -export type FSStreamOps = FSStreamOpsGen; - -export type FSStreamOpsGen = { - open: (a: T) => void; - close: (a: T) => void; - fsync: (a: T) => void; - read: ( - a: T, - b: Uint8Array, - offset: number, - length: number, - pos: number, - ) => number; - write: ( - a: T, - b: Uint8Array, - offset: number, - length: number, - pos: number, - ) => number; -}; - -export interface FS { - unlink: (path: string) => void; - mkdirTree: (path: string, mode?: number) => void; - chdir: (path: string) => void; - symlink: (target: string, src: string) => FSNode; - createDevice: (( - parent: string, - name: string, - input?: (() => number | null) | null, - output?: ((code: number) => void) | null, - ) => FSNode) & { - major: number; - }; - closeStream: (fd: number) => void; - open: (path: string, flags: string | number, mode?: number) => FSStream; - makedev: (major: number, minor: number) => number; - mkdev: (path: string, dev: number) => FSNode; - filesystems: any; - stat: (path: string, dontFollow?: boolean) => any; - readdir: (node: FSNode) => string[]; - isDir: (mode: number) => boolean; - lookupPath: (path: string) => { node: FSNode }; - isFile: (mode: number) => boolean; - writeFile: (path: string, contents: any, o?: { canOwn?: boolean }) => void; - chmod: (path: string, mode: number) => void; - utime: (path: string, atime: number, mtime: number) => void; - rmdir: (path: string) => void; - mount: (type: any, opts: any, mountpoint: string) => any; - write: ( - stream: FSStream, - buffer: any, - offset: number, - length: number, - position?: number, - ) => number; - close: (stream: FSStream) => void; - ErrnoError: { new (errno: number): Error }; - registerDevice(dev: number, ops: FSStreamOpsGen): void; -} - -export interface Module { - noImageDecoding: boolean; - noAudioDecoding: boolean; - noWasmDecoding: boolean; - quit: (status: number, toThrow: Error) => void; - preRun: { (): void }[]; - print: (a: string) => void; - printErr: (a: string) => void; - ENV: { [key: string]: string }; - PATH: any; - TTY: any; - FS: FS; - canvas?: HTMLCanvasElement; - addRunDependency: (id: string) => void; - removeRunDependency: (id: string) => void; - reportUndefinedSymbols: () => void; - ERRNO_CODES: { [k: string]: number }; - instantiateWasm?: ( - imports: { [key: string]: any }, - successCallback: ( - instance: WebAssembly.Instance, - module: WebAssembly.Module, - ) => void, - ) => void; -} - -export interface API { - fatal_error: (e: any) => never; - lockfile_info: any; - lockfile_packages: any; - isPyProxy: (e: any) => e is PyProxy; - debug_ffi: boolean; - maybe_fatal_error: (e: any) => void; - public_api: PyodideInterface; - config: ConfigType; - packageIndexReady: Promise; - bootstrapFinalizedPromise: Promise; - setCdnUrl: (url: string) => void; - typedArrayAsUint8Array: (buffer: TypedArray | ArrayBuffer) => Uint8Array; - initializeStreams: ( - stdin?: InFuncType | undefined, - stdout?: ((a: string) => void) | undefined, - stderr?: ((a: string) => void) | undefined, - ) => void; - - getTypeTag: (o: any) => string; - inTestHoist?: boolean; - on_fatal?: (e: any) => void; - _skip_unwind_fatal_error?: boolean; - capture_stderr: () => void; - restore_stderr: () => string; - fatal_loading_error: (...args: string[]) => never; - PythonError: any; - NoGilError: any; - errorConstructors: Map; - deserializeError: (name: string, message: string, stack: string) => Error; - - package_loader: any; - importlib: any; - _import_name_to_package_name: Map; - lockfile_unvendored_stdlibs: string[]; - lockfile_unvendored_stdlibs_and_test: string[]; - repodata_packages: any; - repodata_info: any; - loadBinaryFile: ( - path: string, - file_sub_resource_hash?: string | undefined, - ) => Promise; - - _pyodide: any; - pyodide_py: any; - pyodide_code: any; - pyodide_ffi: any; - globals: PyProxy; - rawRun: (code: string) => [number, string]; - runPythonInternal: (code: string) => any; - runPythonInternal_dict: any; - saveState: () => any; - restoreState: (state: any) => void; - - defaultLdLibraryPath: string[]; - sitepackages: string; - loadDynlib: ( - lib: string, - global: boolean, - searchDirs?: string[] | undefined, - readFileFunc?: (path: string) => Uint8Array, - ) => Promise; - loadDynlibsFromPackage: ( - pkg: PackageData, - dynlibPaths: string[], - ) => Promise; - - makePublicAPI: () => PyodideInterface; - _Comlink: any; -} diff --git a/src/js/module.ts b/src/js/module.ts index 24692e1fa5b..7ac40ce103c 100644 --- a/src/js/module.ts +++ b/src/js/module.ts @@ -3,7 +3,7 @@ import { ConfigType } from "./pyodide"; import { initializeNativeFS } from "./nativefs"; import { loadBinaryFile, getBinaryResponse } from "./compat"; -import { FS, Module } from "./lib"; +import { Module } from "./types"; /** * The Emscripten Module. diff --git a/src/js/nativefs.ts b/src/js/nativefs.ts index fe71fc10c4e..cf44d0f3b02 100644 --- a/src/js/nativefs.ts +++ b/src/js/nativefs.ts @@ -1,4 +1,4 @@ -import { Module } from "./lib"; +import { Module } from "./types"; /** * @private diff --git a/src/js/pyodide.ts b/src/js/pyodide.ts index 9a162e43053..384f9fda799 100644 --- a/src/js/pyodide.ts +++ b/src/js/pyodide.ts @@ -9,7 +9,7 @@ import { version } from "./version"; import type { PyodideInterface } from "./api.js"; import type { PyProxy, PyDict } from "./pyproxy.gen"; -import type { TypedArray } from "./lib"; +import type { TypedArray } from "./types"; export type { PyodideInterface, TypedArray }; export type { diff --git a/src/js/streams.ts b/src/js/streams.ts index be3b85cb633..7e40940ec0a 100644 --- a/src/js/streams.ts +++ b/src/js/streams.ts @@ -1,7 +1,7 @@ import { IN_NODE } from "./compat.js"; import "./constants"; -import type { FSStream, FSStreamOpsGen } from "./lib"; +import type { FSStream, FSStreamOpsGen } from "./types"; const fs: any = IN_NODE ? require("fs") : undefined; const tty: any = IN_NODE ? require("tty") : undefined;