@stlite/desktop 0.72.0 → 0.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/asset-manifest.json +3 -3
- package/build/electron/worker.js +11 -34
- package/build/index.html +1 -1
- package/build/static/js/8798.0ed7a8bc.chunk.js +1 -0
- package/build/static/js/{main.02fd259c.js → main.b7e36d5a.js} +2 -2
- package/package.json +4 -4
- package/wheels/streamlit-1.39.0-cp312-none-any.whl +0 -0
- package/build/static/js/8798.140e4c63.chunk.js +0 -1
- /package/build/static/js/{main.02fd259c.js.LICENSE.txt → main.b7e36d5a.js.LICENSE.txt} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "/static/css/main.43acb583.css",
|
|
4
|
-
"main.js": "/static/js/main.
|
|
5
|
-
"static/js/8798.
|
|
4
|
+
"main.js": "/static/js/main.b7e36d5a.js",
|
|
5
|
+
"static/js/8798.0ed7a8bc.chunk.js": "/static/js/8798.0ed7a8bc.chunk.js",
|
|
6
6
|
"static/js/4994.2d981099.chunk.js": "/static/js/4994.2d981099.chunk.js",
|
|
7
7
|
"static/js/3685.39209b63.chunk.js": "/static/js/3685.39209b63.chunk.js",
|
|
8
8
|
"static/js/4785.98dbde84.chunk.js": "/static/js/4785.98dbde84.chunk.js",
|
|
@@ -167,6 +167,6 @@
|
|
|
167
167
|
},
|
|
168
168
|
"entrypoints": [
|
|
169
169
|
"static/css/main.43acb583.css",
|
|
170
|
-
"static/js/main.
|
|
170
|
+
"static/js/main.b7e36d5a.js"
|
|
171
171
|
]
|
|
172
172
|
}
|
package/build/electron/worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).filter(e=>!e.startsWith("#")).map(e=>e.replace(
|
|
1
|
+
var fe=Object.create;var J=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var O=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var he=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of pe(e))!ye.call(r,o)&&o!==t&&J(r,o,{get:()=>e[o],enumerable:!(s=me(e,o))||s.enumerable});return r};var M=(r,e,t)=>(t=r!=null?fe(_e(r)):{},he(e||!r||!r.__esModule?J(t,"default",{value:r,enumerable:!0}):t,r));var K=O(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.validateRequirements=void 0;var ve="[",be="(<=>!~",Pe=";",Se="@",we=new RegExp(`[${ve+be+Pe+Se}]`);function ke(r){return r.split(we)[0].trim()}function Ae(r){return r.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>ke(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}C.validateRequirements=Ae});var V=O(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.parseRequirementsTxt=void 0;var Re=/\s#.*$/;function Fe(r){return r.split(`
|
|
2
|
+
`).filter(e=>!e.startsWith("#")).map(e=>e.replace(Re,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Fe});var X=O(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.PromiseDelegate=void 0;var U=class{promise;resolveInternal;rejectInternal;constructor(){this.promise=new Promise((e,t)=>{this.resolveInternal=e,this.rejectInternal=t})}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};N.PromiseDelegate=U});var G=O(P=>{"use strict";var Ie=P&&P.__createBinding||(Object.create?function(r,e,t,s){s===void 0&&(s=t);var o=Object.getOwnPropertyDescriptor(e,t);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,s,o)}:function(r,e,t,s){s===void 0&&(s=t),r[s]=e[t]}),q=P&&P.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Ie(e,r,t)};Object.defineProperty(P,"__esModule",{value:!0});q(K(),P);q(V(),P);q(X(),P)});var Z=O((Je,Y)=>{"use strict";function h(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Q(r,e){for(var t="",s=0,o=-1,i=0,n,a=0;a<=r.length;++a){if(a<r.length)n=r.charCodeAt(a);else{if(n===47)break;n=47}if(n===47){if(!(o===a-1||i===1))if(o!==a-1&&i===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var u=t.lastIndexOf("/");if(u!==t.length-1){u===-1?(t="",s=0):(t=t.slice(0,u),s=t.length-1-t.lastIndexOf("/")),o=a,i=0;continue}}else if(t.length===2||t.length===1){t="",s=0,o=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",s=2)}else t.length>0?t+="/"+r.slice(o+1,a):t=r.slice(o+1,a),s=a-o-1;o=a,i=0}else n===46&&i!==-1?++i:i=-1}return t}function Oe(r,e){var t=e.dir||e.root,s=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+s:t+r+s:s}var R={resolve:function(){for(var e="",t=!1,s,o=arguments.length-1;o>=-1&&!t;o--){var i;o>=0?i=arguments[o]:(s===void 0&&(s=process.cwd()),i=s),h(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=Q(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(h(e),e.length===0)return".";var t=e.charCodeAt(0)===47,s=e.charCodeAt(e.length-1)===47;return e=Q(e,!t),e.length===0&&!t&&(e="."),e.length>0&&s&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return h(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var s=arguments[t];h(s),s.length>0&&(e===void 0?e=s:e+="/"+s)}return e===void 0?".":R.normalize(e)},relative:function(e,t){if(h(e),h(t),e===t||(e=R.resolve(e),t=R.resolve(t),e===t))return"";for(var s=1;s<e.length&&e.charCodeAt(s)===47;++s);for(var o=e.length,i=o-s,n=1;n<t.length&&t.charCodeAt(n)===47;++n);for(var a=t.length,u=a-n,p=i<u?i:u,c=-1,l=0;l<=p;++l){if(l===p){if(u>p){if(t.charCodeAt(n+l)===47)return t.slice(n+l+1);if(l===0)return t.slice(n+l)}else i>p&&(e.charCodeAt(s+l)===47?c=l:l===0&&(c=0));break}var S=e.charCodeAt(s+l),w=t.charCodeAt(n+l);if(S!==w)break;S===47&&(c=l)}var _="";for(l=s+c+1;l<=o;++l)(l===o||e.charCodeAt(l)===47)&&(_.length===0?_+="..":_+="/..");return _.length>0?_+t.slice(n+c):(n+=c,t.charCodeAt(n)===47&&++n,t.slice(n))},_makeLong:function(e){return e},dirname:function(e){if(h(e),e.length===0)return".";for(var t=e.charCodeAt(0),s=t===47,o=-1,i=!0,n=e.length-1;n>=1;--n)if(t=e.charCodeAt(n),t===47){if(!i){o=n;break}}else i=!1;return o===-1?s?"/":".":s&&o===1?"//":e.slice(0,o)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');h(e);var s=0,o=-1,i=!0,n;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,u=-1;for(n=e.length-1;n>=0;--n){var p=e.charCodeAt(n);if(p===47){if(!i){s=n+1;break}}else u===-1&&(i=!1,u=n+1),a>=0&&(p===t.charCodeAt(a)?--a===-1&&(o=n):(a=-1,o=u))}return s===o?o=u:o===-1&&(o=e.length),e.slice(s,o)}else{for(n=e.length-1;n>=0;--n)if(e.charCodeAt(n)===47){if(!i){s=n+1;break}}else o===-1&&(i=!1,o=n+1);return o===-1?"":e.slice(s,o)}},extname:function(e){h(e);for(var t=-1,s=0,o=-1,i=!0,n=0,a=e.length-1;a>=0;--a){var u=e.charCodeAt(a);if(u===47){if(!i){s=a+1;break}continue}o===-1&&(i=!1,o=a+1),u===46?t===-1?t=a:n!==1&&(n=1):t!==-1&&(n=-1)}return t===-1||o===-1||n===0||n===1&&t===o-1&&t===s+1?"":e.slice(t,o)},format:function(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Oe("/",e)},parse:function(e){h(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var s=e.charCodeAt(0),o=s===47,i;o?(t.root="/",i=1):i=0;for(var n=-1,a=0,u=-1,p=!0,c=e.length-1,l=0;c>=i;--c){if(s=e.charCodeAt(c),s===47){if(!p){a=c+1;break}continue}u===-1&&(p=!1,u=c+1),s===46?n===-1?n=c:l!==1&&(l=1):n!==-1&&(l=-1)}return n===-1||u===-1||l===0||l===1&&n===u-1&&n===a+1?u!==-1&&(a===0&&o?t.base=t.name=e.slice(1,u):t.base=t.name=e.slice(a,u)):(a===0&&o?(t.name=e.slice(1,n),t.base=e.slice(1,u)):(t.name=e.slice(a,n),t.base=e.slice(a,u)),t.ext=e.slice(n,u)),a>0?t.dir=e.slice(0,a-1):o&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};R.posix=R;Y.exports=R});var W=require("node:worker_threads");var ie=M(G());var x=M(Z());function ee(r,e){let t=x.default.normalize(e),o=x.default.dirname(t).split("/"),i=[];for(let n of o){i.push(n);let a=i.join("/");if(r.FS.analyzePath(a).exists){if(r.FS.isDir(a))throw new Error(`"${a}" already exists and is not a directory.`);continue}try{r.FS.mkdir(a)}catch(u){throw console.error(`Failed to create a directory "${a}"`),u}}}function $(r,e,t,s){ee(r,e),r.FS.writeFile(e,t,s)}function te(r,e,t){ee(r,t),r.FS.rename(e,t)}var Me="[",Le="(<=>!~",Ee=";",Ce="@",Te=new RegExp(`[${Me+Le+Ee+Ce}]`);function Ne(r){return r.split(Te)[0].trim()}function j(r){return r.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>Ne(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function De(r){let e=typeof process<"u"&&process.versions?.node,t;e?t=(await import("node:path")).sep:t="/";let s=r.slice(0,r.lastIndexOf(t)+1);if(r.endsWith(".mjs")){if(e){let o=await import("node:path"),i=await import("node:url");!r.includes("://")&&o.isAbsolute(r)&&(r=i.pathToFileURL(r).href)}return{scriptURL:r,pyodideIndexURL:s,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:s,isESModule:!1}}async function re(r,e){let{scriptURL:t,pyodideIndexURL:s,isESModule:o}=await De(r),i;return o?i=(await import(t)).loadPyodide:(importScripts(t),i=self.loadPyodide),i({...e,indexURL:s})}function oe(r){r.runPython(`
|
|
3
3
|
import micropip
|
|
4
4
|
micropip.add_mock_package(
|
|
5
5
|
"pyarrow", "0.0.1",
|
|
@@ -25,40 +25,17 @@ class ChunkedArray:
|
|
|
25
25
|
"""
|
|
26
26
|
}
|
|
27
27
|
)
|
|
28
|
-
`)}var
|
|
29
|
-
import ast
|
|
30
|
-
from textwrap import dedent
|
|
31
|
-
|
|
32
|
-
def find_imports(source: str) -> list[str]:
|
|
33
|
-
source = dedent(source)
|
|
34
|
-
|
|
35
|
-
try:
|
|
36
|
-
mod = ast.parse(source)
|
|
37
|
-
except SyntaxError:
|
|
38
|
-
return []
|
|
39
|
-
imports = set()
|
|
40
|
-
for node in mod.body:
|
|
41
|
-
if isinstance(node, ast.Import):
|
|
42
|
-
for name in node.names:
|
|
43
|
-
node_name = name.name
|
|
44
|
-
imports.add(node_name.split(".")[0])
|
|
45
|
-
elif isinstance(node, ast.ImportFrom):
|
|
46
|
-
module_name = node.module
|
|
47
|
-
if module_name is None:
|
|
48
|
-
continue
|
|
49
|
-
imports.add(module_name.split(".")[0])
|
|
50
|
-
return imports
|
|
51
|
-
`),W=r.globals.get("find_imports")),W(e).toJs()}function qe(r){let e=new Set;for(let t of r)for(let n of t)e.add(n);return e}async function se(r,e,t){let n=t.map(f=>xe(r,f)),o=qe(n),a=Array.from(o).filter(f=>!r.runPython(`__import__('importlib').util.find_spec('${f}')`)).map(f=>r._api._import_name_to_package_name.get(f)).filter(f=>f);if(a.length===0)return;let c=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},c.port2);try{let f=await r.loadPackage(a);c.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:f}}),c.port1.close();return}catch(f){throw c.port1.postMessage({type:"moduleAutoLoad:error",error:f}),c.port1.close(),f}}var D=global;function ie(r,e,t){let n=se(r,e,t);D.__moduleAutoLoadPromise__=n,r.runPythonAsync(`
|
|
28
|
+
`)}async function se(r,e,t){let s=r.pyimport("pyodide"),o=c=>s.code.find_imports(c).toJs(),i=t.map(c=>o(c)),u=Array.from(new Set(i.flat())).filter(c=>!r.runPython(`__import__('importlib').util.find_spec('${c}')`)).map(c=>r._api._import_name_to_package_name.get(c)).filter(c=>c);if(u.length===0)return;let p=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:u}},p.port2);try{let c=await r.loadPackage(u);p.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:c}}),p.port1.close();return}catch(c){throw p.port1.postMessage({type:"moduleAutoLoad:error",error:c}),p.port1.close(),c}}var D=global;function ne(r,e,t){let s=se(r,e,t);D.__moduleAutoLoadPromise__=s,r.runPythonAsync(`
|
|
52
29
|
from streamlit.runtime.scriptrunner import script_runner
|
|
53
30
|
from js import __moduleAutoLoadPromise__
|
|
54
31
|
|
|
55
32
|
script_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__
|
|
56
|
-
`)}function
|
|
33
|
+
`)}function ae(r,e,t){function s(c){e({type:"event:progress",data:{message:c}})}let o,i,n=new ie.PromiseDelegate;async function a(){let c=await n.promise,l={...t,...c};console.debug("Initial data",l);let{entrypoint:S,files:w,archives:_,requirements:d,prebuiltPackageNames:f,wheels:y,pyodideUrl:k=r,streamlitConfig:v,idbfsMountpoints:A,nodefsMountpoints:F,moduleAutoLoad:ce}=l,L=j(d);s("Loading Pyodide."),console.debug("Loading Pyodide"),o=await re(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let B=!1;A&&(B=!0,A.forEach(g=>{o.FS.mkdir(g),o.FS.mount(o.FS.filesystems.IDBFS,{},g)}),await new Promise((g,m)=>{o.FS.syncfs(!0,b=>{b?m(b):g()})})),F&&Object.entries(F).forEach(([g,m])=>{o.FS.mkdir(g),o.FS.mount(o.FS.filesystems.NODEFS,{root:m},g)}),s("Mounting files.");let H=[];await Promise.all(Object.keys(w).map(async g=>{let m=w[g],b;"url"in m?(console.debug(`Fetch a file from ${m.url}`),b=await fetch(m.url).then(I=>I.arrayBuffer()).then(I=>new Uint8Array(I))):b=m.data;let{opts:E}=w[g];console.debug(`Write a file "${g}"`),$(o,g,b,E),g.endsWith(".py")&&H.push(g)})),s("Unpacking archives."),await Promise.all(_.map(async g=>{let m;"url"in g?(console.debug(`Fetch an archive from ${g.url}`),m=await fetch(g.url).then(I=>I.arrayBuffer())):m=g.buffer;let{format:b,options:E}=g;console.debug("Unpack an archive",{format:b,options:E}),o.unpackArchive(m,b,E)})),await o.loadPackage("micropip");let z=o.pyimport("micropip");if(s("Mocking some packages."),console.debug("Mock pyarrow"),oe(o),console.debug("Mocked pyarrow"),s("Installing packages."),console.debug("Installing the prebuilt packages:",f),await o.loadPackage(f),console.debug("Installed the prebuilt packages"),y?(console.debug("Installing the wheels:",y,"and the requirements:",L),await z.install.callKwargs([y.stliteLib,y.streamlit,...L],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",L),await z.install.callKwargs(L,{keep_going:!0}),console.debug("Installed the requirements")),ce){let g=H.map(m=>o.FS.readFile(m,{encoding:"utf8"}));ne(o,e,g)}await o.runPythonAsync(`
|
|
57
34
|
import importlib
|
|
58
35
|
importlib.invalidate_caches()
|
|
59
|
-
`),
|
|
36
|
+
`),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await o.runPythonAsync(`
|
|
60
37
|
import streamlit.runtime
|
|
61
|
-
`),console.debug("Loaded the Streamlit package"),
|
|
38
|
+
`),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await o.runPythonAsync(`
|
|
62
39
|
import logging
|
|
63
40
|
import streamlit.logger
|
|
64
41
|
|
|
@@ -76,7 +53,7 @@ for name in streamlit.logger._loggers.keys():
|
|
|
76
53
|
logger.setLevel(logging.NOTSET)
|
|
77
54
|
|
|
78
55
|
streamlit.logger._loggers = {}
|
|
79
|
-
`);let
|
|
56
|
+
`);let de=(g,m)=>{g>=40?console.error(m):g>=30?console.warn(m):g>=20?console.info(m):console.debug(m)};D.__logCallback__=de,await o.runPythonAsync(`
|
|
80
57
|
def setup_loggers(streamlit_level, streamlit_message_format):
|
|
81
58
|
from js import __logCallback__
|
|
82
59
|
|
|
@@ -105,14 +82,14 @@ def setup_loggers(streamlit_level, streamlit_message_format):
|
|
|
105
82
|
streamlit_handler.setFormatter(streamlit_formatter)
|
|
106
83
|
streamlit_logger.addHandler(streamlit_handler)
|
|
107
84
|
streamlit_logger.setLevel(streamlit_level.upper())
|
|
108
|
-
`);let
|
|
85
|
+
`);let ue=(v?.["logger.level"]??"INFO").toString(),ge=v?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(o.globals.get("setup_loggers")(ue,ge),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await o.runPythonAsync(`
|
|
109
86
|
import streamlit
|
|
110
87
|
|
|
111
88
|
def is_cacheable_msg(msg):
|
|
112
89
|
return False
|
|
113
90
|
|
|
114
91
|
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
|
|
115
|
-
`),console.debug("Mocked some Streamlit functions"),
|
|
92
|
+
`),console.debug("Mocked some Streamlit functions"),B){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let g=!1;D.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),g||(g=!0,o.FS.syncfs(!1,m=>{g=!1,m&&console.error(m)}))},await o.runPythonAsync(`
|
|
116
93
|
from streamlit.runtime.app_session import AppSession
|
|
117
94
|
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
|
|
118
95
|
from js import __scriptFinishedCallback__
|
|
@@ -127,7 +104,7 @@ def wrap_app_session_on_scriptrunner_event(original_method):
|
|
|
127
104
|
return wrapped
|
|
128
105
|
|
|
129
106
|
AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
|
|
130
|
-
`),console.debug("Set up the IndexedDB filesystem synchronizer")}return
|
|
107
|
+
`),console.debug("Set up the IndexedDB filesystem synchronizer")}return s("Booting up the Streamlit server."),console.debug("Setting up the Streamlit configuration"),D.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...v,"runner.fastReruns":!1},await o.runPythonAsync(`
|
|
131
108
|
from stlite_lib.bootstrap import load_config_options, prepare
|
|
132
109
|
from js import __streamlitFlagOptions__
|
|
133
110
|
|
|
@@ -138,4 +115,4 @@ main_script_path = "${S}"
|
|
|
138
115
|
args = []
|
|
139
116
|
|
|
140
117
|
prepare(main_script_path, args)
|
|
141
|
-
`),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(S),await i.start(),console.debug("Booted up the Streamlit server"),e({type:"event:loaded"}),l}let
|
|
118
|
+
`),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(S),await i.start(),console.debug("Booted up the Streamlit server"),e({type:"event:loaded"}),l}let u=a().catch(c=>{throw e({type:"event:error",data:{error:c}}),c}),p=async c=>{let l=c.data;if(l.type==="initData"){n.resolve(l.data);return}let{moduleAutoLoad:S}=await u,w=c.ports[0];function _(d){w.postMessage(d)}try{switch(l.type){case"reboot":{console.debug("Reboot the Streamlit server",l.data);let{entrypoint:d}=l.data;i.stop(),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(d),i.start(),console.debug("Booted up the Streamlit server"),_({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:d}=l.data;i.start_websocket(d,(f,y)=>{if(y){let k=f,v=k.getBuffer("u8");k.destroy();let A=new Uint8ClampedArray(v.data.buffer,v.data.byteOffset,v.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(A)}})}else e({type:"websocket:message",data:{payload:f}})}),_({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",l.data);let{payload:d}=l.data;i.receive_websocket_from_js(d);break}case"http:request":{console.debug("http:request",l.data);let{request:d}=l.data,f=(y,k,v)=>{let A=new Map(k.toJs()),F=v.toJs();console.debug({statusCode:y,headers:A,body:F}),_({type:"http:response",data:{response:{statusCode:y,headers:A,body:F}}})};i.receive_http_from_js(d.method,decodeURIComponent(d.path),d.headers,d.body,f);break}case"file:write":{let{path:d,data:f,opts:y}=l.data;S&&typeof f=="string"&&d.endsWith(".py")&&(console.debug(`Auto install the requirements in ${d}`),ne(o,e,[f])),console.debug(`Write a file "${d}"`),$(o,d,f,y),_({type:"reply"});break}case"file:rename":{let{oldPath:d,newPath:f}=l.data;console.debug(`Rename "${d}" to ${f}`),te(o,d,f),_({type:"reply"});break}case"file:unlink":{let{path:d}=l.data;console.debug(`Remove "${d}`),o.FS.unlink(d),_({type:"reply"});break}case"file:read":{let{path:d,opts:f}=l.data;console.debug(`Read "${d}"`);let y=o.FS.readFile(d,f);_({type:"reply:file:read",data:{content:y}});break}case"install":{let{requirements:d}=l.data,f=o.pyimport("micropip"),y=j(d);console.debug("Install the requirements:",y),await f.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),_({type:"reply"})})}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;let f=new Error(d.message);f.name=d.name,f.stack=d.stack,_({type:"reply",error:f})}};return e({type:"event:start"}),p}function le(){let r=process.env.NODEFS_MOUNTPOINTS;if(!r)return;let e;try{e=JSON.parse(r)}catch{console.error(`Failed to parse NODEFS_MOUNTPOINTS as JSON: ${r}`);return}if(typeof e!="object"){console.error(`NODEFS_MOUNTPOINTS is not an object: ${r}`);return}if(Array.isArray(e)){console.error(`NODEFS_MOUNTPOINTS is an array: ${r}`);return}if(Object.keys(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string keys: ${r}`);return}if(Object.values(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string values: ${r}`);return}return e}var Ue=r=>{console.debug("[worker thread] postMessage from worker",r),W.parentPort?.postMessage(r)},qe=ae(process.env.PYODIDE_URL,Ue,{nodefsMountpoints:le()});W.parentPort?.on("message",({data:r,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:r,port:e}),qe({data:r,ports:[e]})});
|
package/build/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>stlite</title><meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'wasm-unsafe-eval' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; script-src-elem 'self' 'unsafe-inline' https:; style-src-elem 'self' 'unsafe-inline' https:; font-src 'self' data: https:; connect-src https://data.streamlit.io/ https://*.mapbox.com/ 'self' https: data:; img-src https: blob: data: file:; media-src https: blob:; frame-src https:"><script defer="defer" src="/static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>stlite</title><meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'wasm-unsafe-eval' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; script-src-elem 'self' 'unsafe-inline' https:; style-src-elem 'self' 'unsafe-inline' https:; font-src 'self' data: https:; connect-src https://data.streamlit.io/ https://*.mapbox.com/ 'self' https: data:; img-src https: blob: data: file:; media-src https: blob:; frame-src https:"><script defer="defer" src="/static/js/main.b7e36d5a.js"></script><link href="/static/css/main.43acb583.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
|
@@ -0,0 +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 r(e,t){for(var r,n="",o=0,a=-1,s=0,i=0;i<=e.length;++i){if(i<e.length)r=e.charCodeAt(i);else{if(47===r)break;r=47}if(47===r){if(a===i-1||1===s);else if(a!==i-1&&2===s){if(n.length<2||2!==o||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var l=n.lastIndexOf("/");if(l!==n.length-1){-1===l?(n="",o=0):o=(n=n.slice(0,l)).length-1-n.lastIndexOf("/"),a=i,s=0;continue}}else if(2===n.length||1===n.length){n="",o=0,a=i,s=0;continue}t&&(n.length>0?n+="/..":n="..",o=2)}else n.length>0?n+="/"+e.slice(a+1,i):n=e.slice(a+1,i),o=i-a-1;a=i,s=0}else 46===r&&-1!==s?++s:s=-1}return n}var n={resolve:function(){for(var e,n="",o=!1,a=arguments.length-1;a>=-1&&!o;a--){var s;a>=0?s=arguments[a]:(void 0===e&&(e=process.cwd()),s=e),t(s),0!==s.length&&(n=s+"/"+n,o=47===s.charCodeAt(0))}return n=r(n,!o),o?n.length>0?"/"+n:"/":n.length>0?n:"."},normalize:function(e){if(t(e),0===e.length)return".";var n=47===e.charCodeAt(0),o=47===e.charCodeAt(e.length-1);return 0!==(e=r(e,!n)).length||n||(e="."),e.length>0&&o&&(e+="/"),n?"/"+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,r=0;r<arguments.length;++r){var o=arguments[r];t(o),o.length>0&&(void 0===e?e=o:e+="/"+o)}return void 0===e?".":n.normalize(e)},relative:function(e,r){if(t(e),t(r),e===r)return"";if((e=n.resolve(e))===(r=n.resolve(r)))return"";for(var o=1;o<e.length&&47===e.charCodeAt(o);++o);for(var a=e.length,s=a-o,i=1;i<r.length&&47===r.charCodeAt(i);++i);for(var l=r.length-i,c=s<l?s:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===r.charCodeAt(i+g))return r.slice(i+g+1);if(0===g)return r.slice(i+g)}else s>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var p=e.charCodeAt(o+g);if(p!==r.charCodeAt(i+g))break;47===p&&(d=g)}var u="";for(g=o+d+1;g<=a;++g)g!==a&&47!==e.charCodeAt(g)||(0===u.length?u+="..":u+="/..");return u.length>0?u+r.slice(i+d):(i+=d,47===r.charCodeAt(i)&&++i,r.slice(i))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var r=e.charCodeAt(0),n=47===r,o=-1,a=!0,s=e.length-1;s>=1;--s)if(47===(r=e.charCodeAt(s))){if(!a){o=s;break}}else a=!1;return-1===o?n?"/":".":n&&1===o?"//":e.slice(0,o)},basename:function(e,r){if(void 0!==r&&"string"!==typeof r)throw new TypeError('"ext" argument must be a string');t(e);var n,o=0,a=-1,s=!0;if(void 0!==r&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var i=r.length-1,l=-1;for(n=e.length-1;n>=0;--n){var c=e.charCodeAt(n);if(47===c){if(!s){o=n+1;break}}else-1===l&&(s=!1,l=n+1),i>=0&&(c===r.charCodeAt(i)?-1===--i&&(a=n):(i=-1,a=l))}return o===a?a=l:-1===a&&(a=e.length),e.slice(o,a)}for(n=e.length-1;n>=0;--n)if(47===e.charCodeAt(n)){if(!s){o=n+1;break}}else-1===a&&(s=!1,a=n+1);return-1===a?"":e.slice(o,a)},extname:function(e){t(e);for(var r=-1,n=0,o=-1,a=!0,s=0,i=e.length-1;i>=0;--i){var l=e.charCodeAt(i);if(47!==l)-1===o&&(a=!1,o=i+1),46===l?-1===r?r=i:1!==s&&(s=1):-1!==r&&(s=-1);else if(!a){n=i+1;break}}return-1===r||-1===o||0===s||1===s&&r===o-1&&r===n+1?"":e.slice(r,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 r=t.dir||t.root,n=t.base||(t.name||"")+(t.ext||"");return r?r===t.root?r+n:r+e+n:n}("/",e)},parse:function(e){t(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return r;var n,o=e.charCodeAt(0),a=47===o;a?(r.root="/",n=1):n=0;for(var s=-1,i=0,l=-1,c=!0,d=e.length-1,g=0;d>=n;--d)if(47!==(o=e.charCodeAt(d)))-1===l&&(c=!1,l=d+1),46===o?-1===s?s=d:1!==g&&(g=1):-1!==s&&(g=-1);else if(!c){i=d+1;break}return-1===s||-1===l||0===g||1===g&&s===l-1&&s===i+1?-1!==l&&(r.base=r.name=0===i&&a?e.slice(1,l):e.slice(i,l)):(0===i&&a?(r.name=e.slice(1,s),r.base=e.slice(1,l)):(r.name=e.slice(i,s),r.base=e.slice(i,l)),r.ext=e.slice(s,l)),i>0?r.dir=e.slice(0,i-1):a&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};n.posix=n,e.exports=n}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}(),r.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=r(56977),n=r.n(t);function o(e,t){const r=n().normalize(t),o=n().dirname(r).split("/"),a=[];for(const n of o){a.push(n);const t=a.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(s){throw console.error(`Failed to create a directory "${t}"`),s}}}function a(e,t,r,n){o(e,t),e.FS.writeFile(t,r,n)}const s=new RegExp("[[(<=>!~;@]");function i(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(s)[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)}))}async function l(e,t){const{scriptURL:r,pyodideIndexURL:n,isESModule:o}=await async function(e){var t;const r="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let n;n=r?(await import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(n)+1);if(e.endsWith(".mjs")){if(r){const t=await import("node:path"),r=await import("node:url");!e.includes("://")&&t.isAbsolute(e)&&(e=r.pathToFileURL(e).href)}return{scriptURL:e,pyodideIndexURL:o,isESModule:!0}}return{scriptURL:e,pyodideIndexURL:o,isESModule:!1}}(e);let a;if(o){a=(await import(r)).loadPyodide}else importScripts(r),a=self.loadPyodide;return a({...t,indexURL:n})}async function c(e,t,r){const n=e.pyimport("pyodide"),o=r.map((e=>(e=>n.code.find_imports(e).toJs())(e))),a=Array.from(new Set(o.flat())).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===a.length)return;const s=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},s.port2);try{const t=await e.loadPackage(a);return s.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void s.port1.close()}catch(i){throw s.port1.postMessage({type:"moduleAutoLoad:error",error:i}),s.port1.close(),i}}const d=r.g;function g(e,t,r){const n=c(e,t,r);d.__moduleAutoLoadPromise__=n,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const p=self.postMessage;self.onmessage=function(t,r,n){function s(e){r({type:"event:progress",data:{message:e}})}let c,p;const u=new e,m=async function(){var e,o;const m=await u.promise,f={...n,...m};console.debug("Initial data",f);const{entrypoint:h,files:_,archives:y,requirements:b,prebuiltPackageNames:v,wheels:w,pyodideUrl:k=t,streamlitConfig:S,idbfsMountpoints:A,nodefsMountpoints:P,moduleAutoLoad:C}=f,F=i(b);s("Loading Pyodide."),console.debug("Loading Pyodide"),c=await l(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let L=!1;A&&(L=!0,A.forEach((e=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.IDBFS,{},e)})),await new Promise(((e,t)=>{c.FS.syncfs(!0,(r=>{r?t(r):e()}))}))),P&&Object.entries(P).forEach((([e,t])=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.NODEFS,{root:t},e)})),s("Mounting files.");const I=[];await Promise.all(Object.keys(_).map((async e=>{const t=_[e];let r;"url"in t?(console.debug(`Fetch a file from ${t.url}`),r=await fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):r=t.data;const{opts:n}=_[e];console.debug(`Write a file "${e}"`),a(c,e,r,n),e.endsWith(".py")&&I.push(e)}))),s("Unpacking archives."),await Promise.all(y.map((async e=>{let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=await fetch(e.url).then((e=>e.arrayBuffer()))):t=e.buffer;const{format:r,options:n}=e;console.debug("Unpack an archive",{format:r,options:n}),c.unpackArchive(t,r,n)}))),await c.loadPackage("micropip");const E=c.pyimport("micropip");if(s("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')}(c),console.debug("Mocked pyarrow"),s("Installing packages."),console.debug("Installing the prebuilt packages:",v),await c.loadPackage(v),console.debug("Installed the prebuilt packages"),w?(console.debug("Installing the wheels:",w,"and the requirements:",F),await E.install.callKwargs([w.stliteLib,w.streamlit,...F],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",F),await E.install.callKwargs(F,{keep_going:!0}),console.debug("Installed the requirements")),C){const e=I.map((e=>c.FS.readFile(e,{encoding:"utf8"})));g(c,r,e)}await c.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await c.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await c.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'),d.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},await c.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 R=(null!==(e=null===S||void 0===S?void 0:S["logger.level"])&&void 0!==e?e:"INFO").toString(),x=null!==(o=null===S||void 0===S?void 0:S["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(c.globals.get("setup_loggers")(R,x),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await c.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){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;d.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,c.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},await c.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")}s("Booting up the Streamlit server."),console.debug("Setting up the Streamlit configuration"),d.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...S,"runner.fastReruns":!1},await c.runPythonAsync(`\nfrom stlite_lib.bootstrap import load_config_options, prepare\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${h}"\nargs = []\n\nprepare(main_script_path, args)\n`),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server");const O=c.pyimport("stlite_lib.server.Server");return p=O(h),await p.start(),console.debug("Booted up the Streamlit server"),r({type:"event:loaded"}),f}().catch((e=>{throw r({type:"event:error",data:{error:e}}),e}));return r({type:"event:start"}),async e=>{const t=e.data;if("initData"===t.type)return void u.resolve(t.data);const{moduleAutoLoad:n}=await m,s=e.ports[0];function l(e){s.postMessage(e)}try{switch(t.type){case"reboot":{console.debug("Reboot the Streamlit server",t.data);const{entrypoint:e}=t.data;p.stop(),console.debug("Booting up the Streamlit server");const r=c.pyimport("stlite_lib.server.Server");p=r(e),p.start(),console.debug("Booted up the Streamlit server"),l({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;p.start_websocket(e,((e,t)=>{if(t){const t=e,n=t.getBuffer("u8");t.destroy();const o=new Uint8ClampedArray(n.data.buffer,n.data.byteOffset,n.data.byteLength);r({type:"websocket:message",data:{payload:new Uint8Array(o)}})}else{r({type:"websocket:message",data:{payload:e}})}})),l({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;p.receive_websocket_from_js(e);break}case"http:request":{console.debug("http:request",t.data);const{request:e}=t.data,r=(e,t,r)=>{const n=new Map(t.toJs()),o=r.toJs();console.debug({statusCode:e,headers:n,body:o}),l({type:"http:response",data:{response:{statusCode:e,headers:n,body:o}}})};p.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,r);break}case"file:write":{const{path:e,data:o,opts:s}=t.data;n&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),g(c,r,[o])),console.debug(`Write a file "${e}"`),a(c,e,o,s),l({type:"reply"});break}case"file:rename":{const{oldPath:e,newPath:r}=t.data;console.debug(`Rename "${e}" to ${r}`),function(e,t,r){o(e,r),e.FS.rename(t,r)}(c,e,r),l({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),c.FS.unlink(e),l({type:"reply"});break}case"file:read":{const{path:e,opts:r}=t.data;console.debug(`Read "${e}"`);l({type:"reply:file:read",data:{content:c.FS.readFile(e,r)}});break}case"install":{const{requirements:e}=t.data,r=c.pyimport("micropip"),n=i(e);console.debug("Install the requirements:",n),await r.install.callKwargs(n,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),l({type:"reply"})}))}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;const e=new Error(d.message);e.name=d.name,e.stack=d.stack,l({type:"reply",error:e})}}}("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js",((e,t)=>p(e,t?[t]:void 0)))})()})();
|