pyodide 0.24.0-alpha.1 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pyodide-lock.json +533 -468
- package/pyodide.asm.js +1 -1
- package/pyodide.asm.wasm +0 -0
- package/pyodide.d.ts +45 -18
- package/pyodide.js +8 -8
- package/pyodide.js.map +3 -3
- package/pyodide.mjs +8 -8
- package/pyodide.mjs.map +3 -3
- package/python_stdlib.zip +0 -0
package/pyodide.asm.wasm
CHANGED
|
Binary file
|
package/pyodide.d.ts
CHANGED
|
@@ -925,7 +925,7 @@ declare function loadPackage(names: string | PyProxy | Array<string>, options?:
|
|
|
925
925
|
messageCallback?: (message: string) => void;
|
|
926
926
|
errorCallback?: (message: string) => void;
|
|
927
927
|
checkIntegrity?: boolean;
|
|
928
|
-
}
|
|
928
|
+
}): Promise<void>;
|
|
929
929
|
declare class PythonError extends Error {
|
|
930
930
|
/**
|
|
931
931
|
* The address of the error we are wrapping. We may later compare this
|
|
@@ -1077,14 +1077,13 @@ declare class PyodideAPI {
|
|
|
1077
1077
|
* (optional)
|
|
1078
1078
|
* @param options.checkIntegrity If true, check the integrity of the downloaded
|
|
1079
1079
|
* packages (default: true)
|
|
1080
|
-
* @param errorCallbackDeprecated @ignore
|
|
1081
1080
|
* @async
|
|
1082
1081
|
*/
|
|
1083
1082
|
static loadPackagesFromImports(code: string, options?: {
|
|
1084
1083
|
messageCallback?: (message: string) => void;
|
|
1085
1084
|
errorCallback?: (message: string) => void;
|
|
1086
1085
|
checkIntegrity?: boolean;
|
|
1087
|
-
}
|
|
1086
|
+
}): Promise<void>;
|
|
1088
1087
|
/**
|
|
1089
1088
|
* Runs a string of Python code from JavaScript, using :py:func:`~pyodide.code.eval_code`
|
|
1090
1089
|
* to evaluate the code. If the last statement in the Python code is an
|
|
@@ -1097,6 +1096,10 @@ declare class PyodideAPI {
|
|
|
1097
1096
|
* Defaults to :js:attr:`pyodide.globals`.
|
|
1098
1097
|
* @param options.locals An optional Python dictionary to use as the locals.
|
|
1099
1098
|
* Defaults to the same as ``globals``.
|
|
1099
|
+
* @param options.filename An optional string to use as the filename. Defaults
|
|
1100
|
+
* to "<exec>". If the filename does not start with "<" and end with ">",
|
|
1101
|
+
* the source code will be added to the Python linecache and tracebacks
|
|
1102
|
+
* will show source lines.
|
|
1100
1103
|
* @returns The result of the Python code translated to JavaScript. See the
|
|
1101
1104
|
* documentation for :py:func:`~pyodide.code.eval_code` for more info.
|
|
1102
1105
|
* @example
|
|
@@ -1118,6 +1121,7 @@ declare class PyodideAPI {
|
|
|
1118
1121
|
static runPython(code: string, options?: {
|
|
1119
1122
|
globals?: PyProxy;
|
|
1120
1123
|
locals?: PyProxy;
|
|
1124
|
+
filename?: string;
|
|
1121
1125
|
}): any;
|
|
1122
1126
|
/**
|
|
1123
1127
|
* Run a Python code string with top level await using
|
|
@@ -1152,12 +1156,17 @@ declare class PyodideAPI {
|
|
|
1152
1156
|
* Defaults to :js:attr:`pyodide.globals`.
|
|
1153
1157
|
* @param options.locals An optional Python dictionary to use as the locals.
|
|
1154
1158
|
* Defaults to the same as ``globals``.
|
|
1159
|
+
* @param options.filename An optional string to use as the filename. Defaults
|
|
1160
|
+
* to "<exec>". If the filename does not start with "<" and end with ">",
|
|
1161
|
+
* the source code will be added to the Python linecache and tracebacks
|
|
1162
|
+
* will show source lines.
|
|
1155
1163
|
* @returns The result of the Python code translated to JavaScript.
|
|
1156
1164
|
* @async
|
|
1157
1165
|
*/
|
|
1158
1166
|
static runPythonAsync(code: string, options?: {
|
|
1159
1167
|
globals?: PyProxy;
|
|
1160
1168
|
locals?: PyProxy;
|
|
1169
|
+
filename?: string;
|
|
1161
1170
|
}): Promise<any>;
|
|
1162
1171
|
/**
|
|
1163
1172
|
* Registers the JavaScript object ``module`` as a JavaScript module named
|
|
@@ -1323,7 +1332,7 @@ declare class PyodideAPI {
|
|
|
1323
1332
|
*/
|
|
1324
1333
|
static get PyProxyBuffer(): typeof PyBuffer;
|
|
1325
1334
|
/**
|
|
1326
|
-
* An alias for :js:class:`pyodide.ffi.
|
|
1335
|
+
* An alias for :js:class:`pyodide.ffi.PythonError`.
|
|
1327
1336
|
*
|
|
1328
1337
|
* @hidetype
|
|
1329
1338
|
* @alias
|
|
@@ -1341,7 +1350,6 @@ declare class PyodideAPI {
|
|
|
1341
1350
|
}
|
|
1342
1351
|
/** @hidetype */
|
|
1343
1352
|
export declare type PyodideInterface = typeof PyodideAPI;
|
|
1344
|
-
export declare type Py2JsResult = any;
|
|
1345
1353
|
/**
|
|
1346
1354
|
* See documentation for loadPyodide.
|
|
1347
1355
|
* @private
|
|
@@ -1362,6 +1370,7 @@ export declare type ConfigType = {
|
|
|
1362
1370
|
env: {
|
|
1363
1371
|
[key: string]: string;
|
|
1364
1372
|
};
|
|
1373
|
+
packages: string[];
|
|
1365
1374
|
};
|
|
1366
1375
|
/**
|
|
1367
1376
|
* Load the main Pyodide wasm module and initialize it.
|
|
@@ -1391,10 +1400,10 @@ export declare function loadPyodide(options?: {
|
|
|
1391
1400
|
*/
|
|
1392
1401
|
indexURL?: string;
|
|
1393
1402
|
/**
|
|
1394
|
-
* The file path where packages will be cached in
|
|
1395
|
-
* exists in
|
|
1396
|
-
* downloaded from the JsDelivr CDN and then cached into
|
|
1397
|
-
* Only applies when running in node
|
|
1403
|
+
* The file path where packages will be cached in node. If a package
|
|
1404
|
+
* exists in ``packageCacheDir`` it is loaded from there, otherwise it is
|
|
1405
|
+
* downloaded from the JsDelivr CDN and then cached into ``packageCacheDir``.
|
|
1406
|
+
* Only applies when running in node; ignored in browsers.
|
|
1398
1407
|
*
|
|
1399
1408
|
* Default: same as indexURL
|
|
1400
1409
|
*/
|
|
@@ -1418,23 +1427,32 @@ export declare function loadPyodide(options?: {
|
|
|
1418
1427
|
fullStdLib?: boolean;
|
|
1419
1428
|
/**
|
|
1420
1429
|
* The URL from which to load the standard library ``python_stdlib.zip``
|
|
1421
|
-
* file. This URL includes the most of the Python
|
|
1430
|
+
* file. This URL includes the most of the Python standard library. Some
|
|
1422
1431
|
* stdlib modules were unvendored, and can be loaded separately
|
|
1423
|
-
* with ``fullStdLib
|
|
1432
|
+
* with ``fullStdLib: true`` option or by their package name.
|
|
1424
1433
|
* Default: ```${indexURL}/python_stdlib.zip```
|
|
1425
1434
|
*/
|
|
1426
1435
|
stdLibURL?: string;
|
|
1427
1436
|
/**
|
|
1428
1437
|
* Override the standard input callback. Should ask the user for one line of
|
|
1429
|
-
* input.
|
|
1438
|
+
* input. The :js:func:`pyodide.setStdin` function is more flexible and
|
|
1439
|
+
* should be preferred.
|
|
1430
1440
|
*/
|
|
1431
1441
|
stdin?: () => string;
|
|
1432
1442
|
/**
|
|
1433
|
-
* Override the standard output callback.
|
|
1443
|
+
* Override the standard output callback. The :js:func:`pyodide.setStdout`
|
|
1444
|
+
* function is more flexible and should be preferred in most cases, but
|
|
1445
|
+
* depending on the ``args`` passed to ``loadPyodide``, Pyodide may write to
|
|
1446
|
+
* stdout on startup, which can only be controlled by passing a custom
|
|
1447
|
+
* ``stdout`` function.
|
|
1434
1448
|
*/
|
|
1435
1449
|
stdout?: (msg: string) => void;
|
|
1436
1450
|
/**
|
|
1437
|
-
* Override the standard error output callback.
|
|
1451
|
+
* Override the standard error output callback. The
|
|
1452
|
+
* :js:func:`pyodide.setStderr` function is more flexible and should be
|
|
1453
|
+
* preferred in most cases, but depending on the ``args`` passed to
|
|
1454
|
+
* ``loadPyodide``, Pyodide may write to stdout on startup, which can only
|
|
1455
|
+
* be controlled by passing a custom ``stdout`` function.
|
|
1438
1456
|
*/
|
|
1439
1457
|
stderr?: (msg: string) => void;
|
|
1440
1458
|
/**
|
|
@@ -1451,16 +1469,25 @@ export declare function loadPyodide(options?: {
|
|
|
1451
1469
|
args?: string[];
|
|
1452
1470
|
/**
|
|
1453
1471
|
* Environment variables to pass to Python. This can be accessed inside of
|
|
1454
|
-
* Python at runtime via
|
|
1472
|
+
* Python at runtime via :py:data:`os.environ`. Certain environment variables change
|
|
1455
1473
|
* the way that Python loads:
|
|
1456
1474
|
* https://docs.python.org/3.10/using/cmdline.html#environment-variables
|
|
1457
|
-
* Default: {}
|
|
1458
|
-
* If
|
|
1459
|
-
*
|
|
1475
|
+
* Default: ``{}``.
|
|
1476
|
+
* If ``env.HOME`` is undefined, it will be set to a default value of
|
|
1477
|
+
* ``"/home/pyodide"``
|
|
1460
1478
|
*/
|
|
1461
1479
|
env?: {
|
|
1462
1480
|
[key: string]: string;
|
|
1463
1481
|
};
|
|
1482
|
+
/**
|
|
1483
|
+
* A list of packages to load as Pyodide is initializing.
|
|
1484
|
+
*
|
|
1485
|
+
* This is the same as loading the packages with
|
|
1486
|
+
* :js:func:`pyodide.loadPackage` after Pyodide is loaded except using the
|
|
1487
|
+
* ``packages`` option is more efficient because the packages are downloaded
|
|
1488
|
+
* while Pyodide bootstraps itself.
|
|
1489
|
+
*/
|
|
1490
|
+
packages?: string[];
|
|
1464
1491
|
/**
|
|
1465
1492
|
* @ignore
|
|
1466
1493
|
*/
|
package/pyodide.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var loadPyodide=(()=>{var
|
|
2
|
-
`).filter(function(i){return!!i.match(s)},this);return
|
|
3
|
-
`).filter(function(i){return!i.match(
|
|
1
|
+
"use strict";var loadPyodide=(()=>{var te=Object.create;var w=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var m=(e,t)=>w(e,"name",{value:t,configurable:!0}),g=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,a)=>(typeof require<"u"?require:t)[a]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});var U=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ae=(e,t)=>{for(var a in t)w(e,a,{get:t[a],enumerable:!0})},$=(e,t,a,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ne(t))!oe.call(e,o)&&o!==a&&w(e,o,{get:()=>t[o],enumerable:!(s=re(t,o))||s.enumerable});return e};var b=(e,t,a)=>(a=e!=null?te(ie(e)):{},$(t||!e||!e.__esModule?w(a,"default",{value:e,enumerable:!0}):a,e)),se=e=>$(w({},"__esModule",{value:!0}),e);var C=U((R,j)=>{(function(e,t){"use strict";typeof define=="function"&&define.amd?define("stackframe",[],t):typeof R=="object"?j.exports=t():e.StackFrame=t()})(R,function(){"use strict";function e(u){return!isNaN(parseFloat(u))&&isFinite(u)}m(e,"_isNumber");function t(u){return u.charAt(0).toUpperCase()+u.substring(1)}m(t,"_capitalize");function a(u){return function(){return this[u]}}m(a,"_getter");var s=["isConstructor","isEval","isNative","isToplevel"],o=["columnNumber","lineNumber"],r=["fileName","functionName","source"],n=["args"],c=["evalOrigin"],i=s.concat(o,r,n,c);function l(u){if(u)for(var y=0;y<i.length;y++)u[i[y]]!==void 0&&this["set"+t(i[y])](u[i[y]])}m(l,"StackFrame"),l.prototype={getArgs:function(){return this.args},setArgs:function(u){if(Object.prototype.toString.call(u)!=="[object Array]")throw new TypeError("Args must be an Array");this.args=u},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(u){if(u instanceof l)this.evalOrigin=u;else if(u instanceof Object)this.evalOrigin=new l(u);else throw new TypeError("Eval Origin must be an Object or StackFrame")},toString:function(){var u=this.getFileName()||"",y=this.getLineNumber()||"",h=this.getColumnNumber()||"",_=this.getFunctionName()||"";return this.getIsEval()?u?"[eval] ("+u+":"+y+":"+h+")":"[eval]:"+y+":"+h:_?_+" ("+u+":"+y+":"+h+")":u+":"+y+":"+h}},l.fromString=m(function(y){var h=y.indexOf("("),_=y.lastIndexOf(")"),Y=y.substring(0,h),J=y.substring(h+1,_).split(","),D=y.substring(_+1);if(D.indexOf("@")===0)var O=/@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(D,""),Q=O[1],Z=O[2],ee=O[3];return new l({functionName:Y,args:J||void 0,fileName:Q,lineNumber:Z||void 0,columnNumber:ee||void 0})},"StackFrame$$fromString");for(var d=0;d<s.length;d++)l.prototype["get"+t(s[d])]=a(s[d]),l.prototype["set"+t(s[d])]=function(u){return function(y){this[u]=!!y}}(s[d]);for(var p=0;p<o.length;p++)l.prototype["get"+t(o[p])]=a(o[p]),l.prototype["set"+t(o[p])]=function(u){return function(y){if(!e(y))throw new TypeError(u+" must be a Number");this[u]=Number(y)}}(o[p]);for(var f=0;f<r.length;f++)l.prototype["get"+t(r[f])]=a(r[f]),l.prototype["set"+t(r[f])]=function(u){return function(y){this[u]=String(y)}}(r[f]);return l})});var A=U((N,M)=>{(function(e,t){"use strict";typeof define=="function"&&define.amd?define("error-stack-parser",["stackframe"],t):typeof N=="object"?M.exports=t(C()):e.ErrorStackParser=t(e.StackFrame)})(N,m(function(t){"use strict";var a=/(^|@)\S+:\d+/,s=/^\s*at .*(\S+:\d+|\(native\))/m,o=/^(eval@)?(\[native code])?$/;return{parse:m(function(n){if(typeof n.stacktrace<"u"||typeof n["opera#sourceloc"]<"u")return this.parseOpera(n);if(n.stack&&n.stack.match(s))return this.parseV8OrIE(n);if(n.stack)return this.parseFFOrSafari(n);throw new Error("Cannot parse given Error object")},"ErrorStackParser$$parse"),extractLocation:m(function(n){if(n.indexOf(":")===-1)return[n];var c=/(.+?)(?::(\d+))?(?::(\d+))?$/,i=c.exec(n.replace(/[()]/g,""));return[i[1],i[2]||void 0,i[3]||void 0]},"ErrorStackParser$$extractLocation"),parseV8OrIE:m(function(n){var c=n.stack.split(`
|
|
2
|
+
`).filter(function(i){return!!i.match(s)},this);return c.map(function(i){i.indexOf("(eval ")>-1&&(i=i.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var l=i.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),d=l.match(/ (\(.+\)$)/);l=d?l.replace(d[0],""):l;var p=this.extractLocation(d?d[1]:l),f=d&&l||void 0,u=["eval","<anonymous>"].indexOf(p[0])>-1?void 0:p[0];return new t({functionName:f,fileName:u,lineNumber:p[1],columnNumber:p[2],source:i})},this)},"ErrorStackParser$$parseV8OrIE"),parseFFOrSafari:m(function(n){var c=n.stack.split(`
|
|
3
|
+
`).filter(function(i){return!i.match(o)},this);return c.map(function(i){if(i.indexOf(" > eval")>-1&&(i=i.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),i.indexOf("@")===-1&&i.indexOf(":")===-1)return new t({functionName:i});var l=/((.*".+"[^@]*)?[^@]*)(?:@)/,d=i.match(l),p=d&&d[1]?d[1]:void 0,f=this.extractLocation(i.replace(l,""));return new t({functionName:p,fileName:f[0],lineNumber:f[1],columnNumber:f[2],source:i})},this)},"ErrorStackParser$$parseFFOrSafari"),parseOpera:m(function(n){return!n.stacktrace||n.message.indexOf(`
|
|
4
4
|
`)>-1&&n.message.split(`
|
|
5
5
|
`).length>n.stacktrace.split(`
|
|
6
|
-
`).length?this.parseOpera9(n):n.stack?this.parseOpera11(n):this.parseOpera10(n)},"ErrorStackParser$$parseOpera"),parseOpera9:
|
|
7
|
-
`),l=[],d=2,p=i.length;d<p;d+=2){var
|
|
8
|
-
`),l=[],d=0,p=i.length;d<p;d+=2){var
|
|
9
|
-
`).filter(function(i){return!!i.match(o)&&!i.match(/^Error created at/)},this);return u.map(function(i){var l=i.split("@"),d=this.extractLocation(l.pop()),p=l.shift()||"",m=p.replace(/<anonymous function(: (\w+))?>/,"$2").replace(/\([^)]*\)/g,"")||void 0,c;p.match(/\(([^)]*)\)/)&&(c=p.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var y=c===void 0||c==="[arguments not available]"?void 0:c.split(",");return new t({functionName:m,args:y,fileName:d[0],lineNumber:d[1],columnNumber:d[2],source:i})},this)},"ErrorStackParser$$parseOpera11")}},"ErrorStackParser"))});var be={};ie(be,{loadPyodide:()=>D,version:()=>b});var q=h(H());var E=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&typeof process.browser=="undefined",A,F,R,I,B;async function z(){if(!E||(A=(await import("url")).default,B=await import("fs/promises"),globalThis.fetch?F=fetch:F=(await import("node-fetch")).default,I=(await import("vm")).default,R=await import("path"),x=R.sep,typeof g!="undefined"))return;let e=await import("fs"),t=await import("crypto"),o=await import("ws"),s=await import("child_process"),a={fs:e,crypto:t,ws:o,child_process:s};globalThis.require=function(r){return a[r]}}f(z,"initNodeModules");function ae(e,t){return R.resolve(t||".",e)}f(ae,"node_resolvePath");function se(e,t){return t===void 0&&(t=location),new URL(e,t).toString()}f(se,"browser_resolvePath");var k;E?k=ae:k=se;var x;E||(x="/");async function le(e,t){if(e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")){let o=await F(e);if(!o.ok)throw new Error(`Failed to load '${e}': request failed.`);return new Uint8Array(await o.arrayBuffer())}else{let o=await B.readFile(e);return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}}f(le,"node_loadBinaryFile");async function de(e,t){let o=new URL(e,location),a=await fetch(o,t?{integrity:t}:{});if(!a.ok)throw new Error(`Failed to load '${o}': request failed.`);return new Uint8Array(await a.arrayBuffer())}f(de,"browser_loadBinaryFile");var P;E?P=le:P=de;var S;if(globalThis.document)S=f(async e=>await import(e),"loadScript");else if(globalThis.importScripts)S=f(async e=>{try{globalThis.importScripts(e)}catch(t){if(t instanceof TypeError)await import(e);else throw t}},"loadScript");else if(E)S=ce;else throw new Error("Cannot determine runtime environment");async function ce(e){e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")?I.runInThisContext(await(await F(e)).text()):await import(A.pathToFileURL(e).href)}f(ce,"nodeLoadScript");function W(e){let t=e.FS,o=e.FS.filesystems.MEMFS,s=e.PATH,a={DIR_MODE:16895,FILE_MODE:33279,mount:function(r){if(!r.opts.fileSystemHandle)throw new Error("opts.fileSystemHandle is required");return o.mount.apply(null,arguments)},syncfs:async(r,n,u)=>{try{let i=a.getLocalSet(r),l=await a.getRemoteSet(r),d=n?l:i,p=n?i:l;await a.reconcile(r,d,p),u(null)}catch(i){u(i)}},getLocalSet:r=>{let n=Object.create(null);function u(d){return d!=="."&&d!==".."}f(u,"isRealDir");function i(d){return p=>s.join2(d,p)}f(i,"toAbsolute");let l=t.readdir(r.mountpoint).filter(u).map(i(r.mountpoint));for(;l.length;){let d=l.pop(),p=t.stat(d);t.isDir(p.mode)&&l.push.apply(l,t.readdir(d).filter(u).map(i(d))),n[d]={timestamp:p.mtime,mode:p.mode}}return{type:"local",entries:n}},getRemoteSet:async r=>{let n=Object.create(null),u=await ue(r.opts.fileSystemHandle);for(let[i,l]of u)i!=="."&&(n[s.join2(r.mountpoint,i)]={timestamp:l.kind==="file"?(await l.getFile()).lastModifiedDate:new Date,mode:l.kind==="file"?a.FILE_MODE:a.DIR_MODE});return{type:"remote",entries:n,handles:u}},loadLocalEntry:r=>{let u=t.lookupPath(r).node,i=t.stat(r);if(t.isDir(i.mode))return{timestamp:i.mtime,mode:i.mode};if(t.isFile(i.mode))return u.contents=o.getFileDataAsTypedArray(u),{timestamp:i.mtime,mode:i.mode,contents:u.contents};throw new Error("node type not supported")},storeLocalEntry:(r,n)=>{if(t.isDir(n.mode))t.mkdirTree(r,n.mode);else if(t.isFile(n.mode))t.writeFile(r,n.contents,{canOwn:!0});else throw new Error("node type not supported");t.chmod(r,n.mode),t.utime(r,n.timestamp,n.timestamp)},removeLocalEntry:r=>{var n=t.stat(r);t.isDir(n.mode)?t.rmdir(r):t.isFile(n.mode)&&t.unlink(r)},loadRemoteEntry:async r=>{if(r.kind==="file"){let n=await r.getFile();return{contents:new Uint8Array(await n.arrayBuffer()),mode:a.FILE_MODE,timestamp:n.lastModifiedDate}}else{if(r.kind==="directory")return{mode:a.DIR_MODE,timestamp:new Date};throw new Error("unknown kind: "+r.kind)}},storeRemoteEntry:async(r,n,u)=>{let i=r.get(s.dirname(n)),l=t.isFile(u.mode)?await i.getFileHandle(s.basename(n),{create:!0}):await i.getDirectoryHandle(s.basename(n),{create:!0});if(l.kind==="file"){let d=await l.createWritable();await d.write(u.contents),await d.close()}r.set(n,l)},removeRemoteEntry:async(r,n)=>{await r.get(s.dirname(n)).removeEntry(s.basename(n)),r.delete(n)},reconcile:async(r,n,u)=>{let i=0,l=[];Object.keys(n.entries).forEach(function(m){let c=n.entries[m],y=u.entries[m];(!y||t.isFile(c.mode)&&c.timestamp.getTime()>y.timestamp.getTime())&&(l.push(m),i++)}),l.sort();let d=[];if(Object.keys(u.entries).forEach(function(m){n.entries[m]||(d.push(m),i++)}),d.sort().reverse(),!i)return;let p=n.type==="remote"?n.handles:u.handles;for(let m of l){let c=s.normalize(m.replace(r.mountpoint,"/")).substring(1);if(u.type==="local"){let y=p.get(c),v=await a.loadRemoteEntry(y);a.storeLocalEntry(m,v)}else{let y=a.loadLocalEntry(m);await a.storeRemoteEntry(p,c,y)}}for(let m of d)if(u.type==="local")a.removeLocalEntry(m);else{let c=s.normalize(m.replace(r.mountpoint,"/")).substring(1);await a.removeRemoteEntry(p,c)}}};e.FS.filesystems.NATIVEFS_ASYNC=a}f(W,"initializeNativeFS");var ue=f(async e=>{let t=[];async function o(a){for await(let r of a.values())t.push(r),r.kind==="directory"&&await o(r)}f(o,"collect"),await o(e);let s=new Map;s.set(".",e);for(let a of t){let r=(await e.resolve(a)).join("/");s.set(r,a)}return s},"getFsHandles");function G(){let e={};return e.noImageDecoding=!0,e.noAudioDecoding=!0,e.noWasmDecoding=!1,e.preRun=[],e.quit=(t,o)=>{throw e.exited={status:t,toThrow:o},o},e}f(G,"createModule");function fe(e,t){e.preRun.push(function(){let o="/";try{e.FS.mkdirTree(t)}catch(s){console.error(`Error occurred while making a home directory '${t}':`),console.error(s),console.error(`Using '${o}' for a home directory instead`),t=o}e.FS.chdir(t)})}f(fe,"createHomeDirectory");function pe(e,t){e.preRun.push(function(){Object.assign(e.ENV,t)})}f(pe,"setEnvironment");function me(e,t){e.preRun.push(()=>{for(let o of t)e.FS.mkdirTree(o),e.FS.mount(e.FS.filesystems.NODEFS,{root:o},o)})}f(me,"mountLocalDirectories");function ye(e,t){let o=P(t);e.preRun.push(()=>{let s=e._py_version_major(),a=e._py_version_minor();e.FS.mkdirTree("/lib"),e.FS.mkdirTree(`/lib/python${s}.${a}/site-packages`),e.addRunDependency("install-stdlib"),o.then(r=>{e.FS.writeFile(`/lib/python${s}${a}.zip`,r)}).catch(r=>{console.error("Error occurred while installing the standard library:"),console.error(r)}).finally(()=>{e.removeRunDependency("install-stdlib")})})}f(ye,"installStdlib");function V(e,t){let o;t.stdLibURL!=null?o=t.stdLibURL:o=t.indexURL+"python_stdlib.zip",ye(e,o),fe(e,t.env.HOME),pe(e,t.env),me(e,t._node_mounts),e.preRun.push(()=>W(e))}f(V,"initializeFileSystem");var b="0.24.0a1";function ge(e,t){return new Proxy(e,{get(o,s){return s==="get"?a=>{let r=o.get(a);return r===void 0&&(r=t.get(a)),r}:s==="has"?a=>o.has(a)||t.has(a):Reflect.get(o,s)}})}f(ge,"wrapPythonGlobals");function he(e,t){e.runPythonInternal_dict=e._pyodide._base.eval_code("{}"),e.importlib=e.runPythonInternal("import importlib; importlib");let o=e.importlib.import_module;e.sys=o("sys"),e.sys.path.insert(0,t.env.HOME),e.os=o("os");let s=e.runPythonInternal("import __main__; __main__.__dict__"),a=e.runPythonInternal("import builtins; builtins.__dict__");e.globals=ge(s,a);let r=e._pyodide._importhook;function n(i){"__all__"in i||Object.defineProperty(i,"__all__",{get:()=>u.toPy(Object.getOwnPropertyNames(i).filter(l=>l!=="__all__")),enumerable:!1,configurable:!0})}f(n,"jsFinderHook"),r.register_js_finder.callKwargs({hook:n}),r.register_js_module("js",t.jsglobals);let u=e.makePublicAPI();return r.register_js_module("pyodide_js",u),e.pyodide_py=o("pyodide"),e.pyodide_code=o("pyodide.code"),e.pyodide_ffi=o("pyodide.ffi"),e.package_loader=o("pyodide._package_loader"),e.sitepackages=e.package_loader.SITE_PACKAGES.__str__(),e.dsodir=e.package_loader.DSO_DIR.__str__(),e.defaultLdLibraryPath=[e.dsodir,e.sitepackages],e.os.environ.__setitem__("LD_LIBRARY_PATH",e.defaultLdLibraryPath.join(":")),u.pyodide_py=e.pyodide_py,u.globals=e.globals,u}f(he,"finalizeBootstrap");function ve(){if(typeof __dirname=="string")return __dirname;let e;try{throw new Error}catch(s){e=s}let t=q.default.parse(e)[0].fileName,o=t.lastIndexOf(x);if(o===-1)throw new Error("Could not extract indexURL path from pyodide module location");return t.slice(0,o)}f(ve,"calculateIndexURL");async function D(e={}){await z();let t=e.indexURL||ve();t=k(t),t.endsWith("/")||(t+="/"),e.indexURL=t;let o={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:t+"pyodide-lock.json",args:[],_node_mounts:[],env:{},packageCacheDir:t},s=Object.assign(o,e);if(e.homedir){if(console.warn("The homedir argument to loadPyodide is deprecated. Use 'env: { HOME: value }' instead of 'homedir: value'."),e.env&&e.env.HOME)throw new Error("Set both env.HOME and homedir arguments");s.env.HOME=s.homedir}s.env.HOME||(s.env.HOME="/home/pyodide");let a=G();a.print=s.stdout,a.printErr=s.stderr,a.arguments=s.args;let r={config:s};a.API=r,V(a,s);let n=new Promise(p=>a.postRun=p);if(a.locateFile=p=>s.indexURL+p,typeof _createPyodideModule!="function"){let p=`${s.indexURL}pyodide.asm.js`;await S(p)}if(await _createPyodideModule(a),await n,a.exited)throw a.exited.toThrow;if(r.version!==b)throw new Error(`Pyodide version does not match: '${b}' <==> '${r.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);a.locateFile=p=>{throw new Error("Didn't expect to load any more file_packager files!")};let[u,i]=r.rawRun("import _pyodide_core");u&&a.API.fatal_loading_error(`Failed to import _pyodide_core
|
|
10
|
-
`,
|
|
6
|
+
`).length?this.parseOpera9(n):n.stack?this.parseOpera11(n):this.parseOpera10(n)},"ErrorStackParser$$parseOpera"),parseOpera9:m(function(n){for(var c=/Line (\d+).*script (?:in )?(\S+)/i,i=n.message.split(`
|
|
7
|
+
`),l=[],d=2,p=i.length;d<p;d+=2){var f=c.exec(i[d]);f&&l.push(new t({fileName:f[2],lineNumber:f[1],source:i[d]}))}return l},"ErrorStackParser$$parseOpera9"),parseOpera10:m(function(n){for(var c=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,i=n.stacktrace.split(`
|
|
8
|
+
`),l=[],d=0,p=i.length;d<p;d+=2){var f=c.exec(i[d]);f&&l.push(new t({functionName:f[3]||void 0,fileName:f[2],lineNumber:f[1],source:i[d]}))}return l},"ErrorStackParser$$parseOpera10"),parseOpera11:m(function(n){var c=n.stack.split(`
|
|
9
|
+
`).filter(function(i){return!!i.match(a)&&!i.match(/^Error created at/)},this);return c.map(function(i){var l=i.split("@"),d=this.extractLocation(l.pop()),p=l.shift()||"",f=p.replace(/<anonymous function(: (\w+))?>/,"$2").replace(/\([^)]*\)/g,"")||void 0,u;p.match(/\(([^)]*)\)/)&&(u=p.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var y=u===void 0||u==="[arguments not available]"?void 0:u.split(",");return new t({functionName:f,args:y,fileName:d[0],lineNumber:d[1],columnNumber:d[2],source:i})},this)},"ErrorStackParser$$parseOpera11")}},"ErrorStackParser"))});var we={};ae(we,{loadPyodide:()=>T,version:()=>v});var X=b(A());var k=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&typeof process.browser=="undefined",B,F,L,W,H;async function I(){if(!k||(B=(await import("url")).default,H=await import("fs/promises"),globalThis.fetch?F=fetch:F=(await import("node-fetch")).default,W=(await import("vm")).default,L=await import("path"),x=L.sep,typeof g!="undefined"))return;let e=await import("fs"),t=await import("crypto"),a=await import("ws"),s=await import("child_process"),o={fs:e,crypto:t,ws:a,child_process:s};globalThis.require=function(r){return o[r]}}m(I,"initNodeModules");function le(e,t){return L.resolve(t||".",e)}m(le,"node_resolvePath");function de(e,t){return t===void 0&&(t=location),new URL(e,t).toString()}m(de,"browser_resolvePath");var P;k?P=le:P=de;var x;k||(x="/");function ce(e,t){return e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")?{response:F(e)}:{binary:H.readFile(e).then(a=>new Uint8Array(a.buffer,a.byteOffset,a.byteLength))}}m(ce,"node_getBinaryResponse");function ue(e,t){let a=new URL(e,location);return{response:fetch(a,t?{integrity:t}:{})}}m(ue,"browser_getBinaryResponse");var E;k?E=ce:E=ue;async function z(e,t){let{response:a,binary:s}=E(e,t);if(s)return s;let o=await a;if(!o.ok)throw new Error(`Failed to load '${e}': request failed.`);return new Uint8Array(await o.arrayBuffer())}m(z,"loadBinaryFile");var S;if(globalThis.document)S=m(async e=>await import(e),"loadScript");else if(globalThis.importScripts)S=m(async e=>{try{globalThis.importScripts(e)}catch(t){if(t instanceof TypeError)await import(e);else throw t}},"loadScript");else if(k)S=fe;else throw new Error("Cannot determine runtime environment");async function fe(e){e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")?W.runInThisContext(await(await F(e)).text()):await import(B.pathToFileURL(e).href)}m(fe,"nodeLoadScript");function G(e){let t=e.FS,a=e.FS.filesystems.MEMFS,s=e.PATH,o={DIR_MODE:16895,FILE_MODE:33279,mount:function(r){if(!r.opts.fileSystemHandle)throw new Error("opts.fileSystemHandle is required");return a.mount.apply(null,arguments)},syncfs:async(r,n,c)=>{try{let i=o.getLocalSet(r),l=await o.getRemoteSet(r),d=n?l:i,p=n?i:l;await o.reconcile(r,d,p),c(null)}catch(i){c(i)}},getLocalSet:r=>{let n=Object.create(null);function c(d){return d!=="."&&d!==".."}m(c,"isRealDir");function i(d){return p=>s.join2(d,p)}m(i,"toAbsolute");let l=t.readdir(r.mountpoint).filter(c).map(i(r.mountpoint));for(;l.length;){let d=l.pop(),p=t.stat(d);t.isDir(p.mode)&&l.push.apply(l,t.readdir(d).filter(c).map(i(d))),n[d]={timestamp:p.mtime,mode:p.mode}}return{type:"local",entries:n}},getRemoteSet:async r=>{let n=Object.create(null),c=await me(r.opts.fileSystemHandle);for(let[i,l]of c)i!=="."&&(n[s.join2(r.mountpoint,i)]={timestamp:l.kind==="file"?(await l.getFile()).lastModifiedDate:new Date,mode:l.kind==="file"?o.FILE_MODE:o.DIR_MODE});return{type:"remote",entries:n,handles:c}},loadLocalEntry:r=>{let c=t.lookupPath(r).node,i=t.stat(r);if(t.isDir(i.mode))return{timestamp:i.mtime,mode:i.mode};if(t.isFile(i.mode))return c.contents=a.getFileDataAsTypedArray(c),{timestamp:i.mtime,mode:i.mode,contents:c.contents};throw new Error("node type not supported")},storeLocalEntry:(r,n)=>{if(t.isDir(n.mode))t.mkdirTree(r,n.mode);else if(t.isFile(n.mode))t.writeFile(r,n.contents,{canOwn:!0});else throw new Error("node type not supported");t.chmod(r,n.mode),t.utime(r,n.timestamp,n.timestamp)},removeLocalEntry:r=>{var n=t.stat(r);t.isDir(n.mode)?t.rmdir(r):t.isFile(n.mode)&&t.unlink(r)},loadRemoteEntry:async r=>{if(r.kind==="file"){let n=await r.getFile();return{contents:new Uint8Array(await n.arrayBuffer()),mode:o.FILE_MODE,timestamp:n.lastModifiedDate}}else{if(r.kind==="directory")return{mode:o.DIR_MODE,timestamp:new Date};throw new Error("unknown kind: "+r.kind)}},storeRemoteEntry:async(r,n,c)=>{let i=r.get(s.dirname(n)),l=t.isFile(c.mode)?await i.getFileHandle(s.basename(n),{create:!0}):await i.getDirectoryHandle(s.basename(n),{create:!0});if(l.kind==="file"){let d=await l.createWritable();await d.write(c.contents),await d.close()}r.set(n,l)},removeRemoteEntry:async(r,n)=>{await r.get(s.dirname(n)).removeEntry(s.basename(n)),r.delete(n)},reconcile:async(r,n,c)=>{let i=0,l=[];Object.keys(n.entries).forEach(function(f){let u=n.entries[f],y=c.entries[f];(!y||t.isFile(u.mode)&&u.timestamp.getTime()>y.timestamp.getTime())&&(l.push(f),i++)}),l.sort();let d=[];if(Object.keys(c.entries).forEach(function(f){n.entries[f]||(d.push(f),i++)}),d.sort().reverse(),!i)return;let p=n.type==="remote"?n.handles:c.handles;for(let f of l){let u=s.normalize(f.replace(r.mountpoint,"/")).substring(1);if(c.type==="local"){let y=p.get(u),h=await o.loadRemoteEntry(y);o.storeLocalEntry(f,h)}else{let y=o.loadLocalEntry(f);await o.storeRemoteEntry(p,u,y)}}for(let f of d)if(c.type==="local")o.removeLocalEntry(f);else{let u=s.normalize(f.replace(r.mountpoint,"/")).substring(1);await o.removeRemoteEntry(p,u)}}};e.FS.filesystems.NATIVEFS_ASYNC=o}m(G,"initializeNativeFS");var me=m(async e=>{let t=[];async function a(o){for await(let r of o.values())t.push(r),r.kind==="directory"&&await a(r)}m(a,"collect"),await a(e);let s=new Map;s.set(".",e);for(let o of t){let r=(await e.resolve(o)).join("/");s.set(r,o)}return s},"getFsHandles");function V(){let e={};return e.noImageDecoding=!0,e.noAudioDecoding=!0,e.noWasmDecoding=!1,e.preRun=[],e.quit=(t,a)=>{throw e.exited={status:t,toThrow:a},a},e}m(V,"createModule");function pe(e,t){e.preRun.push(function(){let a="/";try{e.FS.mkdirTree(t)}catch(s){console.error(`Error occurred while making a home directory '${t}':`),console.error(s),console.error(`Using '${a}' for a home directory instead`),t=a}e.FS.chdir(t)})}m(pe,"createHomeDirectory");function ye(e,t){e.preRun.push(function(){Object.assign(e.ENV,t)})}m(ye,"setEnvironment");function ge(e,t){e.preRun.push(()=>{for(let a of t)e.FS.mkdirTree(a),e.FS.mount(e.FS.filesystems.NODEFS,{root:a},a)})}m(ge,"mountLocalDirectories");function be(e,t){let a=z(t);e.preRun.push(()=>{let s=e._py_version_major(),o=e._py_version_minor();e.FS.mkdirTree("/lib"),e.FS.mkdirTree(`/lib/python${s}.${o}/site-packages`),e.addRunDependency("install-stdlib"),a.then(r=>{e.FS.writeFile(`/lib/python${s}${o}.zip`,r)}).catch(r=>{console.error("Error occurred while installing the standard library:"),console.error(r)}).finally(()=>{e.removeRunDependency("install-stdlib")})})}m(be,"installStdlib");function q(e,t){let a;t.stdLibURL!=null?a=t.stdLibURL:a=t.indexURL+"python_stdlib.zip",be(e,a),pe(e,t.env.HOME),ye(e,t.env),ge(e,t._node_mounts),e.preRun.push(()=>G(e))}m(q,"initializeFileSystem");function K(e,t){let{binary:a,response:s}=E(t+"pyodide.asm.wasm");e.instantiateWasm=function(o,r){return async function(){try{let n;s?n=await WebAssembly.instantiateStreaming(s,o):n=await WebAssembly.instantiate(await a,o);let{instance:c,module:i}=n;typeof WasmOffsetConverter!="undefined"&&(wasmOffsetConverter=new WasmOffsetConverter(wasmBinary,i)),r(c,i)}catch(n){console.warn("wasm instantiation failed!"),console.warn(n)}}(),{}}}m(K,"preloadWasm");var v="0.24.1";function he(e,t){return new Proxy(e,{get(a,s){return s==="get"?o=>{let r=a.get(o);return r===void 0&&(r=t.get(o)),r}:s==="has"?o=>a.has(o)||t.has(o):Reflect.get(a,s)}})}m(he,"wrapPythonGlobals");function ve(e,t){e.runPythonInternal_dict=e._pyodide._base.eval_code("{}"),e.importlib=e.runPythonInternal("import importlib; importlib");let a=e.importlib.import_module;e.sys=a("sys"),e.sys.path.insert(0,t.env.HOME),e.os=a("os");let s=e.runPythonInternal("import __main__; __main__.__dict__"),o=e.runPythonInternal("import builtins; builtins.__dict__");e.globals=he(s,o);let r=e._pyodide._importhook;function n(i){"__all__"in i||Object.defineProperty(i,"__all__",{get:()=>c.toPy(Object.getOwnPropertyNames(i).filter(l=>l!=="__all__")),enumerable:!1,configurable:!0})}m(n,"jsFinderHook"),r.register_js_finder.callKwargs({hook:n}),r.register_js_module("js",t.jsglobals);let c=e.makePublicAPI();return r.register_js_module("pyodide_js",c),e.pyodide_py=a("pyodide"),e.pyodide_code=a("pyodide.code"),e.pyodide_ffi=a("pyodide.ffi"),e.package_loader=a("pyodide._package_loader"),e.sitepackages=e.package_loader.SITE_PACKAGES.__str__(),e.dsodir=e.package_loader.DSO_DIR.__str__(),e.defaultLdLibraryPath=[e.dsodir,e.sitepackages],e.os.environ.__setitem__("LD_LIBRARY_PATH",e.defaultLdLibraryPath.join(":")),c.pyodide_py=e.pyodide_py,c.globals=e.globals,c}m(ve,"finalizeBootstrap");function _e(){if(typeof __dirname=="string")return __dirname;let e;try{throw new Error}catch(s){e=s}let t=X.default.parse(e)[0].fileName,a=t.lastIndexOf(x);if(a===-1)throw new Error("Could not extract indexURL path from pyodide module location");return t.slice(0,a)}m(_e,"calculateIndexURL");async function T(e={}){await I();let t=e.indexURL||_e();t=P(t),t.endsWith("/")||(t+="/"),e.indexURL=t;let a={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:t+"pyodide-lock.json",args:[],_node_mounts:[],env:{},packageCacheDir:t,packages:[]},s=Object.assign(a,e);if(e.homedir){if(console.warn("The homedir argument to loadPyodide is deprecated. Use 'env: { HOME: value }' instead of 'homedir: value'."),e.env&&e.env.HOME)throw new Error("Set both env.HOME and homedir arguments");s.env.HOME=s.homedir}s.env.HOME||(s.env.HOME="/home/pyodide");let o=V();o.print=s.stdout,o.printErr=s.stderr,o.arguments=s.args;let r={config:s};o.API=r,K(o,t),q(o,s);let n=new Promise(f=>o.postRun=f),c;if(r.bootstrapFinalizedPromise=new Promise(f=>c=f),o.locateFile=f=>s.indexURL+f,typeof _createPyodideModule!="function"){let f=`${s.indexURL}pyodide.asm.js`;await S(f)}if(await _createPyodideModule(o),await n,o.exited)throw o.exited.toThrow;if(r.version!==v)throw new Error(`Pyodide version does not match: '${v}' <==> '${r.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);o.locateFile=f=>{throw new Error("Didn't expect to load any more file_packager files!")};let[i,l]=r.rawRun("import _pyodide_core");i&&o.API.fatal_loading_error(`Failed to import _pyodide_core
|
|
10
|
+
`,l);let d=ve(r,s);if(c(),d.version.includes("dev")||r.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${d.version}/full/`),await r.packageIndexReady,r._pyodide._importhook.register_module_not_found_hook(r._import_name_to_package_name,r.lockfile_unvendored_stdlibs_and_test),r.lockfile_info.version!==v)throw new Error("Lock file version doesn't match Pyodide version");return r.package_loader.init_loaded_packages(),s.fullStdLib&&await d.loadPackage(r.lockfile_unvendored_stdlibs),r.initializeStreams(s.stdin,s.stdout,s.stderr),d}m(T,"loadPyodide");globalThis.loadPyodide=T;return se(we);})();
|
|
11
11
|
try{Object.assign(exports,loadPyodide)}catch(_){}
|
|
12
12
|
globalThis.loadPyodide=loadPyodide.loadPyodide;
|
|
13
13
|
//# sourceMappingURL=pyodide.js.map
|