@stlite/desktop 0.71.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stlite/desktop",
3
- "version": "0.71.0",
3
+ "version": "0.72.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -69,9 +69,9 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@craco/craco": "^7.0.0",
72
- "@stlite/common": "^0.71.0",
73
- "@stlite/common-react": "^0.71.0",
74
- "@stlite/kernel": "^0.71.0",
72
+ "@stlite/common": "^0.72.1",
73
+ "@stlite/common-react": "^0.72.1",
74
+ "@stlite/kernel": "^0.72.1",
75
75
  "@streamlit/app": "1.39.0",
76
76
  "@testing-library/react": "^14.1.2",
77
77
  "@testing-library/user-event": "^14.0.0",
@@ -1 +0,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,a=-1,s=0,i=0;i<=e.length;++i){if(i<e.length)n=e.charCodeAt(i);else{if(47===n)break;n=47}if(47===n){if(a===i-1||1===s);else if(a!==i-1&&2===s){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("/"),a=i,s=0;continue}}else if(2===r.length||1===r.length){r="",o=0,a=i,s=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(a+1,i):r=e.slice(a+1,i),o=i-a-1;a=i,s=0}else 46===n&&-1!==s?++s:s=-1}return r}var r={resolve:function(){for(var e,r="",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&&(r=s+"/"+r,o=47===s.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 a=e.length,s=a-o,i=1;i<n.length&&47===n.charCodeAt(i);++i);for(var l=n.length-i,c=s<l?s:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(i+g))return n.slice(i+g+1);if(0===g)return n.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!==n.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+n.slice(i+d):(i+=d,47===n.charCodeAt(i)&&++i,n.slice(i))},_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,a=!0,s=e.length-1;s>=1;--s)if(47===(n=e.charCodeAt(s))){if(!a){o=s;break}}else a=!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,a=-1,s=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var i=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!s){o=r+1;break}}else-1===l&&(s=!1,l=r+1),i>=0&&(c===n.charCodeAt(i)?-1===--i&&(a=r):(i=-1,a=l))}return o===a?a=l:-1===a&&(a=e.length),e.slice(o,a)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!s){o=r+1;break}}else-1===a&&(s=!1,a=r+1);return-1===a?"":e.slice(o,a)},extname:function(e){t(e);for(var n=-1,r=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===n?n=i:1!==s&&(s=1):-1!==n&&(s=-1);else if(!a){r=i+1;break}}return-1===n||-1===o||0===s||1===s&&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),a=47===o;a?(n.root="/",r=1):r=0;for(var s=-1,i=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===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&&(n.base=n.name=0===i&&a?e.slice(1,l):e.slice(i,l)):(0===i&&a?(n.name=e.slice(1,s),n.base=e.slice(1,l)):(n.name=e.slice(i,s),n.base=e.slice(i,l)),n.ext=e.slice(s,l)),i>0?n.dir=e.slice(0,i-1):a&&(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 a=t[r]={exports:{}};return e[r](a,a.exports,n),a.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("/"),a=[];for(const r of o){a.push(r);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,n,r){o(e,t),e.FS.writeFile(t,n,r)}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:n,pyodideIndexURL:r,isESModule:o}=await async function(e){var t;const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(await import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=await import("node:path"),n=await 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 a;if(o){a=(await import(n)).loadPyodide}else importScripts(n),a=self.loadPyodide;return a({...t,indexURL:r})}let c;async function d(e,t,n){const r=n.map((t=>function(e,t){if(!c){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),c=e.globals.get("find_imports")}return c(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),a=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===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 g=n.g;function p(e,t,n){const r=d(e,t,n);g.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const u=self.postMessage;self.onmessage=function(t,n,r){function s(e){n({type:"event:progress",data:{message:e}})}let c,d;const u=new e,m=async function(){var e,o;const m=await u.promise,f={...r,...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:F}=f,C=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,(n=>{n?t(n):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 n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=await fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=_[e];console.debug(`Write a file "${e}"`),a(c,e,n,r),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:n,options:r}=e;console.debug("Unpack an archive",{format:n,options:r}),c.unpackArchive(t,n,r)}))),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:",C),await E.install.callKwargs([w.stliteLib,w.streamlit,...C],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",C),await E.install.callKwargs(C,{keep_going:!0}),console.debug("Installed the requirements")),F){const e=I.map((e=>c.FS.readFile(e,{encoding:"utf8"})));p(c,n,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'),g.__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 x=(null!==(e=null===S||void 0===S?void 0:S["logger.level"])&&void 0!==e?e:"INFO").toString(),R=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")(x,R),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;g.__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"),g.__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 d=O(h),await d.start(),console.debug("Booted up the Streamlit server"),n({type:"event:loaded"}),f}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),async e=>{const t=e.data;if("initData"===t.type)return void u.resolve(t.data);const{moduleAutoLoad:r}=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;d.stop(),console.debug("Booting up the Streamlit server");const n=c.pyimport("stlite_lib.server.Server");d=n(e),d.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;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}})}})),l({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}),l({type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}})};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:s}=t.data;r&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),p(c,n,[o])),console.debug(`Write a file "${e}"`),a(c,e,o,s),l({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)}(c,e,n),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:n}=t.data;console.debug(`Read "${e}"`);l({type:"reply:file:read",data:{content:c.FS.readFile(e,n)}});break}case"install":{const{requirements:e}=t.data,n=c.pyimport("micropip"),r=i(e);console.debug("Install the requirements:",r),await n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),l({type:"reply"})}))}}}catch(g){if(console.error(g),!(g instanceof Error))throw g;const e=new Error(g.message);e.name=g.name,e.stack=g.stack,l({type:"reply",error:e})}}}("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js",((e,t)=>u(e,t?[t]:void 0)))})()})();