@stlite/desktop 0.49.4 → 0.50.0

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.49.4",
3
+ "version": "0.50.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "/",
6
6
  "main": "./build/electron/main.js",
@@ -60,9 +60,9 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@craco/craco": "^7.0.0",
63
- "@stlite/common": "^0.49.4",
64
- "@stlite/common-react": "^0.49.4",
65
- "@stlite/kernel": "^0.49.4",
63
+ "@stlite/common": "^0.50.0",
64
+ "@stlite/common-react": "^0.50.0",
65
+ "@stlite/kernel": "^0.50.0",
66
66
  "@streamlit/app": "1.32.2",
67
67
  "@testing-library/react": "^14.1.2",
68
68
  "@testing-library/user-event": "^14.0.0",
@@ -101,7 +101,10 @@
101
101
  },
102
102
  "stlite": {
103
103
  "desktop": {
104
- "embed": true
104
+ "embed": true,
105
+ "idbfsMountpoints": [
106
+ "/mnt"
107
+ ]
105
108
  }
106
109
  }
107
110
  }
@@ -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 r(e,t){for(var r,n="",o=0,s=-1,a=0,l=0;l<=e.length;++l){if(l<e.length)r=e.charCodeAt(l);else{if(47===r)break;r=47}if(47===r){if(s===l-1||1===a);else if(s!==l-1&&2===a){if(n.length<2||2!==o||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var i=n.lastIndexOf("/");if(i!==n.length-1){-1===i?(n="",o=0):o=(n=n.slice(0,i)).length-1-n.lastIndexOf("/"),s=l,a=0;continue}}else if(2===n.length||1===n.length){n="",o=0,s=l,a=0;continue}t&&(n.length>0?n+="/..":n="..",o=2)}else n.length>0?n+="/"+e.slice(s+1,l):n=e.slice(s+1,l),o=l-s-1;s=l,a=0}else 46===r&&-1!==a?++a:a=-1}return n}var n={resolve:function(){for(var e,n="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var a;s>=0?a=arguments[s]:(void 0===e&&(e=process.cwd()),a=e),t(a),0!==a.length&&(n=a+"/"+n,o=47===a.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 s=e.length,a=s-o,l=1;l<r.length&&47===r.charCodeAt(l);++l);for(var i=r.length-l,c=a<i?a:i,g=-1,d=0;d<=c;++d){if(d===c){if(i>c){if(47===r.charCodeAt(l+d))return r.slice(l+d+1);if(0===d)return r.slice(l+d)}else a>c&&(47===e.charCodeAt(o+d)?g=d:0===d&&(g=0));break}var h=e.charCodeAt(o+d);if(h!==r.charCodeAt(l+d))break;47===h&&(g=d)}var p="";for(d=o+g+1;d<=s;++d)d!==s&&47!==e.charCodeAt(d)||(0===p.length?p+="..":p+="/..");return p.length>0?p+r.slice(l+g):(l+=g,47===r.charCodeAt(l)&&++l,r.slice(l))},_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,s=!0,a=e.length-1;a>=1;--a)if(47===(r=e.charCodeAt(a))){if(!s){o=a;break}}else s=!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,s=-1,a=!0;if(void 0!==r&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var l=r.length-1,i=-1;for(n=e.length-1;n>=0;--n){var c=e.charCodeAt(n);if(47===c){if(!a){o=n+1;break}}else-1===i&&(a=!1,i=n+1),l>=0&&(c===r.charCodeAt(l)?-1===--l&&(s=n):(l=-1,s=i))}return o===s?s=i:-1===s&&(s=e.length),e.slice(o,s)}for(n=e.length-1;n>=0;--n)if(47===e.charCodeAt(n)){if(!a){o=n+1;break}}else-1===s&&(a=!1,s=n+1);return-1===s?"":e.slice(o,s)},extname:function(e){t(e);for(var r=-1,n=0,o=-1,s=!0,a=0,l=e.length-1;l>=0;--l){var i=e.charCodeAt(l);if(47!==i)-1===o&&(s=!1,o=l+1),46===i?-1===r?r=l:1!==a&&(a=1):-1!==r&&(a=-1);else if(!s){n=l+1;break}}return-1===r||-1===o||0===a||1===a&&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),s=47===o;s?(r.root="/",n=1):n=0;for(var a=-1,l=0,i=-1,c=!0,g=e.length-1,d=0;g>=n;--g)if(47!==(o=e.charCodeAt(g)))-1===i&&(c=!1,i=g+1),46===o?-1===a?a=g:1!==d&&(d=1):-1!==a&&(d=-1);else if(!c){l=g+1;break}return-1===a||-1===i||0===d||1===d&&a===i-1&&a===l+1?-1!==i&&(r.base=r.name=0===l&&s?e.slice(1,i):e.slice(l,i)):(0===l&&s?(r.name=e.slice(1,a),r.base=e.slice(1,i)):(r.name=e.slice(l,a),r.base=e.slice(l,i)),r.ext=e.slice(a,i)),l>0?r.dir=e.slice(0,l-1):s&&(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 s=t[n]={exports:{}};return e[n](s,s.exports,r),s.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.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{function e(e){e.forEach((e=>{let t;try{t=new URL(e)}catch(r){return}if("emfs:"===t.protocol||"file:"===t.protocol)throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)}))}var t=r(56977),n=r.n(t);function o(e,t){const r=n().normalize(t),o=n().dirname(r).split("/"),s=[];for(const n of o){s.push(n);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(a){throw console.error(`Failed to create a directory "${t}"`),a}}}function s(e,t,r,n){o(e,t),e.FS.writeFile(t,r,n)}function a(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 }\n)\n')}var l=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function a(e){try{i(n.next(e))}catch(t){s(t)}}function l(e){try{i(n.throw(e))}catch(t){s(t)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}i((n=n.apply(e,t||[])).next())}))};let i,c;const g=self,d=new class{constructor(){this.promise=new Promise(((e,t)=>{this.resolveInternal=e,this.rejectInternal=t}))}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};function h(e){g.postMessage({type:"event:progress",data:{message:e}})}const p="https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js";const u=function(){var t,r;return l(this,void 0,void 0,(function*(){const{entrypoint:n,files:o,archives:u,requirements:m,wheels:f,mountedSitePackagesSnapshotFilePath:_,pyodideUrl:y=p,streamlitConfig:v}=yield d.promise;if(h("Loading Pyodide."),console.debug("Loading Pyodide"),i=yield function(e,t){return l(this,void 0,void 0,(function*(){const r=e.slice(0,e.lastIndexOf("/")+1);let n;return e.endsWith(".mjs")?n=(yield import(e)).loadPyodide:(importScripts(e),n=self.loadPyodide),n(Object.assign(Object.assign({},t),{indexURL:r}))}))}(y,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide"),h("Mounting files."),yield Promise.all(Object.keys(o).map((e=>l(this,void 0,void 0,(function*(){const t=o[e];let r;"url"in t?(console.debug(`Fetch a file from ${t.url}`),r=yield fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):r=t.data;const{opts:n}=o[e];console.debug(`Write a file "${e}"`),s(i,e,r,n)}))))),h("Unpacking archives."),yield Promise.all(u.map((e=>l(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:r,options:n}=e;console.debug("Unpack an archive",{format:r,options:n}),i.unpackArchive(t,r,n)}))))),!_&&!f)throw new Error("Neither snapshot nor wheel files are provided.");_&&(h("Restoring the snapshot."),yield i.runPythonAsync("import tarfile, shutil, site"),yield i.runPythonAsync("\n site_packages_dirs = site.getsitepackages()\n for site_packages in site_packages_dirs:\n shutil.rmtree(site_packages)\n "),console.debug(`Unarchive ${_}`),yield i.runPythonAsync(`\n with tarfile.open("${_}", "r") as tar_gz_file:\n tar_gz_file.extractall("/")\n `),console.debug("Restored the snapshot"),h("Mocking some packages."),console.debug("Mock pyarrow"),a(i),console.debug("Mocked pyarrow")),e(m),h("Installing packages."),yield i.loadPackage("micropip");const b=i.pyimport("micropip");f?(console.debug("Installing the wheels:",f,"and the requirements:",m),yield b.install.callKwargs([f.stliteServer,f.streamlit,...m],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),h("Mocking some packages."),console.debug("Mock pyarrow"),a(i),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",m),yield b.install.callKwargs(m,{keep_going:!0}),console.debug("Installed the requirements")),yield i.runPythonAsync("\n import importlib\n importlib.invalidate_caches()\n "),h("Loading streamlit package."),console.debug("Loading the Streamlit package"),yield i.runPythonAsync("\n import streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),h("Setting up the loggers."),console.debug("Setting the loggers"),yield i.runPythonAsync('\n import logging\n import streamlit.logger\n\n streamlit.logger.get_logger = logging.getLogger\n streamlit.logger.setup_formatter = None\n streamlit.logger.update_formatter = lambda *a, **k: None\n streamlit.logger.set_log_level = lambda *a, **k: None\n\n for 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\n streamlit.logger._loggers = {}\n ');self.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},yield i.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 k=(null!==(t=null===v||void 0===v?void 0:v["logger.level"])&&void 0!==t?t:"INFO").toString(),w=null!==(r=null===v||void 0===v?void 0:v["logger.messageFormat"])&&void 0!==r?r:"%(asctime)s %(message)s";i.globals.get("setup_loggers")(k,w),console.debug("Set the loggers"),h("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),yield i.runPythonAsync("\n import streamlit\n\n def is_cacheable_msg(msg):\n return False\n\n streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg\n "),console.debug("Mocked some Streamlit functions"),h("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),self.__streamlitFlagOptions__=Object.assign(Object.assign({"browser.gatherUsageStats":!1},v),{"runner.fastReruns":!1}),yield i.runPythonAsync(`\n from stlite_server.bootstrap import load_config_options, prepare\n from stlite_server.server import Server\n from js import __streamlitFlagOptions__\n\n flag_options = __streamlitFlagOptions__.to_py()\n load_config_options(flag_options)\n\n main_script_path = "${n}"\n command_line = None\n args = []\n\n prepare(main_script_path, args)\n\n server = Server(main_script_path, command_line)\n server.start()\n `),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),c=i.globals.get("server").copy(),console.debug("Set up the HTTP server"),g.postMessage({type:"event:loaded"})}))}().catch((e=>{throw g.postMessage({type:"event:error",data:{error:e}}),e}));self.onmessage=t=>l(void 0,void 0,void 0,(function*(){const r=t.data;if("initData"===r.type)return void d.resolve(r.data);yield u;const n=t.ports[0];try{switch(r.type){case"websocket:connect":{console.debug("websocket:connect",r.data);const{path:e}=r.data;c.start_websocket(e,((e,t)=>{if(t){const t=e.getBuffer("u8");e.destroy();const r=new Uint8ClampedArray(t.data.buffer,t.data.byteOffset,t.data.byteLength);g.postMessage({type:"websocket:message",data:{payload:new Uint8Array(r)}})}else g.postMessage({type:"websocket:message",data:{payload:e}})})),n.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",r.data);const{payload:e}=r.data;c.receive_websocket_from_js(e);break}case"http:request":{console.debug("http:request",r.data);const{request:e}=r.data,t=(e,t,r)=>{const o=t.toJs(),s=r.toJs();console.debug({statusCode:e,headers:o,body:s});const a={type:"http:response",data:{response:{statusCode:e,headers:o,body:s}}};n.postMessage(a)};c.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,t);break}case"file:write":{const{path:e,data:t,opts:o}=r.data;console.debug(`Write a file "${e}"`),s(i,e,t,o),n.postMessage({type:"reply"});break}case"file:rename":{const{oldPath:e,newPath:t}=r.data;console.debug(`Rename "${e}" to ${t}`),function(e,t,r){o(e,r),e.FS.rename(t,r)}(i,e,t),n.postMessage({type:"reply"});break}case"file:unlink":{const{path:e}=r.data;console.debug(`Remove "${e}`),i.FS.unlink(e),n.postMessage({type:"reply"});break}case"install":{const{requirements:t}=r.data,o=i.pyimport("micropip");console.debug("Install the requirements:",t),e(t),yield o.install.callKwargs(t,{keep_going:!0}).then((()=>{if(t.includes("matplotlib"))return i.runPythonAsync("\n from stlite_server.bootstrap import _fix_matplotlib_crash\n _fix_matplotlib_crash()\n ")})).then((()=>{console.debug("Successfully installed"),n.postMessage({type:"reply"})}))}}}catch(a){if(console.error(a),!(a instanceof Error))throw a;const e=new Error(a.message);e.name=a.name,e.stack=a.stack,n.postMessage({type:"reply",error:e})}})),g.postMessage({type:"event:start"})})()})();