From 3d1e2ef8aa3e3955fba5dea0cc1125a643efdbc1 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 24 Jul 2024 16:39:02 -0500 Subject: [PATCH] Update to Pyodide 0.26.1 --- Makefile | 2 +- src/pyodide/pyodide.d.ts | 5 +++++ src/pyodide/pyodide.js | 18 +++++++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 080506bf..e334566d 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SHINYLIVE_VERSION = $(shell node -p "require('./package.json').version") -PYODIDE_VERSION = 0.26.0 +PYODIDE_VERSION = 0.26.1 PYODIDE_DIST_FILENAME = pyodide-$(PYODIDE_VERSION).tar.bz2 DOWNLOAD_DIR = ./downloads R_SHINY_VERSION = 1.8.1.8001-webr diff --git a/src/pyodide/pyodide.d.ts b/src/pyodide/pyodide.d.ts index 106b31b0..9afcebdc 100644 --- a/src/pyodide/pyodide.d.ts +++ b/src/pyodide/pyodide.d.ts @@ -1410,6 +1410,7 @@ type ConfigType = { }; packages: string[]; _makeSnapshot: boolean; + enableRunUntilComplete: boolean; }; /** * Load the main Pyodide wasm module and initialize it. @@ -1527,6 +1528,10 @@ export declare function loadPyodide(options?: { * @deprecated */ pyproxyToStringRepr?: boolean; + /** + * Make loop.run_until_complete() function correctly using stack switching + */ + enableRunUntilComplete?: boolean; /** * @ignore */ diff --git a/src/pyodide/pyodide.js b/src/pyodide/pyodide.js index 4dcbf464..cc9d0fe0 100644 --- a/src/pyodide/pyodide.js +++ b/src/pyodide/pyodide.js @@ -1,10 +1,10 @@ -var ne=Object.create;var O=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var f=(t,e)=>O(t,"name",{value:e,configurable:!0}),w=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ce=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of oe(e))!ae.call(t,l)&&l!==o&&O(t,l,{get:()=>e[l],enumerable:!(s=ie(e,l))||s.enumerable});return t};var le=(t,e,o)=>(o=t!=null?ne(se(t)):{},ce(e||!t||!t.__esModule?O(o,"default",{value:t,enumerable:!0}):o,t));var M=D((R,T)=>{(function(t,e){"use strict";typeof define=="function"&&define.amd?define("stackframe",[],e):typeof R=="object"?T.exports=e():t.StackFrame=e()})(R,function(){"use strict";function t(d){return!isNaN(parseFloat(d))&&isFinite(d)}f(t,"_isNumber");function e(d){return d.charAt(0).toUpperCase()+d.substring(1)}f(e,"_capitalize");function o(d){return function(){return this[d]}}f(o,"_getter");var s=["isConstructor","isEval","isNative","isToplevel"],l=["columnNumber","lineNumber"],r=["fileName","functionName","source"],n=["args"],u=["evalOrigin"],i=s.concat(l,r,n,u);function c(d){if(d)for(var y=0;y{(function(t,e){"use strict";typeof define=="function"&&define.amd?define("error-stack-parser",["stackframe"],e):typeof N=="object"?U.exports=e(M()):t.ErrorStackParser=e(t.StackFrame)})(N,f(function(e){"use strict";var o=/(^|@)\S+:\d+/,s=/^\s*at .*(\S+:\d+|\(native\))/m,l=/^(eval@)?(\[native code])?$/;return{parse:f(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:f(function(n){if(n.indexOf(":")===-1)return[n];var u=/(.+?)(?::(\d+))?(?::(\d+))?$/,i=u.exec(n.replace(/[()]/g,""));return[i[1],i[2]||void 0,i[3]||void 0]},"ErrorStackParser$$extractLocation"),parseV8OrIE:f(function(n){var u=n.stack.split(` -`).filter(function(i){return!!i.match(s)},this);return u.map(function(i){i.indexOf("(eval ")>-1&&(i=i.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var c=i.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),a=c.match(/ (\(.+\)$)/);c=a?c.replace(a[0],""):c;var m=this.extractLocation(a?a[1]:c),p=a&&c||void 0,d=["eval",""].indexOf(m[0])>-1?void 0:m[0];return new e({functionName:p,fileName:d,lineNumber:m[1],columnNumber:m[2],source:i})},this)},"ErrorStackParser$$parseV8OrIE"),parseFFOrSafari:f(function(n){var u=n.stack.split(` -`).filter(function(i){return!i.match(l)},this);return u.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 e({functionName:i});var c=/((.*".+"[^@]*)?[^@]*)(?:@)/,a=i.match(c),m=a&&a[1]?a[1]:void 0,p=this.extractLocation(i.replace(c,""));return new e({functionName:m,fileName:p[0],lineNumber:p[1],columnNumber:p[2],source:i})},this)},"ErrorStackParser$$parseFFOrSafari"),parseOpera:f(function(n){return!n.stacktrace||n.message.indexOf(` -`)>-1&&n.message.split(` -`).length>n.stacktrace.split(` -`).length?this.parseOpera9(n):n.stack?this.parseOpera11(n):this.parseOpera10(n)},"ErrorStackParser$$parseOpera"),parseOpera9:f(function(n){for(var u=/Line (\d+).*script (?:in )?(\S+)/i,i=n.message.split(` -`),c=[],a=2,m=i.length;a/,"$2").replace(/\([^)]*\)/g,"")||void 0,d;m.match(/\(([^)]*)\)/)&&(d=m.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var y=d===void 0||d==="[arguments not available]"?void 0:d.split(",");return new e({functionName:p,args:y,fileName:a[0],lineNumber:a[1],columnNumber:a[2],source:i})},this)},"ErrorStackParser$$parseOpera11")}},"ErrorStackParser"))});var z=le($());var g=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&typeof process.browser>"u",F=g&&typeof module<"u"&&typeof module.exports<"u"&&typeof w<"u"&&typeof __dirname<"u",C=g&&!F,de=typeof Deno<"u",W=!g&&!de,j=W&&typeof window=="object"&&typeof document=="object"&&typeof document.createElement=="function"&&typeof sessionStorage=="object"&&typeof importScripts!="function",B=W&&typeof importScripts=="function"&&typeof self=="object",Ne=typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Chrome")==-1&&navigator.userAgent.indexOf("Safari")>-1;var q,P,V,H,x;async function I(){if(!g||(q=(await import("node:url")).default,H=await import("node:fs"),x=await import("node:fs/promises"),V=(await import("node:vm")).default,P=await import("node:path"),k=P.sep,typeof w<"u"))return;let t=H,e=await import("node:crypto"),o=await import("ws"),s=await import("node:child_process"),l={fs:t,crypto:e,ws:o,child_process:s};globalThis.require=function(r){return l[r]}}f(I,"initNodeModules");function fe(t,e){return P.resolve(e||".",t)}f(fe,"node_resolvePath");function ue(t,e){return e===void 0&&(e=location),new URL(t,e).toString()}f(ue,"browser_resolvePath");var S;g?S=fe:S=ue;var k;g||(k="/");function pe(t,e){return t.startsWith("file://")&&(t=t.slice(7)),t.includes("://")?{response:fetch(t)}:{binary:x.readFile(t).then(o=>new Uint8Array(o.buffer,o.byteOffset,o.byteLength))}}f(pe,"node_getBinaryResponse");function me(t,e){let o=new URL(t,location);return{response:fetch(o,e?{integrity:e}:{})}}f(me,"browser_getBinaryResponse");var b;g?b=pe:b=me;async function K(t,e){let{response:o,binary:s}=b(t,e);if(s)return s;let l=await o;if(!l.ok)throw new Error(`Failed to load '${t}': request failed.`);return new Uint8Array(await l.arrayBuffer())}f(K,"loadBinaryFile");var E;if(j)E=f(async t=>await import(t),"loadScript");else if(B)E=f(async t=>{try{globalThis.importScripts(t)}catch(e){if(e instanceof TypeError)await import(t);else throw e}},"loadScript");else if(g)E=ye;else throw new Error("Cannot determine runtime environment");async function ye(t){t.startsWith("file://")&&(t=t.slice(7)),t.includes("://")?V.runInThisContext(await(await fetch(t)).text()):await import(q.pathToFileURL(t).href)}f(ye,"nodeLoadScript");async function J(t){if(g){await I();let e=await x.readFile(t,{encoding:"utf8"});return JSON.parse(e)}else return await(await fetch(t)).json()}f(J,"loadLockFile");async function X(){if(F)return __dirname;let t;try{throw new Error}catch(s){t=s}let e=z.default.parse(t)[0].fileName;if(C){let s=await import("node:path");return(await import("node:url")).fileURLToPath(s.dirname(e))}let o=e.lastIndexOf(k);if(o===-1)throw new Error("Could not extract indexURL path from pyodide module location");return e.slice(0,o)}f(X,"calculateDirname");function G(t){let e=t.FS,o=t.FS.filesystems.MEMFS,s=t.PATH,l={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=l.getLocalSet(r),c=await l.getRemoteSet(r),a=n?c:i,m=n?i:c;await l.reconcile(r,a,m),u(null)}catch(i){u(i)}},getLocalSet:r=>{let n=Object.create(null);function u(a){return a!=="."&&a!==".."}f(u,"isRealDir");function i(a){return m=>s.join2(a,m)}f(i,"toAbsolute");let c=e.readdir(r.mountpoint).filter(u).map(i(r.mountpoint));for(;c.length;){let a=c.pop(),m=e.stat(a);e.isDir(m.mode)&&c.push.apply(c,e.readdir(a).filter(u).map(i(a))),n[a]={timestamp:m.mtime,mode:m.mode}}return{type:"local",entries:n}},getRemoteSet:async r=>{let n=Object.create(null),u=await ge(r.opts.fileSystemHandle);for(let[i,c]of u)i!=="."&&(n[s.join2(r.mountpoint,i)]={timestamp:c.kind==="file"?(await c.getFile()).lastModifiedDate:new Date,mode:c.kind==="file"?l.FILE_MODE:l.DIR_MODE});return{type:"remote",entries:n,handles:u}},loadLocalEntry:r=>{let u=e.lookupPath(r).node,i=e.stat(r);if(e.isDir(i.mode))return{timestamp:i.mtime,mode:i.mode};if(e.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(e.isDir(n.mode))e.mkdirTree(r,n.mode);else if(e.isFile(n.mode))e.writeFile(r,n.contents,{canOwn:!0});else throw new Error("node type not supported");e.chmod(r,n.mode),e.utime(r,n.timestamp,n.timestamp)},removeLocalEntry:r=>{var n=e.stat(r);e.isDir(n.mode)?e.rmdir(r):e.isFile(n.mode)&&e.unlink(r)},loadRemoteEntry:async r=>{if(r.kind==="file"){let n=await r.getFile();return{contents:new Uint8Array(await n.arrayBuffer()),mode:l.FILE_MODE,timestamp:n.lastModifiedDate}}else{if(r.kind==="directory")return{mode:l.DIR_MODE,timestamp:new Date};throw new Error("unknown kind: "+r.kind)}},storeRemoteEntry:async(r,n,u)=>{let i=r.get(s.dirname(n)),c=e.isFile(u.mode)?await i.getFileHandle(s.basename(n),{create:!0}):await i.getDirectoryHandle(s.basename(n),{create:!0});if(c.kind==="file"){let a=await c.createWritable();await a.write(u.contents),await a.close()}r.set(n,c)},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,c=[];Object.keys(n.entries).forEach(function(p){let d=n.entries[p],y=u.entries[p];(!y||e.isFile(d.mode)&&d.timestamp.getTime()>y.timestamp.getTime())&&(c.push(p),i++)}),c.sort();let a=[];if(Object.keys(u.entries).forEach(function(p){n.entries[p]||(a.push(p),i++)}),a.sort().reverse(),!i)return;let m=n.type==="remote"?n.handles:u.handles;for(let p of c){let d=s.normalize(p.replace(r.mountpoint,"/")).substring(1);if(u.type==="local"){let y=m.get(d),h=await l.loadRemoteEntry(y);l.storeLocalEntry(p,h)}else{let y=l.loadLocalEntry(p);await l.storeRemoteEntry(m,d,y)}}for(let p of a)if(u.type==="local")l.removeLocalEntry(p);else{let d=s.normalize(p.replace(r.mountpoint,"/")).substring(1);await l.removeRemoteEntry(m,d)}}};t.FS.filesystems.NATIVEFS_ASYNC=l}f(G,"initializeNativeFS");var ge=f(async t=>{let e=[];async function o(l){for await(let r of l.values())e.push(r),r.kind==="directory"&&await o(r)}f(o,"collect"),await o(t);let s=new Map;s.set(".",t);for(let l of e){let r=(await t.resolve(l)).join("/");s.set(r,l)}return s},"getFsHandles");function Y(t){let e={noImageDecoding:!0,noAudioDecoding:!0,noWasmDecoding:!1,preRun:we(t),quit(o,s){throw e.exited={status:o,toThrow:s},s},print:t.stdout,printErr:t.stderr,arguments:t.args,API:{config:t},locateFile:o=>t.indexURL+o,instantiateWasm:Se(t.indexURL)};return e}f(Y,"createSettings");function he(t){return function(e){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(he,"createHomeDirectory");function ve(t){return function(e){Object.assign(e.ENV,t)}}f(ve,"setEnvironment");function Ee(t){return e=>{for(let o of t)e.FS.mkdirTree(o),e.FS.mount(e.FS.filesystems.NODEFS,{root:o},o)}}f(Ee,"mountLocalDirectories");function be(t){let e=K(t);return o=>{let s=o._py_version_major(),l=o._py_version_minor();o.FS.mkdirTree("/lib"),o.FS.mkdirTree(`/lib/python${s}.${l}/site-packages`),o.addRunDependency("install-stdlib"),e.then(r=>{o.FS.writeFile(`/lib/python${s}${l}.zip`,r)}).catch(r=>{console.error("Error occurred while installing the standard library:"),console.error(r)}).finally(()=>{o.removeRunDependency("install-stdlib")})}}f(be,"installStdlib");function we(t){let e;return t.stdLibURL!=null?e=t.stdLibURL:e=t.indexURL+"python_stdlib.zip",[be(e),he(t.env.HOME),ve(t.env),Ee(t._node_mounts),G]}f(we,"getFileSystemInitializationFuncs");function Se(t){let{binary:e,response:o}=b(t+"pyodide.asm.wasm");return function(s,l){return async function(){try{let r;o?r=await WebAssembly.instantiateStreaming(o,s):r=await WebAssembly.instantiate(await e,s);let{instance:n,module:u}=r;typeof WasmOffsetConverter<"u"&&(wasmOffsetConverter=new WasmOffsetConverter(wasmBinary,u)),l(n,u)}catch(r){console.warn("wasm instantiation failed!"),console.warn(r)}}(),{}}}f(Se,"getInstantiateWasmFunc");var A="0.26.0";async function Be(t={}){await I();let e=t.indexURL||await X();e=S(e),e.endsWith("/")||(e+="/"),t.indexURL=e;let o={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:e+"pyodide-lock.json",args:[],_node_mounts:[],env:{},packageCacheDir:e,packages:[]},s=Object.assign(o,t);s.env.HOME||(s.env.HOME="/home/pyodide");let l=Y(s),r=l.API;if(r.lockFilePromise=J(s.lockFileURL),typeof _createPyodideModule!="function"){let a=`${s.indexURL}pyodide.asm.js`;await E(a)}let n;if(t._loadSnapshot){let a=await t._loadSnapshot;ArrayBuffer.isView(a)?n=a:n=new Uint8Array(a),l.noInitialRun=!0,l.INITIAL_MEMORY=n.length}let u=await _createPyodideModule(l);if(l.exited)throw l.exited.toThrow;if(t.pyproxyToStringRepr&&r.setPyProxyToStringMethod(!0),r.version!==A)throw new Error(`Pyodide version does not match: '${A}' <==> '${r.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);u.locateFile=a=>{throw new Error("Didn't expect to load any more file_packager files!")};let i;n&&(i=r.restoreSnapshot(n));let c=r.finalizeBootstrap(i);return r.sys.path.insert(0,r.config.env.HOME),c.version.includes("dev")||r.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${c.version}/full/`),r._pyodide.set_excepthook(),await r.packageIndexReady,r.initializeStreams(s.stdin,s.stdout,s.stderr),c}f(Be,"loadPyodide");export{Be as loadPyodide,A as version}; +var re=Object.create;var R=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var f=(t,e)=>R(t,"name",{value:e,configurable:!0}),w=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ce=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of oe(e))!se.call(t,l)&&l!==o&&R(t,l,{get:()=>e[l],enumerable:!(a=ie(e,l))||a.enumerable});return t};var le=(t,e,o)=>(o=t!=null?re(ae(t)):{},ce(e||!t||!t.__esModule?R(o,"default",{value:t,enumerable:!0}):o,t));var T=D((O,U)=>{(function(t,e){"use strict";typeof define=="function"&&define.amd?define("stackframe",[],e):typeof O=="object"?U.exports=e():t.StackFrame=e()})(O,function(){"use strict";function t(d){return!isNaN(parseFloat(d))&&isFinite(d)}f(t,"_isNumber");function e(d){return d.charAt(0).toUpperCase()+d.substring(1)}f(e,"_capitalize");function o(d){return function(){return this[d]}}f(o,"_getter");var a=["isConstructor","isEval","isNative","isToplevel"],l=["columnNumber","lineNumber"],n=["fileName","functionName","source"],r=["args"],u=["evalOrigin"],i=a.concat(l,n,r,u);function c(d){if(d)for(var y=0;y{(function(t,e){"use strict";typeof define=="function"&&define.amd?define("error-stack-parser",["stackframe"],e):typeof N=="object"?M.exports=e(T()):t.ErrorStackParser=e(t.StackFrame)})(N,f(function(e){"use strict";var o=/(^|@)\S+:\d+/,a=/^\s*at .*(\S+:\d+|\(native\))/m,l=/^(eval@)?(\[native code])?$/;return{parse:f(function(r){if(typeof r.stacktrace<"u"||typeof r["opera#sourceloc"]<"u")return this.parseOpera(r);if(r.stack&&r.stack.match(a))return this.parseV8OrIE(r);if(r.stack)return this.parseFFOrSafari(r);throw new Error("Cannot parse given Error object")},"ErrorStackParser$$parse"),extractLocation:f(function(r){if(r.indexOf(":")===-1)return[r];var u=/(.+?)(?::(\d+))?(?::(\d+))?$/,i=u.exec(r.replace(/[()]/g,""));return[i[1],i[2]||void 0,i[3]||void 0]},"ErrorStackParser$$extractLocation"),parseV8OrIE:f(function(r){var u=r.stack.split(` +`).filter(function(i){return!!i.match(a)},this);return u.map(function(i){i.indexOf("(eval ")>-1&&(i=i.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var c=i.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),s=c.match(/ (\(.+\)$)/);c=s?c.replace(s[0],""):c;var m=this.extractLocation(s?s[1]:c),p=s&&c||void 0,d=["eval",""].indexOf(m[0])>-1?void 0:m[0];return new e({functionName:p,fileName:d,lineNumber:m[1],columnNumber:m[2],source:i})},this)},"ErrorStackParser$$parseV8OrIE"),parseFFOrSafari:f(function(r){var u=r.stack.split(` +`).filter(function(i){return!i.match(l)},this);return u.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 e({functionName:i});var c=/((.*".+"[^@]*)?[^@]*)(?:@)/,s=i.match(c),m=s&&s[1]?s[1]:void 0,p=this.extractLocation(i.replace(c,""));return new e({functionName:m,fileName:p[0],lineNumber:p[1],columnNumber:p[2],source:i})},this)},"ErrorStackParser$$parseFFOrSafari"),parseOpera:f(function(r){return!r.stacktrace||r.message.indexOf(` +`)>-1&&r.message.split(` +`).length>r.stacktrace.split(` +`).length?this.parseOpera9(r):r.stack?this.parseOpera11(r):this.parseOpera10(r)},"ErrorStackParser$$parseOpera"),parseOpera9:f(function(r){for(var u=/Line (\d+).*script (?:in )?(\S+)/i,i=r.message.split(` +`),c=[],s=2,m=i.length;s/,"$2").replace(/\([^)]*\)/g,"")||void 0,d;m.match(/\(([^)]*)\)/)&&(d=m.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var y=d===void 0||d==="[arguments not available]"?void 0:d.split(",");return new e({functionName:p,args:y,fileName:s[0],lineNumber:s[1],columnNumber:s[2],source:i})},this)},"ErrorStackParser$$parseOpera11")}},"ErrorStackParser"))});var z=le($());var g=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&typeof process.browser>"u",F=g&&typeof module<"u"&&typeof module.exports<"u"&&typeof w<"u"&&typeof __dirname<"u",C=g&&!F,de=typeof Deno<"u",W=!g&&!de,j=W&&typeof window=="object"&&typeof document=="object"&&typeof document.createElement=="function"&&typeof sessionStorage=="object"&&typeof importScripts!="function",B=W&&typeof importScripts=="function"&&typeof self=="object",Ne=typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Chrome")==-1&&navigator.userAgent.indexOf("Safari")>-1;var q,P,V,H,x;async function I(){if(!g||(q=(await import("node:url")).default,H=await import("node:fs"),x=await import("node:fs/promises"),V=(await import("node:vm")).default,P=await import("node:path"),k=P.sep,typeof w<"u"))return;let t=H,e=await import("node:crypto"),o=await import("ws"),a=await import("node:child_process"),l={fs:t,crypto:e,ws:o,child_process:a};globalThis.require=function(n){return l[n]}}f(I,"initNodeModules");function fe(t,e){return P.resolve(e||".",t)}f(fe,"node_resolvePath");function ue(t,e){return e===void 0&&(e=location),new URL(t,e).toString()}f(ue,"browser_resolvePath");var S;g?S=fe:S=ue;var k;g||(k="/");function pe(t,e){return t.startsWith("file://")&&(t=t.slice(7)),t.includes("://")?{response:fetch(t)}:{binary:x.readFile(t).then(o=>new Uint8Array(o.buffer,o.byteOffset,o.byteLength))}}f(pe,"node_getBinaryResponse");function me(t,e){let o=new URL(t,location);return{response:fetch(o,e?{integrity:e}:{})}}f(me,"browser_getBinaryResponse");var b;g?b=pe:b=me;async function K(t,e){let{response:o,binary:a}=b(t,e);if(a)return a;let l=await o;if(!l.ok)throw new Error(`Failed to load '${t}': request failed.`);return new Uint8Array(await l.arrayBuffer())}f(K,"loadBinaryFile");var E;if(j)E=f(async t=>await import(t),"loadScript");else if(B)E=f(async t=>{try{globalThis.importScripts(t)}catch(e){if(e instanceof TypeError)await import(t);else throw e}},"loadScript");else if(g)E=ye;else throw new Error("Cannot determine runtime environment");async function ye(t){t.startsWith("file://")&&(t=t.slice(7)),t.includes("://")?V.runInThisContext(await(await fetch(t)).text()):await import(q.pathToFileURL(t).href)}f(ye,"nodeLoadScript");async function J(t){if(g){await I();let e=await x.readFile(t,{encoding:"utf8"});return JSON.parse(e)}else return await(await fetch(t)).json()}f(J,"loadLockFile");async function X(){if(F)return __dirname;let t;try{throw new Error}catch(a){t=a}let e=z.default.parse(t)[0].fileName;if(C){let a=await import("node:path");return(await import("node:url")).fileURLToPath(a.dirname(e))}let o=e.lastIndexOf(k);if(o===-1)throw new Error("Could not extract indexURL path from pyodide module location");return e.slice(0,o)}f(X,"calculateDirname");function G(t){let e=t.FS,o=t.FS.filesystems.MEMFS,a=t.PATH,l={DIR_MODE:16895,FILE_MODE:33279,mount:function(n){if(!n.opts.fileSystemHandle)throw new Error("opts.fileSystemHandle is required");return o.mount.apply(null,arguments)},syncfs:async(n,r,u)=>{try{let i=l.getLocalSet(n),c=await l.getRemoteSet(n),s=r?c:i,m=r?i:c;await l.reconcile(n,s,m),u(null)}catch(i){u(i)}},getLocalSet:n=>{let r=Object.create(null);function u(s){return s!=="."&&s!==".."}f(u,"isRealDir");function i(s){return m=>a.join2(s,m)}f(i,"toAbsolute");let c=e.readdir(n.mountpoint).filter(u).map(i(n.mountpoint));for(;c.length;){let s=c.pop(),m=e.stat(s);e.isDir(m.mode)&&c.push.apply(c,e.readdir(s).filter(u).map(i(s))),r[s]={timestamp:m.mtime,mode:m.mode}}return{type:"local",entries:r}},getRemoteSet:async n=>{let r=Object.create(null),u=await ge(n.opts.fileSystemHandle);for(let[i,c]of u)i!=="."&&(r[a.join2(n.mountpoint,i)]={timestamp:c.kind==="file"?(await c.getFile()).lastModifiedDate:new Date,mode:c.kind==="file"?l.FILE_MODE:l.DIR_MODE});return{type:"remote",entries:r,handles:u}},loadLocalEntry:n=>{let u=e.lookupPath(n).node,i=e.stat(n);if(e.isDir(i.mode))return{timestamp:i.mtime,mode:i.mode};if(e.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:(n,r)=>{if(e.isDir(r.mode))e.mkdirTree(n,r.mode);else if(e.isFile(r.mode))e.writeFile(n,r.contents,{canOwn:!0});else throw new Error("node type not supported");e.chmod(n,r.mode),e.utime(n,r.timestamp,r.timestamp)},removeLocalEntry:n=>{var r=e.stat(n);e.isDir(r.mode)?e.rmdir(n):e.isFile(r.mode)&&e.unlink(n)},loadRemoteEntry:async n=>{if(n.kind==="file"){let r=await n.getFile();return{contents:new Uint8Array(await r.arrayBuffer()),mode:l.FILE_MODE,timestamp:r.lastModifiedDate}}else{if(n.kind==="directory")return{mode:l.DIR_MODE,timestamp:new Date};throw new Error("unknown kind: "+n.kind)}},storeRemoteEntry:async(n,r,u)=>{let i=n.get(a.dirname(r)),c=e.isFile(u.mode)?await i.getFileHandle(a.basename(r),{create:!0}):await i.getDirectoryHandle(a.basename(r),{create:!0});if(c.kind==="file"){let s=await c.createWritable();await s.write(u.contents),await s.close()}n.set(r,c)},removeRemoteEntry:async(n,r)=>{await n.get(a.dirname(r)).removeEntry(a.basename(r)),n.delete(r)},reconcile:async(n,r,u)=>{let i=0,c=[];Object.keys(r.entries).forEach(function(p){let d=r.entries[p],y=u.entries[p];(!y||e.isFile(d.mode)&&d.timestamp.getTime()>y.timestamp.getTime())&&(c.push(p),i++)}),c.sort();let s=[];if(Object.keys(u.entries).forEach(function(p){r.entries[p]||(s.push(p),i++)}),s.sort().reverse(),!i)return;let m=r.type==="remote"?r.handles:u.handles;for(let p of c){let d=a.normalize(p.replace(n.mountpoint,"/")).substring(1);if(u.type==="local"){let y=m.get(d),h=await l.loadRemoteEntry(y);l.storeLocalEntry(p,h)}else{let y=l.loadLocalEntry(p);await l.storeRemoteEntry(m,d,y)}}for(let p of s)if(u.type==="local")l.removeLocalEntry(p);else{let d=a.normalize(p.replace(n.mountpoint,"/")).substring(1);await l.removeRemoteEntry(m,d)}}};t.FS.filesystems.NATIVEFS_ASYNC=l}f(G,"initializeNativeFS");var ge=f(async t=>{let e=[];async function o(l){for await(let n of l.values())e.push(n),n.kind==="directory"&&await o(n)}f(o,"collect"),await o(t);let a=new Map;a.set(".",t);for(let l of e){let n=(await t.resolve(l)).join("/");a.set(n,l)}return a},"getFsHandles");function Y(t){let e={noImageDecoding:!0,noAudioDecoding:!0,noWasmDecoding:!1,preRun:we(t),quit(o,a){throw e.exited={status:o,toThrow:a},a},print:t.stdout,printErr:t.stderr,arguments:t.args,API:{config:t},locateFile:o=>t.indexURL+o,instantiateWasm:Se(t.indexURL)};return e}f(Y,"createSettings");function he(t){return function(e){let o="/";try{e.FS.mkdirTree(t)}catch(a){console.error(`Error occurred while making a home directory '${t}':`),console.error(a),console.error(`Using '${o}' for a home directory instead`),t=o}e.FS.chdir(t)}}f(he,"createHomeDirectory");function ve(t){return function(e){Object.assign(e.ENV,t)}}f(ve,"setEnvironment");function Ee(t){return e=>{for(let o of t)e.FS.mkdirTree(o),e.FS.mount(e.FS.filesystems.NODEFS,{root:o},o)}}f(Ee,"mountLocalDirectories");function be(t){let e=K(t);return o=>{let a=o._py_version_major(),l=o._py_version_minor();o.FS.mkdirTree("/lib"),o.FS.mkdirTree(`/lib/python${a}.${l}/site-packages`),o.addRunDependency("install-stdlib"),e.then(n=>{o.FS.writeFile(`/lib/python${a}${l}.zip`,n)}).catch(n=>{console.error("Error occurred while installing the standard library:"),console.error(n)}).finally(()=>{o.removeRunDependency("install-stdlib")})}}f(be,"installStdlib");function we(t){let e;return t.stdLibURL!=null?e=t.stdLibURL:e=t.indexURL+"python_stdlib.zip",[be(e),he(t.env.HOME),ve(t.env),Ee(t._node_mounts),G]}f(we,"getFileSystemInitializationFuncs");function Se(t){let{binary:e,response:o}=b(t+"pyodide.asm.wasm");return function(a,l){return async function(){try{let n;o?n=await WebAssembly.instantiateStreaming(o,a):n=await WebAssembly.instantiate(await e,a);let{instance:r,module:u}=n;typeof WasmOffsetConverter<"u"&&(wasmOffsetConverter=new WasmOffsetConverter(wasmBinary,u)),l(r,u)}catch(n){console.warn("wasm instantiation failed!"),console.warn(n)}}(),{}}}f(Se,"getInstantiateWasmFunc");var A="0.26.1";async function Be(t={}){await I();let e=t.indexURL||await X();e=S(e),e.endsWith("/")||(e+="/"),t.indexURL=e;let o={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:e+"pyodide-lock.json",args:[],_node_mounts:[],env:{},packageCacheDir:e,packages:[],enableRunUntilComplete:!1},a=Object.assign(o,t);a.env.HOME||(a.env.HOME="/home/pyodide");let l=Y(a),n=l.API;if(n.lockFilePromise=J(a.lockFileURL),typeof _createPyodideModule!="function"){let s=`${a.indexURL}pyodide.asm.js`;await E(s)}let r;if(t._loadSnapshot){let s=await t._loadSnapshot;ArrayBuffer.isView(s)?r=s:r=new Uint8Array(s),l.noInitialRun=!0,l.INITIAL_MEMORY=r.length}let u=await _createPyodideModule(l);if(l.exited)throw l.exited.toThrow;if(t.pyproxyToStringRepr&&n.setPyProxyToStringMethod(!0),n.version!==A)throw new Error(`Pyodide version does not match: '${A}' <==> '${n.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);u.locateFile=s=>{throw new Error("Didn't expect to load any more file_packager files!")};let i;r&&(i=n.restoreSnapshot(r));let c=n.finalizeBootstrap(i);return n.sys.path.insert(0,n.config.env.HOME),c.version.includes("dev")||n.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${c.version}/full/`),n._pyodide.set_excepthook(),await n.packageIndexReady,n.initializeStreams(a.stdin,a.stdout,a.stderr),c}f(Be,"loadPyodide");export{Be as loadPyodide,A as version}; //# sourceMappingURL=pyodide.mjs.map