@stlite/desktop 0.48.3 → 0.49.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.
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env node
2
- var F=Object.create;var P=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var E=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of x(t))!C.call(e,a)&&a!==i&&P(e,a,{get:()=>t[a],enumerable:!(r=I(t,a))||r.enumerable});return e};var d=(e,t,i)=>(i=e!=null?F(M(e)):{},E(t||!e||!e.__esModule?P(i,"default",{value:e,enumerable:!0}):i,e));var v=y(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.parseRequirementsTxt=void 0;var R=/\s#.*$/;function J(e){return e.split(`
3
- `).filter(t=>!t.startsWith("#")).map(t=>t.replace(R,"")).map(t=>t.trim()).filter(t=>t!=="")}f.parseRequirementsTxt=J});var D=y(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.PromiseDelegate=void 0;var w=class{constructor(){this.promise=new Promise((t,i)=>{this.resolveInternal=t,this.rejectInternal=i})}resolve(t){this.resolveInternal(t)}reject(t){this.rejectInternal(t)}};g.PromiseDelegate=w});var b=y(l=>{"use strict";var W=l&&l.__createBinding||(Object.create?function(e,t,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(t,i);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,a)}:function(e,t,i,r){r===void 0&&(r=i),e[r]=t[i]}),_=l&&l.__exportStar||function(e,t){for(var i in e)i!=="default"&&!Object.prototype.hasOwnProperty.call(t,i)&&W(t,e,i)};Object.defineProperty(l,"__esModule",{value:!0});_(v(),l);_(D(),l)});var O=d(require("yargs")),T=require("yargs/helpers"),o=d(require("path")),s=d(require("fs/promises")),k=d(require("fs-extra")),h=d(require("node-fetch")),m=require("pyodide"),$=d(b());global.fetch=h.default;function S(e){return`https://cdn.jsdelivr.net/pyodide/v${m.version}/full/${e}`}async function A(e){console.info("Copy the build directory (the bare built app files) to this directory...");let t=o.default.resolve(__dirname,"../build");if(!(await s.default.stat(t)).isDirectory())throw new Error(`The source ${t} does not exist.`);if(t===e.copyTo){console.warn(`sourceDir == destDir (${t}). Are you in the development environment? Skip copying the directory.`);return}if(e.keepOld)try{await s.default.access(e.copyTo),console.info(`${e.copyTo} already exists. Use it and skip copying.`);return}catch{throw new Error(`${e.copyTo} does not exist even though the \`keepOld\` option is specified`)}console.log(`Copy ${t} to ${e.copyTo}`),await s.default.rm(e.copyTo,{recursive:!0,force:!0}),await k.default.copy(t,e.copyTo)}async function H(e){if(e.requirements.length===0)return[];let t=await(0,m.loadPyodide)();return await j(t,{requirements:e.requirements}),Object.entries(t.loadedPackages).filter(([,i])=>i==="default channel").map(([i])=>i)}async function B(){let e=S("pyodide-lock.json");return console.log(`Load the Pyodide pyodide-lock.json from ${e}`),(await(await(0,h.default)(e)).json()).packages}async function q(e,t){console.log(`Preparing the local wheel ${t}`);let i=await s.default.readFile(t),r="/tmp/"+o.default.basename(t);e.FS.writeFile(r,i);let a=`emfs:${r}`;return console.log(`The local wheel ${t} is prepared as ${a}`),a}async function j(e,t){await e.loadPackage(["micropip"]);let i=e.pyimport("micropip"),r=[...t.requirements],a=o.default.join(__dirname,"../wheels"),n=await q(e,o.default.join(a,"stlite_server-0.1.0-py3-none-any.whl"));r.push(n);let c=await q(e,o.default.join(a,"streamlit-1.32.2-cp311-none-any.whl"));r.push(c),console.log("Install the packages:",r),await i.install.callKwargs(r,{keep_going:!0})}async function z(e){console.info("Create the site-packages snapshot file...");let t=await(0,m.loadPyodide)();await t.loadPackage(["micropip"]);let i=t.pyimport("micropip"),r=await B(),a=[];e.usedBuiltinPackages.length>0&&(console.log("Mocking builtin packages so that they will not be included in the site-packages snapshot because these will be installed from the vendored wheel files at runtime..."),e.usedBuiltinPackages.forEach(p=>{let u=r[p];if(u==null)throw new Error(`Package ${p} is not found in the lock file.`);console.log(`Mock ${u.name} ${u.version}`),i.add_mock_package(u.name,u.version),a.push(u.name)})),console.log(`Install the requirements ${JSON.stringify(e.requirements)}`),await j(t,{requirements:e.requirements}),console.log("Remove the mocked packages",a),a.forEach(p=>i.remove_mock_package(p)),console.log("Archive the site-packages director(y|ies)");let n="/tmp/site-packages-snapshot.tar.gz";await t.runPythonAsync(`
2
+ var E=Object.create;var _=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var W=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!H.call(e,a)&&a!==i&&_(e,a,{get:()=>t[a],enumerable:!(r=M(t,a))||r.enumerable});return e};var p=(e,t,i)=>(i=e!=null?E(C(e)):{},W(t||!e||!e.__esModule?_(i,"default",{value:e,enumerable:!0}):i,e));var D=y(f=>{"use strict";Object.defineProperty(f,"__esModule",{value:!0});f.parseRequirementsTxt=void 0;var A=/\s#.*$/;function J(e){return e.split(`
3
+ `).filter(t=>!t.startsWith("#")).map(t=>t.replace(A,"")).map(t=>t.trim()).filter(t=>t!=="")}f.parseRequirementsTxt=J});var b=y(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.PromiseDelegate=void 0;var w=class{constructor(){this.promise=new Promise((t,i)=>{this.resolveInternal=t,this.rejectInternal=i})}resolve(t){this.resolveInternal(t)}reject(t){this.rejectInternal(t)}};g.PromiseDelegate=w});var O=y(l=>{"use strict";var U=l&&l.__createBinding||(Object.create?function(e,t,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(t,i);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,a)}:function(e,t,i,r){r===void 0&&(r=i),e[r]=t[i]}),T=l&&l.__exportStar||function(e,t){for(var i in e)i!=="default"&&!Object.prototype.hasOwnProperty.call(t,i)&&U(t,e,i)};Object.defineProperty(l,"__esModule",{value:!0});T(D(),l);T(b(),l)});var I=p(require("yargs")),$=require("yargs/helpers"),o=p(require("path")),n=p(require("fs/promises")),k=p(require("fs-extra")),P=p(require("node-fetch")),v=require("pyodide"),j=p(O());var q=require("pyodide");function h(e){return`https://cdn.jsdelivr.net/pyodide/v${q.version}/full/${e}`}var B=p(require("node-fetch"));var m=class e{static _instance;_data=null;constructor(){}static async loadPyodideBuiltinPackageData(){let t=h("pyodide-lock.json");return console.log(`Load the Pyodide pyodide-lock.json from ${t}`),(await(await(0,B.default)(t,void 0)).json()).packages}static async getInstance(){return this._instance==null&&(this._instance=new e,this._instance._data=await this.loadPyodideBuiltinPackageData()),this._instance}getPackageInfoByName(t){if(this._data==null)throw new Error("The package data is not loaded yet.");let i=Object.values(this._data).find(r=>r.name===t);if(i==null)throw new Error(`Package ${t} is not found in the lock file.`);return i}};global.fetch=P.default;var L="../build",z="../wheels";async function F(e,t){let i=[],r=a=>{i.push(a)};if(await e.loadPackage(t,{errorCallback:r}),i.length>0)throw new Error(i.join(`
4
+ `))}async function N(e){console.info("Copy the build directory (the bare built app files) to this directory...");let t=o.default.resolve(__dirname,L);if(!(await n.default.stat(t)).isDirectory())throw new Error(`The source ${t} does not exist.`);if(t===e.copyTo){console.warn(`sourceDir == destDir (${t}). Are you in the development environment? Skip copying the directory.`);return}if(e.keepOld)try{await n.default.access(e.copyTo),console.info(`${e.copyTo} already exists. Use it and skip copying.`);return}catch{throw new Error(`${e.copyTo} does not exist even though the \`keepOld\` option is specified`)}console.log(`Copy ${t} to ${e.copyTo}`),await n.default.rm(e.copyTo,{recursive:!0,force:!0}),await k.default.copy(t,e.copyTo)}async function K(e){if(e.requirements.length===0)return[];let t=await(0,v.loadPyodide)();return await x(t,{requirements:e.requirements}),Object.entries(t.loadedPackages).filter(([,i])=>i==="default channel").map(([i])=>i)}async function S(e,t){console.log(`Preparing the local wheel ${t}`);let i=await n.default.readFile(t),r="/tmp/"+o.default.basename(t);e.FS.writeFile(r,i);let a=`emfs:${r}`;return console.log(`The local wheel ${t} is prepared as ${a}`),a}async function x(e,t){await F(e,"micropip");let i=e.pyimport("micropip"),r=[...t.requirements],a=o.default.join(__dirname,z),s=await S(e,o.default.join(a,"stlite_server-0.1.0-py3-none-any.whl"));r.push(s);let c=await S(e,o.default.join(a,"streamlit-1.32.2-cp311-none-any.whl"));r.push(c),console.log("Install the packages:",r),await i.install.callKwargs(r,{keep_going:!0})}async function V(e){console.info("Create the site-packages snapshot file...");let t=await(0,v.loadPyodide)();await F(t,"micropip");let i=t.pyimport("micropip"),r=await m.getInstance(),a=[];e.usedBuiltinPackages.length>0&&(console.log("Mocking builtin packages so that they will not be included in the site-packages snapshot because these will be installed from the vendored wheel files at runtime..."),e.usedBuiltinPackages.forEach(d=>{let u=r.getPackageInfoByName(d);if(u==null)throw new Error(`Package ${d} is not found in the lock file.`);console.log(`Mock ${u.name} ${u.version}`),i.add_mock_package(u.name,u.version),a.push(u.name)})),console.log(`Install the requirements ${JSON.stringify(e.requirements)}`),await x(t,{requirements:e.requirements}),console.log("Remove the mocked packages",a),a.forEach(d=>i.remove_mock_package(d)),console.log("Archive the site-packages director(y|ies)");let s="/tmp/site-packages-snapshot.tar.gz";await t.runPythonAsync(`
4
5
  import os
5
6
  import tarfile
6
7
  import site
7
8
 
8
9
  site_packages_dirs = site.getsitepackages()
9
10
 
10
- tar_file_name = '${n}'
11
+ tar_file_name = '${s}'
11
12
  with tarfile.open(tar_file_name, mode='w:gz') as gzf:
12
13
  for site_packages in site_packages_dirs:
13
14
  print("Add site-package:", site_packages)
14
15
  print(os.listdir(site_packages))
15
16
  gzf.add(site_packages)
16
- `),console.log("Extract the archive file from EMFS");let c=t.FS.readFile(n);console.log(`Save the archive file (${e.saveTo})`),await s.default.writeFile(e.saveTo,c)}async function U(e){console.info("Copy the Streamlit app directory..."),console.log(`Copy ${e.sourceDir} to ${e.copyTo}`),await s.default.rm(e.copyTo,{recursive:!0,force:!0}),await k.default.copy(e.sourceDir,e.copyTo)}async function L(e){let t=await s.default.readFile(e,{encoding:"utf-8"});return(0,$.parseRequirementsTxt)(t)}async function K(e,t){let i=t.join(`
17
- `);await s.default.writeFile(e,i,{encoding:"utf-8"})}function N(e){e.forEach(t=>{let i;try{i=new URL(t)}catch{return}if(i.protocol==="emfs:"||i.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)})}async function V(e){let t=await B(),r=e.packages.map(a=>t[a]).map(a=>S(a.file_name));console.log("Downloading the used built-in packages..."),await Promise.all(r.map(async a=>{let n=o.default.resolve(e.destDir,"./pyodide",o.default.basename(a));console.log(`Download ${a} to ${n}`);let c=await(0,h.default)(a);if(!c.ok)throw new Error(`Failed to download ${a}: ${c.status} ${c.statusText}`);let p=await c.arrayBuffer();await s.default.writeFile(n,Buffer.from(p))}))}async function G(e){let r={embed:(require(e.packageJsonPath).stlite?.desktop||{}).embed||!1},a=JSON.stringify(r,null,2);console.log(`Dump the manifest file -> ${e.manifestFilePath}`),console.log(a),await s.default.writeFile(e.manifestFilePath,a,{encoding:"utf-8"})}(0,O.default)((0,T.hideBin)(process.argv)).command("* <appHomeDirSource> [packages..]","Put the user code and data and the snapshot of the required packages into the build artifact.",()=>{},e=>{console.info(e)}).positional("appHomeDirSource",{describe:"The source directory of the user code and data that will be mounted in the Pyodide file system at app runtime",type:"string",demandOption:!0}).positional("packages",{describe:"Package names to install.",type:"string",array:!0}).options("requirement",{describe:"Install from the given requirements file. This option can be used multiple times.",array:!0,type:"string",alias:"r",default:[]}).options("keepOldBuild",{type:"boolean",default:!1,alias:"k",describe:"Keep the existing build directory contents except appHomeDir."}).parseAsync().then(async e=>{let t=process.cwd(),i=o.default.resolve(t,"./build");try{await s.default.access(e.appHomeDirSource)}catch{throw new Error(`${e.appHomeDirSource} does not exist.`)}let r=e.packages??[];for(let n of e.requirement)r=r.concat(await L(n));N(r);let a=await H({requirements:r});console.log("The built-in packages loaded for the given requirements:"),console.log(a),await A({copyTo:i,keepOld:e.keepOldBuild}),await z({requirements:r,usedBuiltinPackages:a,saveTo:o.default.resolve(i,"./site-packages-snapshot.tar.gz")}),await K(o.default.resolve(i,"./requirements.txt"),a),await U({sourceDir:e.appHomeDirSource,copyTo:o.default.resolve(i,"./streamlit_app")}),await V({packages:a,destDir:i}),await G({packageJsonPath:o.default.resolve(t,"./package.json"),manifestFilePath:o.default.resolve(i,"./stlite-manifest.json")})});
17
+ `),console.log("Extract the archive file from EMFS");let c=t.FS.readFile(s);console.log(`Save the archive file (${e.saveTo})`),await n.default.writeFile(e.saveTo,c)}async function G(e){console.info("Copy the Streamlit app directory..."),console.log(`Copy ${e.sourceDir} to ${e.copyTo}`),await n.default.rm(e.copyTo,{recursive:!0,force:!0}),await k.default.copy(e.sourceDir,e.copyTo)}async function Q(e){let t=await n.default.readFile(e,{encoding:"utf-8"});return(0,j.parseRequirementsTxt)(t)}async function X(e,t){let i=t.join(`
18
+ `);await n.default.writeFile(e,i,{encoding:"utf-8"})}function Y(e){e.forEach(t=>{let i;try{i=new URL(t)}catch{return}if(i.protocol==="emfs:"||i.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)})}async function Z(e){let t=await m.getInstance(),r=e.packages.map(a=>t.getPackageInfoByName(a)).map(a=>h(a.file_name));console.log("Downloading the used built-in packages..."),await Promise.all(r.map(async a=>{let s=o.default.resolve(e.destDir,"./pyodide",o.default.basename(a));console.log(`Download ${a} to ${s}`);let c=await(0,P.default)(a);if(!c.ok)throw new Error(`Failed to download ${a}: ${c.status} ${c.statusText}`);let d=await c.arrayBuffer();await n.default.writeFile(s,Buffer.from(d))}))}async function ee(e){let r={embed:(require(e.packageJsonPath).stlite?.desktop||{}).embed||!1},a=JSON.stringify(r,null,2);console.log(`Dump the manifest file -> ${e.manifestFilePath}`),console.log(a),await n.default.writeFile(e.manifestFilePath,a,{encoding:"utf-8"})}(0,I.default)((0,$.hideBin)(process.argv)).command("* <appHomeDirSource> [packages..]","Put the user code and data and the snapshot of the required packages into the build artifact.",()=>{},e=>{console.info(e)}).positional("appHomeDirSource",{describe:"The source directory of the user code and data that will be mounted in the Pyodide file system at app runtime",type:"string",demandOption:!0}).positional("packages",{describe:"Package names to install.",type:"string",array:!0}).options("requirement",{describe:"Install from the given requirements file. This option can be used multiple times.",array:!0,type:"string",alias:"r",default:[]}).options("keepOldBuild",{type:"boolean",default:!1,alias:"k",describe:"Keep the existing build directory contents except appHomeDir."}).parseAsync().then(async e=>{let t=process.cwd(),i=o.default.resolve(t,"./build");try{await n.default.access(e.appHomeDirSource)}catch{throw new Error(`${e.appHomeDirSource} does not exist.`)}let r=e.packages??[];for(let s of e.requirement)r=r.concat(await Q(s));Y(r);let a=await K({requirements:r});console.log("The built-in packages loaded for the given requirements:"),console.log(a),await N({copyTo:i,keepOld:e.keepOldBuild}),await V({requirements:r,usedBuiltinPackages:a,saveTo:o.default.resolve(i,"./site-packages-snapshot.tar.gz")}),await X(o.default.resolve(i,"./requirements.txt"),a),await G({sourceDir:e.appHomeDirSource,copyTo:o.default.resolve(i,"./streamlit_app")}),await Z({packages:a,destDir:i}),await ee({packageJsonPath:o.default.resolve(t,"./package.json"),manifestFilePath:o.default.resolve(i,"./stlite-manifest.json")})});
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.fb5f4d99.css",
4
- "main.js": "/static/js/main.b5316fd2.js",
5
- "static/js/7332.71a3c522.chunk.js": "/static/js/7332.71a3c522.chunk.js",
4
+ "main.js": "/static/js/main.3409f837.js",
5
+ "static/js/7332.3f3436f3.chunk.js": "/static/js/7332.3f3436f3.chunk.js",
6
6
  "static/js/4994.551c87ac.chunk.js": "/static/js/4994.551c87ac.chunk.js",
7
7
  "static/js/3685.c65c1e48.chunk.js": "/static/js/3685.c65c1e48.chunk.js",
8
8
  "static/js/4785.f21e0ace.chunk.js": "/static/js/4785.f21e0ace.chunk.js",
@@ -162,6 +162,6 @@
162
162
  },
163
163
  "entrypoints": [
164
164
  "static/css/main.fb5f4d99.css",
165
- "static/js/main.b5316fd2.js"
165
+ "static/js/main.3409f837.js"
166
166
  ]
167
167
  }
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><script defer="defer" src="/static/js/main.b5316fd2.js"></script><link href="/static/css/main.fb5f4d99.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>stlite</title><script defer="defer" src="/static/js/main.3409f837.js"></script><link href="/static/css/main.fb5f4d99.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>