@stlite/desktop 0.62.3 → 0.62.4
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/build/asset-manifest.json +3 -3
- package/build/index.html +1 -1
- package/build/pyodide/pyodide-lock.json +1 -1
- package/build/pyodide/pyodide.asm.js +1 -1
- package/build/pyodide/pyodide.asm.wasm +0 -0
- package/build/pyodide/pyodide.mjs +3 -9
- package/build/pyodide/python_stdlib.zip +0 -0
- package/build/static/js/{8798.a2b2458c.chunk.js → 8798.7f17013e.chunk.js} +1 -1
- package/build/static/js/{main.53e797b7.js → main.357b6428.js} +2 -2
- package/package.json +6 -6
- package/wheels/streamlit-1.36.0-cp312-none-any.whl +0 -0
- /package/build/static/js/{main.53e797b7.js.LICENSE.txt → main.357b6428.js.LICENSE.txt} +0 -0
|
Binary file
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).filter(function(
|
|
3
|
-
`).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(`
|
|
4
|
-
`)>-1&&r.message.split(`
|
|
5
|
-
`).length>r.stacktrace.split(`
|
|
6
|
-
`).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(`
|
|
7
|
-
`),c=[],s=2,m=i.length;s<m;s+=2){var p=u.exec(i[s]);p&&c.push(new e({fileName:p[2],lineNumber:p[1],source:i[s]}))}return c},"ErrorStackParser$$parseOpera9"),parseOpera10:f(function(r){for(var u=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,i=r.stacktrace.split(`
|
|
8
|
-
`),c=[],s=0,m=i.length;s<m;s+=2){var p=u.exec(i[s]);p&&c.push(new e({functionName:p[3]||void 0,fileName:p[2],lineNumber:p[1],source:i[s]}))}return c},"ErrorStackParser$$parseOpera10"),parseOpera11:f(function(r){var u=r.stack.split(`
|
|
9
|
-
`).filter(function(i){return!!i.match(o)&&!i.match(/^Error created at/)},this);return u.map(function(i){var c=i.split("@"),s=this.extractLocation(c.pop()),m=c.shift()||"",p=m.replace(/<anonymous function(: (\w+))?>/,"$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};
|
|
1
|
+
var Q=Object.defineProperty;var c=(e,t)=>Q(e,"name",{value:t,configurable:!0}),O=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,i)=>(typeof require<"u"?require:t)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});function Z(e){return!isNaN(parseFloat(e))&&isFinite(e)}c(Z,"_isNumber");function E(e){return e.charAt(0).toUpperCase()+e.substring(1)}c(E,"_capitalize");function P(e){return function(){return this[e]}}c(P,"_getter");var w=["isConstructor","isEval","isNative","isToplevel"],N=["columnNumber","lineNumber"],_=["fileName","functionName","source"],ee=["args"],te=["evalOrigin"],I=w.concat(N,_,ee,te);function p(e){if(e)for(var t=0;t<I.length;t++)e[I[t]]!==void 0&&this["set"+E(I[t])](e[I[t]])}c(p,"StackFrame");p.prototype={getArgs:function(){return this.args},setArgs:function(e){if(Object.prototype.toString.call(e)!=="[object Array]")throw new TypeError("Args must be an Array");this.args=e},getEvalOrigin:function(){return this.evalOrigin},setEvalOrigin:function(e){if(e instanceof p)this.evalOrigin=e;else if(e instanceof Object)this.evalOrigin=new p(e);else throw new TypeError("Eval Origin must be an Object or StackFrame")},toString:function(){var e=this.getFileName()||"",t=this.getLineNumber()||"",i=this.getColumnNumber()||"",r=this.getFunctionName()||"";return this.getIsEval()?e?"[eval] ("+e+":"+t+":"+i+")":"[eval]:"+t+":"+i:r?r+" ("+e+":"+t+":"+i+")":e+":"+t+":"+i}};p.fromString=c(function(t){var i=t.indexOf("("),r=t.lastIndexOf(")"),a=t.substring(0,i),n=t.substring(i+1,r).split(","),o=t.substring(r+1);if(o.indexOf("@")===0)var s=/@(.+?)(?::(\d+))?(?::(\d+))?$/.exec(o,""),l=s[1],d=s[2],u=s[3];return new p({functionName:a,args:n||void 0,fileName:l,lineNumber:d||void 0,columnNumber:u||void 0})},"StackFrame$$fromString");for(b=0;b<w.length;b++)p.prototype["get"+E(w[b])]=P(w[b]),p.prototype["set"+E(w[b])]=function(e){return function(t){this[e]=!!t}}(w[b]);var b;for(v=0;v<N.length;v++)p.prototype["get"+E(N[v])]=P(N[v]),p.prototype["set"+E(N[v])]=function(e){return function(t){if(!Z(t))throw new TypeError(e+" must be a Number");this[e]=Number(t)}}(N[v]);var v;for(h=0;h<_.length;h++)p.prototype["get"+E(_[h])]=P(_[h]),p.prototype["set"+E(_[h])]=function(e){return function(t){this[e]=String(t)}}(_[h]);var h,x=p;function ne(){var e=/^\s*at .*(\S+:\d+|\(native\))/m,t=/^(eval@)?(\[native code])?$/;return{parse:c(function(r){if(r.stack&&r.stack.match(e))return this.parseV8OrIE(r);if(r.stack)return this.parseFFOrSafari(r);throw new Error("Cannot parse given Error object")},"ErrorStackParser$$parse"),extractLocation:c(function(r){if(r.indexOf(":")===-1)return[r];var a=/(.+?)(?::(\d+))?(?::(\d+))?$/,n=a.exec(r.replace(/[()]/g,""));return[n[1],n[2]||void 0,n[3]||void 0]},"ErrorStackParser$$extractLocation"),parseV8OrIE:c(function(r){var a=r.stack.split(`
|
|
2
|
+
`).filter(function(n){return!!n.match(e)},this);return a.map(function(n){n.indexOf("(eval ")>-1&&(n=n.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(,.*$)/g,""));var o=n.replace(/^\s+/,"").replace(/\(eval code/g,"(").replace(/^.*?\s+/,""),s=o.match(/ (\(.+\)$)/);o=s?o.replace(s[0],""):o;var l=this.extractLocation(s?s[1]:o),d=s&&o||void 0,u=["eval","<anonymous>"].indexOf(l[0])>-1?void 0:l[0];return new x({functionName:d,fileName:u,lineNumber:l[1],columnNumber:l[2],source:n})},this)},"ErrorStackParser$$parseV8OrIE"),parseFFOrSafari:c(function(r){var a=r.stack.split(`
|
|
3
|
+
`).filter(function(n){return!n.match(t)},this);return a.map(function(n){if(n.indexOf(" > eval")>-1&&(n=n.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),n.indexOf("@")===-1&&n.indexOf(":")===-1)return new x({functionName:n});var o=/((.*".+"[^@]*)?[^@]*)(?:@)/,s=n.match(o),l=s&&s[1]?s[1]:void 0,d=this.extractLocation(n.replace(o,""));return new x({functionName:l,fileName:d[0],lineNumber:d[1],columnNumber:d[2],source:n})},this)},"ErrorStackParser$$parseFFOrSafari")}}c(ne,"ErrorStackParser");var re=new ne;var M=re;var g=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&!process.browser,A=g&&typeof module<"u"&&typeof module.exports<"u"&&typeof O<"u"&&typeof __dirname<"u",W=g&&!A,Ne=typeof globalThis.Bun<"u",oe=typeof Deno<"u",B=!g&&!oe,$=B&&typeof window=="object"&&typeof document=="object"&&typeof document.createElement=="function"&&typeof sessionStorage=="object"&&typeof importScripts!="function",j=B&&typeof importScripts=="function"&&typeof self=="object",_e=typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent.indexOf("Chrome")==-1&&navigator.userAgent.indexOf("Safari")>-1;var V,L,z,H,D;async function T(){if(!g||(V=(await import("node:url")).default,H=await import("node:fs"),D=await import("node:fs/promises"),z=(await import("node:vm")).default,L=await import("node:path"),U=L.sep,typeof O<"u"))return;let e=H,t=await import("node:crypto"),i=await import("ws"),r=await import("node:child_process"),a={fs:e,crypto:t,ws:i,child_process:r};globalThis.require=function(n){return a[n]}}c(T,"initNodeModules");function ie(e,t){return L.resolve(t||".",e)}c(ie,"node_resolvePath");function ae(e,t){return t===void 0&&(t=location),new URL(e,t).toString()}c(ae,"browser_resolvePath");var k;g?k=ie:k=ae;var U;g||(U="/");function se(e,t){return e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")?{response:fetch(e)}:{binary:D.readFile(e).then(i=>new Uint8Array(i.buffer,i.byteOffset,i.byteLength))}}c(se,"node_getBinaryResponse");function ce(e,t){let i=new URL(e,location);return{response:fetch(i,t?{integrity:t}:{})}}c(ce,"browser_getBinaryResponse");var R;g?R=se:R=ce;async function q(e,t){let{response:i,binary:r}=R(e,t);if(r)return r;let a=await i;if(!a.ok)throw new Error(`Failed to load '${e}': request failed.`);return new Uint8Array(await a.arrayBuffer())}c(q,"loadBinaryFile");var F;if($)F=c(async e=>await import(e),"loadScript");else if(j)F=c(async e=>{try{globalThis.importScripts(e)}catch(t){if(t instanceof TypeError)await import(e);else throw t}},"loadScript");else if(g)F=le;else throw new Error("Cannot determine runtime environment");async function le(e){e.startsWith("file://")&&(e=e.slice(7)),e.includes("://")?z.runInThisContext(await(await fetch(e)).text()):await import(V.pathToFileURL(e).href)}c(le,"nodeLoadScript");async function J(e){if(g){await T();let t=await D.readFile(e,{encoding:"utf8"});return JSON.parse(t)}else return await(await fetch(e)).json()}c(J,"loadLockFile");async function K(){if(A)return __dirname;let e;try{throw new Error}catch(r){e=r}let t=M.parse(e)[0].fileName;if(g&&!t.startsWith("file://")&&(t=`file://${t}`),W){let r=await import("node:path");return(await import("node:url")).fileURLToPath(r.dirname(t))}let i=t.lastIndexOf(U);if(i===-1)throw new Error("Could not extract indexURL path from pyodide module location");return t.slice(0,i)}c(K,"calculateDirname");function Y(e){let t=e.FS,i=e.FS.filesystems.MEMFS,r=e.PATH,a={DIR_MODE:16895,FILE_MODE:33279,mount:function(n){if(!n.opts.fileSystemHandle)throw new Error("opts.fileSystemHandle is required");return i.mount.apply(null,arguments)},syncfs:async(n,o,s)=>{try{let l=a.getLocalSet(n),d=await a.getRemoteSet(n),u=o?d:l,m=o?l:d;await a.reconcile(n,u,m),s(null)}catch(l){s(l)}},getLocalSet:n=>{let o=Object.create(null);function s(u){return u!=="."&&u!==".."}c(s,"isRealDir");function l(u){return m=>r.join2(u,m)}c(l,"toAbsolute");let d=t.readdir(n.mountpoint).filter(s).map(l(n.mountpoint));for(;d.length;){let u=d.pop(),m=t.stat(u);t.isDir(m.mode)&&d.push.apply(d,t.readdir(u).filter(s).map(l(u))),o[u]={timestamp:m.mtime,mode:m.mode}}return{type:"local",entries:o}},getRemoteSet:async n=>{let o=Object.create(null),s=await de(n.opts.fileSystemHandle);for(let[l,d]of s)l!=="."&&(o[r.join2(n.mountpoint,l)]={timestamp:d.kind==="file"?(await d.getFile()).lastModifiedDate:new Date,mode:d.kind==="file"?a.FILE_MODE:a.DIR_MODE});return{type:"remote",entries:o,handles:s}},loadLocalEntry:n=>{let s=t.lookupPath(n).node,l=t.stat(n);if(t.isDir(l.mode))return{timestamp:l.mtime,mode:l.mode};if(t.isFile(l.mode))return s.contents=i.getFileDataAsTypedArray(s),{timestamp:l.mtime,mode:l.mode,contents:s.contents};throw new Error("node type not supported")},storeLocalEntry:(n,o)=>{if(t.isDir(o.mode))t.mkdirTree(n,o.mode);else if(t.isFile(o.mode))t.writeFile(n,o.contents,{canOwn:!0});else throw new Error("node type not supported");t.chmod(n,o.mode),t.utime(n,o.timestamp,o.timestamp)},removeLocalEntry:n=>{var o=t.stat(n);t.isDir(o.mode)?t.rmdir(n):t.isFile(o.mode)&&t.unlink(n)},loadRemoteEntry:async n=>{if(n.kind==="file"){let o=await n.getFile();return{contents:new Uint8Array(await o.arrayBuffer()),mode:a.FILE_MODE,timestamp:o.lastModifiedDate}}else{if(n.kind==="directory")return{mode:a.DIR_MODE,timestamp:new Date};throw new Error("unknown kind: "+n.kind)}},storeRemoteEntry:async(n,o,s)=>{let l=n.get(r.dirname(o)),d=t.isFile(s.mode)?await l.getFileHandle(r.basename(o),{create:!0}):await l.getDirectoryHandle(r.basename(o),{create:!0});if(d.kind==="file"){let u=await d.createWritable();await u.write(s.contents),await u.close()}n.set(o,d)},removeRemoteEntry:async(n,o)=>{await n.get(r.dirname(o)).removeEntry(r.basename(o)),n.delete(o)},reconcile:async(n,o,s)=>{let l=0,d=[];Object.keys(o.entries).forEach(function(f){let y=o.entries[f],S=s.entries[f];(!S||t.isFile(y.mode)&&y.timestamp.getTime()>S.timestamp.getTime())&&(d.push(f),l++)}),d.sort();let u=[];if(Object.keys(s.entries).forEach(function(f){o.entries[f]||(u.push(f),l++)}),u.sort().reverse(),!l)return;let m=o.type==="remote"?o.handles:s.handles;for(let f of d){let y=r.normalize(f.replace(n.mountpoint,"/")).substring(1);if(s.type==="local"){let S=m.get(y),X=await a.loadRemoteEntry(S);a.storeLocalEntry(f,X)}else{let S=a.loadLocalEntry(f);await a.storeRemoteEntry(m,y,S)}}for(let f of u)if(s.type==="local")a.removeLocalEntry(f);else{let y=r.normalize(f.replace(n.mountpoint,"/")).substring(1);await a.removeRemoteEntry(m,y)}}};e.FS.filesystems.NATIVEFS_ASYNC=a}c(Y,"initializeNativeFS");var de=c(async e=>{let t=[];async function i(a){for await(let n of a.values())t.push(n),n.kind==="directory"&&await i(n)}c(i,"collect"),await i(e);let r=new Map;r.set(".",e);for(let a of t){let n=(await e.resolve(a)).join("/");r.set(n,a)}return r},"getFsHandles");function G(e){let t={noImageDecoding:!0,noAudioDecoding:!0,noWasmDecoding:!1,preRun:ge(e),quit(i,r){throw t.exited={status:i,toThrow:r},r},print:e.stdout,printErr:e.stderr,arguments:e.args,API:{config:e},locateFile:i=>e.indexURL+i,instantiateWasm:ye(e.indexURL)};return t}c(G,"createSettings");function ue(e){return function(t){let i="/";try{t.FS.mkdirTree(e)}catch(r){console.error(`Error occurred while making a home directory '${e}':`),console.error(r),console.error(`Using '${i}' for a home directory instead`),e=i}t.FS.chdir(e)}}c(ue,"createHomeDirectory");function fe(e){return function(t){Object.assign(t.ENV,e)}}c(fe,"setEnvironment");function me(e){return t=>{for(let i of e)t.FS.mkdirTree(i),t.FS.mount(t.FS.filesystems.NODEFS,{root:i},i)}}c(me,"mountLocalDirectories");function pe(e){let t=q(e);return i=>{let r=i._py_version_major(),a=i._py_version_minor();i.FS.mkdirTree("/lib"),i.FS.mkdirTree(`/lib/python${r}.${a}/site-packages`),i.addRunDependency("install-stdlib"),t.then(n=>{i.FS.writeFile(`/lib/python${r}${a}.zip`,n)}).catch(n=>{console.error("Error occurred while installing the standard library:"),console.error(n)}).finally(()=>{i.removeRunDependency("install-stdlib")})}}c(pe,"installStdlib");function ge(e){let t;return e.stdLibURL!=null?t=e.stdLibURL:t=e.indexURL+"python_stdlib.zip",[pe(t),ue(e.env.HOME),fe(e.env),me(e._node_mounts),Y]}c(ge,"getFileSystemInitializationFuncs");function ye(e){let{binary:t,response:i}=R(e+"pyodide.asm.wasm");return function(r,a){return async function(){try{let n;i?n=await WebAssembly.instantiateStreaming(i,r):n=await WebAssembly.instantiate(await t,r);let{instance:o,module:s}=n;typeof WasmOffsetConverter<"u"&&(wasmOffsetConverter=new WasmOffsetConverter(wasmBinary,s)),a(o,s)}catch(n){console.warn("wasm instantiation failed!"),console.warn(n)}}(),{}}}c(ye,"getInstantiateWasmFunc");var C="0.26.2";async function $e(e={}){var u,m;await T();let t=e.indexURL||await K();t=k(t),t.endsWith("/")||(t+="/"),e.indexURL=t;let i={fullStdLib:!1,jsglobals:globalThis,stdin:globalThis.prompt?globalThis.prompt:void 0,lockFileURL:t+"pyodide-lock.json",args:[],_node_mounts:[],env:{},packageCacheDir:t,packages:[],enableRunUntilComplete:!1,checkAPIVersion:!0},r=Object.assign(i,e);(u=r.env).HOME??(u.HOME="/home/pyodide"),(m=r.env).PYTHONINSPECT??(m.PYTHONINSPECT="1");let a=G(r),n=a.API;if(n.lockFilePromise=J(r.lockFileURL),typeof _createPyodideModule!="function"){let f=`${r.indexURL}pyodide.asm.js`;await F(f)}let o;if(e._loadSnapshot){let f=await e._loadSnapshot;ArrayBuffer.isView(f)?o=f:o=new Uint8Array(f),a.noInitialRun=!0,a.INITIAL_MEMORY=o.length}let s=await _createPyodideModule(a);if(a.exited)throw a.exited.toThrow;if(e.pyproxyToStringRepr&&n.setPyProxyToStringMethod(!0),n.version!==C&&r.checkAPIVersion)throw new Error(`Pyodide version does not match: '${C}' <==> '${n.version}'. If you updated the Pyodide version, make sure you also updated the 'indexURL' parameter passed to loadPyodide.`);s.locateFile=f=>{throw new Error("Didn't expect to load any more file_packager files!")};let l;o&&(l=n.restoreSnapshot(o));let d=n.finalizeBootstrap(l);return n.sys.path.insert(0,n.config.env.HOME),d.version.includes("dev")||n.setCdnUrl(`https://cdn.jsdelivr.net/pyodide/v${d.version}/full/`),n._pyodide.set_excepthook(),await n.packageIndexReady,n.initializeStreams(r.stdin,r.stdout,r.stderr),d}c($e,"loadPyodide");export{$e as loadPyodide,C as version};
|
|
10
4
|
//# sourceMappingURL=pyodide.mjs.map
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={56977:e=>{function t(e){if("string"!==typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function n(e,t){for(var n,r="",o=0,s=-1,i=0,a=0;a<=e.length;++a){if(a<e.length)n=e.charCodeAt(a);else{if(47===n)break;n=47}if(47===n){if(s===a-1||1===i);else if(s!==a-1&&2===i){if(r.length<2||2!==o||46!==r.charCodeAt(r.length-1)||46!==r.charCodeAt(r.length-2))if(r.length>2){var l=r.lastIndexOf("/");if(l!==r.length-1){-1===l?(r="",o=0):o=(r=r.slice(0,l)).length-1-r.lastIndexOf("/"),s=a,i=0;continue}}else if(2===r.length||1===r.length){r="",o=0,s=a,i=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(s+1,a):r=e.slice(s+1,a),o=a-s-1;s=a,i=0}else 46===n&&-1!==i?++i:i=-1}return r}var r={resolve:function(){for(var e,r="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var i;s>=0?i=arguments[s]:(void 0===e&&(e=process.cwd()),i=e),t(i),0!==i.length&&(r=i+"/"+r,o=47===i.charCodeAt(0))}return r=n(r,!o),o?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(e){if(t(e),0===e.length)return".";var r=47===e.charCodeAt(0),o=47===e.charCodeAt(e.length-1);return 0!==(e=n(e,!r)).length||r||(e="."),e.length>0&&o&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return t(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,n=0;n<arguments.length;++n){var o=arguments[n];t(o),o.length>0&&(void 0===e?e=o:e+="/"+o)}return void 0===e?".":r.normalize(e)},relative:function(e,n){if(t(e),t(n),e===n)return"";if((e=r.resolve(e))===(n=r.resolve(n)))return"";for(var o=1;o<e.length&&47===e.charCodeAt(o);++o);for(var s=e.length,i=s-o,a=1;a<n.length&&47===n.charCodeAt(a);++a);for(var l=n.length-a,c=i<l?i:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(a+g))return n.slice(a+g+1);if(0===g)return n.slice(a+g)}else i>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var u=e.charCodeAt(o+g);if(u!==n.charCodeAt(a+g))break;47===u&&(d=g)}var p="";for(g=o+d+1;g<=s;++g)g!==s&&47!==e.charCodeAt(g)||(0===p.length?p+="..":p+="/..");return p.length>0?p+n.slice(a+d):(a+=d,47===n.charCodeAt(a)&&++a,n.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var n=e.charCodeAt(0),r=47===n,o=-1,s=!0,i=e.length-1;i>=1;--i)if(47===(n=e.charCodeAt(i))){if(!s){o=i;break}}else s=!1;return-1===o?r?"/":".":r&&1===o?"//":e.slice(0,o)},basename:function(e,n){if(void 0!==n&&"string"!==typeof n)throw new TypeError('"ext" argument must be a string');t(e);var r,o=0,s=-1,i=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var a=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!i){o=r+1;break}}else-1===l&&(i=!1,l=r+1),a>=0&&(c===n.charCodeAt(a)?-1===--a&&(s=r):(a=-1,s=l))}return o===s?s=l:-1===s&&(s=e.length),e.slice(o,s)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!i){o=r+1;break}}else-1===s&&(i=!1,s=r+1);return-1===s?"":e.slice(o,s)},extname:function(e){t(e);for(var n=-1,r=0,o=-1,s=!0,i=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===o&&(s=!1,o=a+1),46===l?-1===n?n=a:1!==i&&(i=1):-1!==n&&(i=-1);else if(!s){r=a+1;break}}return-1===n||-1===o||0===i||1===i&&n===o-1&&n===r+1?"":e.slice(n,o)},format:function(e){if(null===e||"object"!==typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var n=t.dir||t.root,r=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+r:n+e+r:r}("/",e)},parse:function(e){t(e);var n={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return n;var r,o=e.charCodeAt(0),s=47===o;s?(n.root="/",r=1):r=0;for(var i=-1,a=0,l=-1,c=!0,d=e.length-1,g=0;d>=r;--d)if(47!==(o=e.charCodeAt(d)))-1===l&&(c=!1,l=d+1),46===o?-1===i?i=d:1!==g&&(g=1):-1!==i&&(g=-1);else if(!c){a=d+1;break}return-1===i||-1===l||0===g||1===g&&i===l-1&&i===a+1?-1!==l&&(n.base=n.name=0===a&&s?e.slice(1,l):e.slice(a,l)):(0===a&&s?(n.name=e.slice(1,i),n.base=e.slice(1,l)):(n.name=e.slice(a,i),n.base=e.slice(a,l)),n.ext=e.slice(i,l)),a>0?n.dir=e.slice(0,a-1):s&&(n.dir="/"),n},sep:"/",delimiter:":",win32:null,posix:null};r.posix=r,e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{new RegExp("[[(<=>!~;@]");class e{constructor(){this.promise=new Promise(((e,t)=>{this.resolveInternal=e,this.rejectInternal=t}))}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}}var t=n(56977),r=n.n(t);function o(e,t){const n=r().normalize(t),o=r().dirname(n).split("/"),s=[];for(const r of o){s.push(r);const t=s.join("/");if(e.FS.analyzePath(t).exists){if(e.FS.isDir(t))throw new Error(`"${t}" already exists and is not a directory.`)}else try{e.FS.mkdir(t)}catch(i){throw console.error(`Failed to create a directory "${t}"`),i}}}function s(e,t,n,r){o(e,t),e.FS.writeFile(t,n,r)}const i=new RegExp("[[(<=>!~;@]");function a(e){e.forEach((e=>{let t;try{t=new URL(e)}catch{return}if("emfs:"===t.protocol||"file:"===t.protocol)throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)}));return e.filter((e=>{const t="streamlit"===function(e){return e.split(i)[0].trim()}(e);return!t||(console.warn(`Streamlit is specified in the requirements ("${e}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1)}))}var l=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};function c(e,t){return l(this,void 0,void 0,(function*(){const{scriptURL:n,pyodideIndexURL:r,isESModule:o}=yield function(e){var t;return l(this,void 0,void 0,(function*(){const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(yield import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=yield import("node:path"),n=yield import("node:url");!e.includes("://")&&t.isAbsolute(e)&&(e=n.pathToFileURL(e).href)}return{scriptURL:e,pyodideIndexURL:o,isESModule:!0}}return{scriptURL:e,pyodideIndexURL:o,isESModule:!1}}))}(e);let s;if(o){s=(yield import(n)).loadPyodide}else importScripts(n),s=self.loadPyodide;return s(Object.assign(Object.assign({},t),{indexURL:r}))}))}var d=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};let g;function u(e,t,n){return d(this,void 0,void 0,(function*(){const r=n.map((t=>function(e,t){if(!g){const t='\nimport ast\nfrom textwrap import dedent\n\ndef find_imports(source: str) -> list[str]:\n source = dedent(source)\n\n try:\n mod = ast.parse(source)\n except SyntaxError:\n return []\n imports = set()\n for node in mod.body:\n if isinstance(node, ast.Import):\n for name in node.names:\n node_name = name.name\n imports.add(node_name.split(".")[0])\n elif isinstance(node, ast.ImportFrom):\n module_name = node.module\n if module_name is None:\n continue\n imports.add(module_name.split(".")[0])\n return imports\n';e.runPython(t),g=e.globals.get("find_imports")}return g(t).toJs()}(e,t))),o=function(e){const t=new Set;for(const n of e)for(const e of n)t.add(e);return t}(r),s=Array.from(o).filter((t=>!e.runPython(`__import__('importlib').util.find_spec('${t}')`))).map((t=>e._api._import_name_to_package_name.get(t))).filter((e=>e));if(0===s.length)return;const i=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:s}},i.port2);try{const t=yield e.loadPackage(s);return i.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void i.port1.close()}catch(a){throw i.port1.postMessage({type:"moduleAutoLoad:error",error:a}),i.port1.close(),a}}))}var p=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};const m=n.g;function f(e,t,n){const r=u(e,t,n);m.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const h=self.postMessage;self.onmessage=function(t,n,r){function i(e){n({type:"event:progress",data:{message:e}})}let l,d;const g=new e,u=function(){var e,o;return p(this,void 0,void 0,(function*(){const u=yield g.promise,h=Object.assign(Object.assign({},r),u);console.debug("Initial data",h);const{entrypoint:_,files:y,archives:v,requirements:b,prebuiltPackageNames:w,wheels:k,pyodideUrl:S=t,streamlitConfig:A,idbfsMountpoints:P,nodefsMountpoints:C,moduleAutoLoad:F}=h,x=a(b);i("Loading Pyodide."),console.debug("Loading Pyodide"),l=yield c(S,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let L=!1;P&&(L=!0,P.forEach((e=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.IDBFS,{},e)})),yield new Promise(((e,t)=>{l.FS.syncfs(!0,(n=>{n?t(n):e()}))}))),C&&Object.entries(C).forEach((([e,t])=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.NODEFS,{root:t},e)})),i("Mounting files.");const I=[];yield Promise.all(Object.keys(y).map((e=>p(this,void 0,void 0,(function*(){const t=y[e];let n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=yield fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=y[e];console.debug(`Write a file "${e}"`),s(l,e,n,r),e.endsWith(".py")&&I.push(e)}))))),i("Unpacking archives."),yield Promise.all(v.map((e=>p(this,void 0,void 0,(function*(){let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=yield fetch(e.url).then((e=>e.arrayBuffer()))):t=e.buffer;const{format:n,options:r}=e;console.debug("Unpack an archive",{format:n,options:r}),l.unpackArchive(t,n,r)}))))),yield l.loadPackage("micropip");const E=l.pyimport("micropip");if(i("Mocking some packages."),console.debug("Mock pyarrow"),function(e){e.runPython('\nimport micropip\nmicropip.add_mock_package(\n "pyarrow", "0.0.1",\n modules={\n "pyarrow": """\n__version__ = \'0.0.1\' # TODO: Update when releasing\n\n\nclass Table:\n @classmethod\n def from_pandas(*args, **kwargs):\n raise NotImplementedError("stlite is not supporting this method.")\n\n\nclass Array:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.Array")\n\n\nclass ChunkedArray:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")\n"""\n }\n)\n')}(l),console.debug("Mocked pyarrow"),i("Installing packages."),console.debug("Installing the prebuilt packages:",w),yield l.loadPackage(w),console.debug("Installed the prebuilt packages"),k?(console.debug("Installing the wheels:",k,"and the requirements:",x),yield E.install.callKwargs([k.stliteLib,k.streamlit,...x],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",x),yield E.install.callKwargs(x,{keep_going:!0}),console.debug("Installed the requirements")),F){const e=I.map((e=>l.FS.readFile(e,{encoding:"utf8"})));f(l,n,e)}yield l.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),i("Loading streamlit package."),console.debug("Loading the Streamlit package"),yield l.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),i("Setting up the loggers."),console.debug("Setting the loggers"),yield l.runPythonAsync('\nimport logging\nimport streamlit.logger\n\nstreamlit.logger.get_logger = logging.getLogger\nstreamlit.logger.setup_formatter = None\nstreamlit.logger.update_formatter = lambda *a, **k: None\nstreamlit.logger.set_log_level = lambda *a, **k: None\n\nfor name in streamlit.logger._loggers.keys():\n if name == "root":\n name = "streamlit"\n logger = logging.getLogger(name)\n logger.propagate = True\n logger.handlers.clear()\n logger.setLevel(logging.NOTSET)\n\nstreamlit.logger._loggers = {}\n');m.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},yield l.runPythonAsync('\ndef setup_loggers(streamlit_level, streamlit_message_format):\n from js import __logCallback__\n\n\n class JsHandler(logging.Handler):\n def emit(self, record):\n msg = self.format(record)\n __logCallback__(record.levelno, msg)\n\n\n root_message_format = "%(levelname)s:%(name)s:%(message)s"\n\n root_logger = logging.getLogger()\n root_logger.handlers.clear()\n root_formatter = logging.Formatter(root_message_format)\n root_handler = JsHandler()\n root_handler.setFormatter(root_formatter)\n root_logger.addHandler(root_handler)\n root_logger.setLevel(logging.DEBUG)\n\n streamlit_logger = logging.getLogger("streamlit")\n streamlit_logger.propagate = False\n streamlit_logger.handlers.clear()\n streamlit_formatter = logging.Formatter(streamlit_message_format)\n streamlit_handler = JsHandler()\n streamlit_handler.setFormatter(streamlit_formatter)\n streamlit_logger.addHandler(streamlit_handler)\n streamlit_logger.setLevel(streamlit_level.upper())\n');const O=(null!==(e=null===A||void 0===A?void 0:A["logger.level"])&&void 0!==e?e:"INFO").toString(),j=null!==(o=null===A||void 0===A?void 0:A["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(l.globals.get("setup_loggers")(O,j),console.debug("Set the loggers"),i("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),yield l.runPythonAsync("\nimport streamlit\n\ndef is_cacheable_msg(msg):\n return False\n\nstreamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg\n"),console.debug("Mocked some Streamlit functions"),L){i("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;m.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,l.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},yield l.runPythonAsync('\nfrom streamlit.runtime.app_session import AppSession\nfrom streamlit.runtime.scriptrunner import ScriptRunnerEvent\nfrom js import __scriptFinishedCallback__\n\ndef wrap_app_session_on_scriptrunner_event(original_method):\n def wrapped(self, *args, **kwargs):\n if "event" in kwargs:\n event = kwargs["event"]\n if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:\n __scriptFinishedCallback__()\n return original_method(self, *args, **kwargs)\n return wrapped\n\nAppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)\n'),console.debug("Set up the IndexedDB filesystem synchronizer")}return i("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),m.__streamlitFlagOptions__=Object.assign(Object.assign({"browser.gatherUsageStats":!1},A),{"runner.fastReruns":!1}),yield l.runPythonAsync(`\nfrom stlite_lib.bootstrap import load_config_options, prepare\nfrom stlite_lib.server import Server\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${_}"\nargs = []\n\nprepare(main_script_path, args)\n\nserver = Server(main_script_path)\nserver.start()\n`),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),d=l.globals.get("server").copy(),console.debug("Set up the HTTP server"),n({type:"event:loaded"}),h}))}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),e=>p(this,void 0,void 0,(function*(){const t=e.data;if("initData"===t.type)return void g.resolve(t.data);const{moduleAutoLoad:r}=yield u,i=e.ports[0];try{switch(t.type){case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;d.start_websocket(e,((e,t)=>{if(t){const t=e,r=t.getBuffer("u8");t.destroy();const o=new Uint8ClampedArray(r.data.buffer,r.data.byteOffset,r.data.byteLength);n({type:"websocket:message",data:{payload:new Uint8Array(o)}})}else{n({type:"websocket:message",data:{payload:e}})}})),i.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;d.receive_websocket_from_js(e);break}case"http:request":{console.debug("http:request",t.data);const{request:e}=t.data,n=(e,t,n)=>{const r=new Map(t.toJs()),o=n.toJs();console.debug({statusCode:e,headers:r,body:o});const s={type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}};i.postMessage(s)};d.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,n);break}case"file:write":{const{path:e,data:o,opts:a}=t.data;r&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),f(l,n,[o])),console.debug(`Write a file "${e}"`),s(l,e,o,a),i.postMessage({type:"reply"});break}case"file:rename":{const{oldPath:e,newPath:n}=t.data;console.debug(`Rename "${e}" to ${n}`),function(e,t,n){o(e,n),e.FS.rename(t,n)}(l,e,n),i.postMessage({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),l.FS.unlink(e),i.postMessage({type:"reply"});break}case"install":{const{requirements:e}=t.data,n=l.pyimport("micropip"),r=a(e);console.debug("Install the requirements:",r),yield n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),i.postMessage({type:"reply"})}))}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;const e=new Error(c.message);e.name=c.name,e.stack=c.stack,i.postMessage({type:"reply",error:e})}}))}("https://cdn.jsdelivr.net/pyodide/v0.26.1/full/pyodide.js",((e,t)=>h(e,t?[t]:void 0)))})()})();
|
|
1
|
+
(()=>{"use strict";var e={56977:e=>{function t(e){if("string"!==typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function n(e,t){for(var n,r="",o=0,s=-1,i=0,a=0;a<=e.length;++a){if(a<e.length)n=e.charCodeAt(a);else{if(47===n)break;n=47}if(47===n){if(s===a-1||1===i);else if(s!==a-1&&2===i){if(r.length<2||2!==o||46!==r.charCodeAt(r.length-1)||46!==r.charCodeAt(r.length-2))if(r.length>2){var l=r.lastIndexOf("/");if(l!==r.length-1){-1===l?(r="",o=0):o=(r=r.slice(0,l)).length-1-r.lastIndexOf("/"),s=a,i=0;continue}}else if(2===r.length||1===r.length){r="",o=0,s=a,i=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(s+1,a):r=e.slice(s+1,a),o=a-s-1;s=a,i=0}else 46===n&&-1!==i?++i:i=-1}return r}var r={resolve:function(){for(var e,r="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var i;s>=0?i=arguments[s]:(void 0===e&&(e=process.cwd()),i=e),t(i),0!==i.length&&(r=i+"/"+r,o=47===i.charCodeAt(0))}return r=n(r,!o),o?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(e){if(t(e),0===e.length)return".";var r=47===e.charCodeAt(0),o=47===e.charCodeAt(e.length-1);return 0!==(e=n(e,!r)).length||r||(e="."),e.length>0&&o&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return t(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,n=0;n<arguments.length;++n){var o=arguments[n];t(o),o.length>0&&(void 0===e?e=o:e+="/"+o)}return void 0===e?".":r.normalize(e)},relative:function(e,n){if(t(e),t(n),e===n)return"";if((e=r.resolve(e))===(n=r.resolve(n)))return"";for(var o=1;o<e.length&&47===e.charCodeAt(o);++o);for(var s=e.length,i=s-o,a=1;a<n.length&&47===n.charCodeAt(a);++a);for(var l=n.length-a,c=i<l?i:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(a+g))return n.slice(a+g+1);if(0===g)return n.slice(a+g)}else i>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var u=e.charCodeAt(o+g);if(u!==n.charCodeAt(a+g))break;47===u&&(d=g)}var p="";for(g=o+d+1;g<=s;++g)g!==s&&47!==e.charCodeAt(g)||(0===p.length?p+="..":p+="/..");return p.length>0?p+n.slice(a+d):(a+=d,47===n.charCodeAt(a)&&++a,n.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var n=e.charCodeAt(0),r=47===n,o=-1,s=!0,i=e.length-1;i>=1;--i)if(47===(n=e.charCodeAt(i))){if(!s){o=i;break}}else s=!1;return-1===o?r?"/":".":r&&1===o?"//":e.slice(0,o)},basename:function(e,n){if(void 0!==n&&"string"!==typeof n)throw new TypeError('"ext" argument must be a string');t(e);var r,o=0,s=-1,i=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var a=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!i){o=r+1;break}}else-1===l&&(i=!1,l=r+1),a>=0&&(c===n.charCodeAt(a)?-1===--a&&(s=r):(a=-1,s=l))}return o===s?s=l:-1===s&&(s=e.length),e.slice(o,s)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!i){o=r+1;break}}else-1===s&&(i=!1,s=r+1);return-1===s?"":e.slice(o,s)},extname:function(e){t(e);for(var n=-1,r=0,o=-1,s=!0,i=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===o&&(s=!1,o=a+1),46===l?-1===n?n=a:1!==i&&(i=1):-1!==n&&(i=-1);else if(!s){r=a+1;break}}return-1===n||-1===o||0===i||1===i&&n===o-1&&n===r+1?"":e.slice(n,o)},format:function(e){if(null===e||"object"!==typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var n=t.dir||t.root,r=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+r:n+e+r:r}("/",e)},parse:function(e){t(e);var n={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return n;var r,o=e.charCodeAt(0),s=47===o;s?(n.root="/",r=1):r=0;for(var i=-1,a=0,l=-1,c=!0,d=e.length-1,g=0;d>=r;--d)if(47!==(o=e.charCodeAt(d)))-1===l&&(c=!1,l=d+1),46===o?-1===i?i=d:1!==g&&(g=1):-1!==i&&(g=-1);else if(!c){a=d+1;break}return-1===i||-1===l||0===g||1===g&&i===l-1&&i===a+1?-1!==l&&(n.base=n.name=0===a&&s?e.slice(1,l):e.slice(a,l)):(0===a&&s?(n.name=e.slice(1,i),n.base=e.slice(1,l)):(n.name=e.slice(a,i),n.base=e.slice(a,l)),n.ext=e.slice(i,l)),a>0?n.dir=e.slice(0,a-1):s&&(n.dir="/"),n},sep:"/",delimiter:":",win32:null,posix:null};r.posix=r,e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{new RegExp("[[(<=>!~;@]");class e{constructor(){this.promise=new Promise(((e,t)=>{this.resolveInternal=e,this.rejectInternal=t}))}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}}var t=n(56977),r=n.n(t);function o(e,t){const n=r().normalize(t),o=r().dirname(n).split("/"),s=[];for(const r of o){s.push(r);const t=s.join("/");if(e.FS.analyzePath(t).exists){if(e.FS.isDir(t))throw new Error(`"${t}" already exists and is not a directory.`)}else try{e.FS.mkdir(t)}catch(i){throw console.error(`Failed to create a directory "${t}"`),i}}}function s(e,t,n,r){o(e,t),e.FS.writeFile(t,n,r)}const i=new RegExp("[[(<=>!~;@]");function a(e){e.forEach((e=>{let t;try{t=new URL(e)}catch{return}if("emfs:"===t.protocol||"file:"===t.protocol)throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)}));return e.filter((e=>{const t="streamlit"===function(e){return e.split(i)[0].trim()}(e);return!t||(console.warn(`Streamlit is specified in the requirements ("${e}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1)}))}var l=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};function c(e,t){return l(this,void 0,void 0,(function*(){const{scriptURL:n,pyodideIndexURL:r,isESModule:o}=yield function(e){var t;return l(this,void 0,void 0,(function*(){const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(yield import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=yield import("node:path"),n=yield import("node:url");!e.includes("://")&&t.isAbsolute(e)&&(e=n.pathToFileURL(e).href)}return{scriptURL:e,pyodideIndexURL:o,isESModule:!0}}return{scriptURL:e,pyodideIndexURL:o,isESModule:!1}}))}(e);let s;if(o){s=(yield import(n)).loadPyodide}else importScripts(n),s=self.loadPyodide;return s(Object.assign(Object.assign({},t),{indexURL:r}))}))}var d=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};let g;function u(e,t,n){return d(this,void 0,void 0,(function*(){const r=n.map((t=>function(e,t){if(!g){const t='\nimport ast\nfrom textwrap import dedent\n\ndef find_imports(source: str) -> list[str]:\n source = dedent(source)\n\n try:\n mod = ast.parse(source)\n except SyntaxError:\n return []\n imports = set()\n for node in mod.body:\n if isinstance(node, ast.Import):\n for name in node.names:\n node_name = name.name\n imports.add(node_name.split(".")[0])\n elif isinstance(node, ast.ImportFrom):\n module_name = node.module\n if module_name is None:\n continue\n imports.add(module_name.split(".")[0])\n return imports\n';e.runPython(t),g=e.globals.get("find_imports")}return g(t).toJs()}(e,t))),o=function(e){const t=new Set;for(const n of e)for(const e of n)t.add(e);return t}(r),s=Array.from(o).filter((t=>!e.runPython(`__import__('importlib').util.find_spec('${t}')`))).map((t=>e._api._import_name_to_package_name.get(t))).filter((e=>e));if(0===s.length)return;const i=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:s}},i.port2);try{const t=yield e.loadPackage(s);return i.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void i.port1.close()}catch(a){throw i.port1.postMessage({type:"moduleAutoLoad:error",error:a}),i.port1.close(),a}}))}var p=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};const m=n.g;function f(e,t,n){const r=u(e,t,n);m.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const h=self.postMessage;self.onmessage=function(t,n,r){function i(e){n({type:"event:progress",data:{message:e}})}let l,d;const g=new e,u=function(){var e,o;return p(this,void 0,void 0,(function*(){const u=yield g.promise,h=Object.assign(Object.assign({},r),u);console.debug("Initial data",h);const{entrypoint:_,files:y,archives:v,requirements:b,prebuiltPackageNames:w,wheels:k,pyodideUrl:S=t,streamlitConfig:A,idbfsMountpoints:P,nodefsMountpoints:C,moduleAutoLoad:F}=h,x=a(b);i("Loading Pyodide."),console.debug("Loading Pyodide"),l=yield c(S,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let L=!1;P&&(L=!0,P.forEach((e=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.IDBFS,{},e)})),yield new Promise(((e,t)=>{l.FS.syncfs(!0,(n=>{n?t(n):e()}))}))),C&&Object.entries(C).forEach((([e,t])=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.NODEFS,{root:t},e)})),i("Mounting files.");const I=[];yield Promise.all(Object.keys(y).map((e=>p(this,void 0,void 0,(function*(){const t=y[e];let n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=yield fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=y[e];console.debug(`Write a file "${e}"`),s(l,e,n,r),e.endsWith(".py")&&I.push(e)}))))),i("Unpacking archives."),yield Promise.all(v.map((e=>p(this,void 0,void 0,(function*(){let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=yield fetch(e.url).then((e=>e.arrayBuffer()))):t=e.buffer;const{format:n,options:r}=e;console.debug("Unpack an archive",{format:n,options:r}),l.unpackArchive(t,n,r)}))))),yield l.loadPackage("micropip");const E=l.pyimport("micropip");if(i("Mocking some packages."),console.debug("Mock pyarrow"),function(e){e.runPython('\nimport micropip\nmicropip.add_mock_package(\n "pyarrow", "0.0.1",\n modules={\n "pyarrow": """\n__version__ = \'0.0.1\' # TODO: Update when releasing\n\n\nclass Table:\n @classmethod\n def from_pandas(*args, **kwargs):\n raise NotImplementedError("stlite is not supporting this method.")\n\n\nclass Array:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.Array")\n\n\nclass ChunkedArray:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")\n"""\n }\n)\n')}(l),console.debug("Mocked pyarrow"),i("Installing packages."),console.debug("Installing the prebuilt packages:",w),yield l.loadPackage(w),console.debug("Installed the prebuilt packages"),k?(console.debug("Installing the wheels:",k,"and the requirements:",x),yield E.install.callKwargs([k.stliteLib,k.streamlit,...x],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",x),yield E.install.callKwargs(x,{keep_going:!0}),console.debug("Installed the requirements")),F){const e=I.map((e=>l.FS.readFile(e,{encoding:"utf8"})));f(l,n,e)}yield l.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),i("Loading streamlit package."),console.debug("Loading the Streamlit package"),yield l.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),i("Setting up the loggers."),console.debug("Setting the loggers"),yield l.runPythonAsync('\nimport logging\nimport streamlit.logger\n\nstreamlit.logger.get_logger = logging.getLogger\nstreamlit.logger.setup_formatter = None\nstreamlit.logger.update_formatter = lambda *a, **k: None\nstreamlit.logger.set_log_level = lambda *a, **k: None\n\nfor name in streamlit.logger._loggers.keys():\n if name == "root":\n name = "streamlit"\n logger = logging.getLogger(name)\n logger.propagate = True\n logger.handlers.clear()\n logger.setLevel(logging.NOTSET)\n\nstreamlit.logger._loggers = {}\n');m.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},yield l.runPythonAsync('\ndef setup_loggers(streamlit_level, streamlit_message_format):\n from js import __logCallback__\n\n\n class JsHandler(logging.Handler):\n def emit(self, record):\n msg = self.format(record)\n __logCallback__(record.levelno, msg)\n\n\n root_message_format = "%(levelname)s:%(name)s:%(message)s"\n\n root_logger = logging.getLogger()\n root_logger.handlers.clear()\n root_formatter = logging.Formatter(root_message_format)\n root_handler = JsHandler()\n root_handler.setFormatter(root_formatter)\n root_logger.addHandler(root_handler)\n root_logger.setLevel(logging.DEBUG)\n\n streamlit_logger = logging.getLogger("streamlit")\n streamlit_logger.propagate = False\n streamlit_logger.handlers.clear()\n streamlit_formatter = logging.Formatter(streamlit_message_format)\n streamlit_handler = JsHandler()\n streamlit_handler.setFormatter(streamlit_formatter)\n streamlit_logger.addHandler(streamlit_handler)\n streamlit_logger.setLevel(streamlit_level.upper())\n');const O=(null!==(e=null===A||void 0===A?void 0:A["logger.level"])&&void 0!==e?e:"INFO").toString(),j=null!==(o=null===A||void 0===A?void 0:A["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(l.globals.get("setup_loggers")(O,j),console.debug("Set the loggers"),i("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),yield l.runPythonAsync("\nimport streamlit\n\ndef is_cacheable_msg(msg):\n return False\n\nstreamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg\n"),console.debug("Mocked some Streamlit functions"),L){i("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;m.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,l.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},yield l.runPythonAsync('\nfrom streamlit.runtime.app_session import AppSession\nfrom streamlit.runtime.scriptrunner import ScriptRunnerEvent\nfrom js import __scriptFinishedCallback__\n\ndef wrap_app_session_on_scriptrunner_event(original_method):\n def wrapped(self, *args, **kwargs):\n if "event" in kwargs:\n event = kwargs["event"]\n if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:\n __scriptFinishedCallback__()\n return original_method(self, *args, **kwargs)\n return wrapped\n\nAppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)\n'),console.debug("Set up the IndexedDB filesystem synchronizer")}return i("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),m.__streamlitFlagOptions__=Object.assign(Object.assign({"browser.gatherUsageStats":!1},A),{"runner.fastReruns":!1}),yield l.runPythonAsync(`\nfrom stlite_lib.bootstrap import load_config_options, prepare\nfrom stlite_lib.server import Server\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${_}"\nargs = []\n\nprepare(main_script_path, args)\n\nserver = Server(main_script_path)\nserver.start()\n`),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),d=l.globals.get("server").copy(),console.debug("Set up the HTTP server"),n({type:"event:loaded"}),h}))}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),e=>p(this,void 0,void 0,(function*(){const t=e.data;if("initData"===t.type)return void g.resolve(t.data);const{moduleAutoLoad:r}=yield u,i=e.ports[0];try{switch(t.type){case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;d.start_websocket(e,((e,t)=>{if(t){const t=e,r=t.getBuffer("u8");t.destroy();const o=new Uint8ClampedArray(r.data.buffer,r.data.byteOffset,r.data.byteLength);n({type:"websocket:message",data:{payload:new Uint8Array(o)}})}else{n({type:"websocket:message",data:{payload:e}})}})),i.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;d.receive_websocket_from_js(e);break}case"http:request":{console.debug("http:request",t.data);const{request:e}=t.data,n=(e,t,n)=>{const r=new Map(t.toJs()),o=n.toJs();console.debug({statusCode:e,headers:r,body:o});const s={type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}};i.postMessage(s)};d.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,n);break}case"file:write":{const{path:e,data:o,opts:a}=t.data;r&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),f(l,n,[o])),console.debug(`Write a file "${e}"`),s(l,e,o,a),i.postMessage({type:"reply"});break}case"file:rename":{const{oldPath:e,newPath:n}=t.data;console.debug(`Rename "${e}" to ${n}`),function(e,t,n){o(e,n),e.FS.rename(t,n)}(l,e,n),i.postMessage({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),l.FS.unlink(e),i.postMessage({type:"reply"});break}case"install":{const{requirements:e}=t.data,n=l.pyimport("micropip"),r=a(e);console.debug("Install the requirements:",r),yield n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),i.postMessage({type:"reply"})}))}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;const e=new Error(c.message);e.name=c.name,e.stack=c.stack,i.postMessage({type:"reply",error:e})}}))}("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js",((e,t)=>h(e,t?[t]:void 0)))})()})();
|