@stlite/desktop 0.83.0 → 0.84.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/bin/dump_artifacts.js +31 -31
- package/build/assets/{ErrorOutline.esm-w3SotGgg.js → ErrorOutline.esm-7fPCAua1.js} +1 -1
- package/build/assets/{FileDownload.esm-DNaG7mhy.js → FileDownload.esm-5XDRJbc8.js} +1 -1
- package/build/assets/{FileHelper-DoUfoupm.js → FileHelper-BarQJiLz.js} +1 -1
- package/build/assets/{FormClearHelper-DI9KwuTl.js → FormClearHelper-BZaxoxQN.js} +1 -1
- package/build/assets/{Hooks-BRr-mPDr.js → Hooks-BxizdPoJ.js} +1 -1
- package/build/assets/{InputInstructions-mpv25B9R.js → InputInstructions-Dmr8j4xE.js} +1 -1
- package/build/assets/{ProgressBar-DalMRT-4.js → ProgressBar-C_yUO6k-.js} +1 -1
- package/build/assets/{RenderInPortalIfExists-CfX3LXlx.js → RenderInPortalIfExists-eTRglO06.js} +1 -1
- package/build/assets/{Toolbar-1r13KE9d.js → Toolbar-bneC7vhq.js} +1 -1
- package/build/assets/{base-input-BJ4WO1K3.js → base-input-DrVuxJmE.js} +1 -1
- package/build/assets/{checkbox-COr-UunX.js → checkbox-Ce7VH5yR.js} +1 -1
- package/build/assets/{createSuper-BD8Om4of.js → createSuper-Ce1x_8d5.js} +1 -1
- package/build/assets/{data-grid-overlay-editor-DUKLRWRf.js → data-grid-overlay-editor-Bd6FIb0g.js} +1 -1
- package/build/assets/{downloader-K2yu2VBv.js → downloader-DTdoFA0u.js} +1 -1
- package/build/assets/{es6-CqFPgbyx.js → es6-eSFIFIhE.js} +2 -2
- package/build/assets/{iframeResizer.contentWindow-CYxwXEKD.js → iframeResizer.contentWindow-BbhpUGmG.js} +1 -1
- package/build/assets/{index-CBHSzhtV.js → index-2zFaDmrI.js} +1 -1
- package/build/assets/{index-DHvjd_NM.js → index-B6AypoKB.js} +1 -1
- package/build/assets/{index-CgaLKbNA.js → index-BF3Fet0V.js} +1 -1
- package/build/assets/{index-DhpOSNWU.js → index-BU5lMh9f.js} +1 -1
- package/build/assets/{index-Chg_Z_Ai.js → index-BU9sb5h3.js} +1 -1
- package/build/assets/{index-WJi2gbUd.js → index-BWKeW-zA.js} +1 -1
- package/build/assets/{index-B7nFcP4b.js → index-BcIT8Wnk.js} +1 -1
- package/build/assets/{index-D4DI0i3_.js → index-Bf7iW3kb.js} +1 -1
- package/build/assets/{index-BBSx627c.js → index-Bj66FfmM.js} +1 -1
- package/build/assets/{index-qPiigGKE.js → index-BlaLvghR.js} +1 -1
- package/build/assets/{index-CbGVTpRX.js → index-BrFIUJra.js} +1 -1
- package/build/assets/{index-TIqCq-vm.js → index-BwAJEr7A.js} +1 -1
- package/build/assets/{index-DJ9ENWJ6.js → index-BxnhSwtv.js} +1 -1
- package/build/assets/{index-QxKGd3KZ.js → index-C-8qP7Ru.js} +1 -1
- package/build/assets/{index-CTKSPDuj.js → index-CGpWCLFI.js} +1 -1
- package/build/assets/{index-FQnDjdgN.js → index-CQr0CfvQ.js} +1 -1
- package/build/assets/{index-CgIf_789.js → index-CfZojTNf.js} +1 -1
- package/build/assets/{index-DAFr20lD.js → index-D1bJoe6r.js} +1 -1
- package/build/assets/{index-DbWqdg_N.js → index-DAb-Jtr2.js} +1 -1
- package/build/assets/{index-D_aTbShm.js → index-DBHyG99F.js} +1 -1
- package/build/assets/{index-BTWAYrEA.js → index-DFxMAoHY.js} +1 -1
- package/build/assets/{index-oIFkiM-w.js → index-DGjwMTQq.js} +1 -1
- package/build/assets/{index-GeTKqk0L.js → index-DMAr4hNX.js} +1 -1
- package/build/assets/{index-CVPZJuoC.js → index-DPBNUFWE.js} +4 -4
- package/build/assets/{index-DZGNB9Z2.js → index-DW2AfAPF.js} +1 -1
- package/build/assets/{index-DIR2fiU3.js → index-DcKJu6C9.js} +1 -1
- package/build/assets/{index-CJj5-jL6.js → index-Dk8gL3aI.js} +1 -1
- package/build/assets/{index-Dkkplt7E.js → index-DluRIgvs.js} +1 -1
- package/build/assets/{index-dOLNZa0u.js → index-Dwbjahn_.js} +1 -1
- package/build/assets/{index-CG0w2Shn.js → index-DyGi5YBc.js} +1 -1
- package/build/assets/{index-Cy3sYumn.js → index-DzT-BaTB.js} +1 -1
- package/build/assets/{index-BVYhtbL7.js → index-_GH5VSbG.js} +1 -1
- package/build/assets/{index-DAyJZph2.js → index-_iQJZ8n8.js} +1 -1
- package/build/assets/{index-bXFpQSEH.js → index-atxzdN1F.js} +1 -1
- package/build/assets/{index-h6PFbOmO.js → index-c-NQS3qn.js} +5 -5
- package/build/assets/{index-Bga7N97D.js → index-rc6TuZ_x.js} +1 -1
- package/build/assets/{index-BY2_5dEP.js → index-wWTCE5QI.js} +1 -1
- package/build/assets/{inherits-DtR6i4OG.js → inherits-83mK7fR9.js} +1 -1
- package/build/assets/{input-9qldoJOB.js → input-CXi1-D16.js} +1 -1
- package/build/assets/{memory-Cy3-iIgx.js → memory-BtIreI5V.js} +1 -1
- package/build/assets/{mergeWith-DdD-5zWL.js → mergeWith-DZ-wgSc6.js} +1 -1
- package/build/assets/{number-overlay-editor-DmP64vrs.js → number-overlay-editor-BxuviOUl.js} +1 -1
- package/build/assets/{sandbox-DzhFXmWd.js → sandbox-DHLnmH8d.js} +1 -1
- package/build/assets/{slicedToArray-CNrowD0v.js → slicedToArray-Bj-RN7K3.js} +1 -1
- package/build/assets/{textarea-Bql4j-_M.js → textarea-BKD-emFb.js} +1 -1
- package/build/assets/{timepicker-sEhIITXf.js → timepicker-CWkzEpyz.js} +1 -1
- package/build/assets/{uniqueId-DfRnwW3q.js → uniqueId-BGMRjdMp.js} +1 -1
- package/build/assets/{useBasicWidgetState-DJ8kXLgn.js → useBasicWidgetState-uJo0naOA.js} +1 -1
- package/build/assets/{useOnInputChange-CZX_IkMh.js → useOnInputChange-DI3AnwSZ.js} +1 -1
- package/build/assets/{withFullScreenWrapper-DBlEST2L.js → withFullScreenWrapper-DbD5_ijt.js} +1 -1
- package/build/assets/worker-DEam9hTF.js +105 -0
- package/build/electron/worker.js +9 -119
- package/build/index.html +1 -1
- package/package.json +5 -5
- package/wheels/stlite_lib-0.1.0-py3-none-any.whl +0 -0
- package/wheels/streamlit-1.45.1-cp312-none-any.whl +0 -0
- package/build/assets/worker-CXcujS1W.js +0 -215
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
function Q(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var E,j;function Y(){if(j)return E;j=1;function o(l){if(typeof l!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(l))}function c(l,e){for(var t="",i=0,s=-1,n=0,r,a=0;a<=l.length;++a){if(a<l.length)r=l.charCodeAt(a);else{if(r===47)break;r=47}if(r===47){if(!(s===a-1||n===1))if(s!==a-1&&n===2){if(t.length<2||i!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var p=t.lastIndexOf("/");if(p!==t.length-1){p===-1?(t="",i=0):(t=t.slice(0,p),i=t.length-1-t.lastIndexOf("/")),s=a,n=0;continue}}else if(t.length===2||t.length===1){t="",i=0,s=a,n=0;continue}}e&&(t.length>0?t+="/..":t="..",i=2)}else t.length>0?t+="/"+l.slice(s+1,a):t=l.slice(s+1,a),i=a-s-1;s=a,n=0}else r===46&&n!==-1?++n:n=-1}return t}function d(l,e){var t=e.dir||e.root,i=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+i:t+l+i:i}var m={resolve:function(){for(var e="",t=!1,i,s=arguments.length-1;s>=-1&&!t;s--){var n;s>=0?n=arguments[s]:(i===void 0&&(i=process.cwd()),n=i),o(n),n.length!==0&&(e=n+"/"+e,t=n.charCodeAt(0)===47)}return e=c(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(o(e),e.length===0)return".";var t=e.charCodeAt(0)===47,i=e.charCodeAt(e.length-1)===47;return e=c(e,!t),e.length===0&&!t&&(e="."),e.length>0&&i&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return o(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 i=arguments[t];o(i),i.length>0&&(e===void 0?e=i:e+="/"+i)}return e===void 0?".":m.normalize(e)},relative:function(e,t){if(o(e),o(t),e===t||(e=m.resolve(e),t=m.resolve(t),e===t))return"";for(var i=1;i<e.length&&e.charCodeAt(i)===47;++i);for(var s=e.length,n=s-i,r=1;r<t.length&&t.charCodeAt(r)===47;++r);for(var a=t.length,p=a-r,S=n<p?n:p,b=-1,h=0;h<=S;++h){if(h===S){if(p>S){if(t.charCodeAt(r+h)===47)return t.slice(r+h+1);if(h===0)return t.slice(r+h)}else n>S&&(e.charCodeAt(i+h)===47?b=h:h===0&&(b=0));break}var v=e.charCodeAt(i+h),g=t.charCodeAt(r+h);if(v!==g)break;v===47&&(b=h)}var _="";for(h=i+b+1;h<=s;++h)(h===s||e.charCodeAt(h)===47)&&(_.length===0?_+="..":_+="/..");return _.length>0?_+t.slice(r+b):(r+=b,t.charCodeAt(r)===47&&++r,t.slice(r))},_makeLong:function(e){return e},dirname:function(e){if(o(e),e.length===0)return".";for(var t=e.charCodeAt(0),i=t===47,s=-1,n=!0,r=e.length-1;r>=1;--r)if(t=e.charCodeAt(r),t===47){if(!n){s=r;break}}else n=!1;return s===-1?i?"/":".":i&&s===1?"//":e.slice(0,s)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');o(e);var i=0,s=-1,n=!0,r;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,p=-1;for(r=e.length-1;r>=0;--r){var S=e.charCodeAt(r);if(S===47){if(!n){i=r+1;break}}else p===-1&&(n=!1,p=r+1),a>=0&&(S===t.charCodeAt(a)?--a===-1&&(s=r):(a=-1,s=p))}return i===s?s=p:s===-1&&(s=e.length),e.slice(i,s)}else{for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===47){if(!n){i=r+1;break}}else s===-1&&(n=!1,s=r+1);return s===-1?"":e.slice(i,s)}},extname:function(e){o(e);for(var t=-1,i=0,s=-1,n=!0,r=0,a=e.length-1;a>=0;--a){var p=e.charCodeAt(a);if(p===47){if(!n){i=a+1;break}continue}s===-1&&(n=!1,s=a+1),p===46?t===-1?t=a:r!==1&&(r=1):t!==-1&&(r=-1)}return t===-1||s===-1||r===0||r===1&&t===s-1&&t===i+1?"":e.slice(t,s)},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 d("/",e)},parse:function(e){o(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var i=e.charCodeAt(0),s=i===47,n;s?(t.root="/",n=1):n=0;for(var r=-1,a=0,p=-1,S=!0,b=e.length-1,h=0;b>=n;--b){if(i=e.charCodeAt(b),i===47){if(!S){a=b+1;break}continue}p===-1&&(S=!1,p=b+1),i===46?r===-1?r=b:h!==1&&(h=1):r!==-1&&(h=-1)}return r===-1||p===-1||h===0||h===1&&r===p-1&&r===a+1?p!==-1&&(a===0&&s?t.base=t.name=e.slice(1,p):t.base=t.name=e.slice(a,p)):(a===0&&s?(t.name=e.slice(1,r),t.base=e.slice(1,p)):(t.name=e.slice(a,r),t.base=e.slice(a,p)),t.ext=e.slice(r,p)),a>0?t.dir=e.slice(0,a-1):s&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};return m.posix=m,E=m,E}var Z=Y(),R=Q(Z);const O="/home/pyodide",N=o=>`${O}/${o}`,F=(o,c)=>o==null?R.resolve(O,c):R.resolve(N(o),c);function z(o,c){const d=R.normalize(c),l=R.dirname(d).split("/"),e=[];for(const t of l){e.push(t);const i=e.join("/");if(o.FS.analyzePath(i).exists){if(o.FS.isDir(i))throw new Error(`"${i}" already exists and is not a directory.`);continue}try{o.FS.mkdir(i)}catch(s){throw console.error(`Failed to create a directory "${i}"`),s}}}function q(o,c,d,m){z(o,c),o.FS.writeFile(c,d,m)}function ee(o,c,d){z(o,d),o.FS.rename(c,d)}const te="[",re="(<=>!~",oe=";",ne="@",se=new RegExp(`[${te+re+oe+ne}]`);function ie(o){return o.split(se)[0].trim()}function U(o){return o.forEach(d=>{let m;try{m=new URL(d)}catch{return}if(m.protocol==="emfs:"||m.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${d})`)}),o.filter(d=>ie(d)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${d}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function ae(o){var l;const c=typeof process<"u"&&((l=process.versions)==null?void 0:l.node);let d;c?d=(await import("./__vite-browser-external-9wXp6ZBx.js")).sep:d="/";const m=o.slice(0,o.lastIndexOf(d)+1);if(o.endsWith(".mjs")){if(c){const e=await import("./__vite-browser-external-9wXp6ZBx.js"),t=await import("./__vite-browser-external-9wXp6ZBx.js");!o.includes("://")&&e.isAbsolute(o)&&(o=t.pathToFileURL(o).href)}return{scriptURL:o,pyodideIndexURL:m,isESModule:!0}}else return{scriptURL:o,pyodideIndexURL:m,isESModule:!1}}async function le(o,c){const{scriptURL:d,pyodideIndexURL:m,isESModule:l}=await ae(o);let e;return l?e=(await import(d)).loadPyodide:(importScripts(d),e=self.loadPyodide),e({...c,indexURL:m})}function ce(o){o.runPython(`
|
|
2
|
-
import micropip
|
|
3
|
-
micropip.add_mock_package(
|
|
4
|
-
"pyarrow", "0.0.1",
|
|
5
|
-
modules={
|
|
6
|
-
"pyarrow": """
|
|
7
|
-
__version__ = '0.0.1' # TODO: Update when releasing
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Table:
|
|
11
|
-
@classmethod
|
|
12
|
-
def from_pandas(*args, **kwargs):
|
|
13
|
-
raise NotImplementedError("stlite is not supporting this method.")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class Array:
|
|
17
|
-
def __init__(self, *args, **kwargs):
|
|
18
|
-
raise NotImplementedError("stlite is not supporting PyArrow.Array")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class ChunkedArray:
|
|
22
|
-
def __init__(self, *args, **kwargs):
|
|
23
|
-
raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")
|
|
24
|
-
"""
|
|
25
|
-
}
|
|
26
|
-
)
|
|
27
|
-
`)}function de(o,c,d){const m=o.pyimport("pyodide"),l=r=>m.code.find_imports(r).toJs(),e=d.map(r=>l(r)),s=Array.from(new Set(e.flat())).filter(r=>!o.runPython(`__import__('importlib').util.find_spec('${r}')`)).map(r=>o._api._import_name_to_package_name.get(r)).filter(r=>r);if(s.length===0)return Promise.resolve();const n=o.loadPackage(s);return c(s,n),n.then()}function $(o,c,d){const m=de(o,c,d);o.runPython(`
|
|
28
|
-
def __set_module_auto_load_promise__(promise):
|
|
29
|
-
from streamlit.runtime.scriptrunner import script_runner
|
|
30
|
-
script_runner.moduleAutoLoadPromise = promise
|
|
31
|
-
|
|
32
|
-
__set_module_auto_load_promise__`)(m)}const ue=async o=>{await o.runPythonAsync(`import jedi
|
|
33
|
-
import re
|
|
34
|
-
import json
|
|
35
|
-
from typing import Dict
|
|
36
|
-
from lsprotocol.types import (CompletionItem, CompletionList, CompletionItemKind, Position, Range, TextEdit)
|
|
37
|
-
from lsprotocol import converters as lsp_converters
|
|
38
|
-
from jedi.api.classes import Completion
|
|
39
|
-
|
|
40
|
-
def as_completion_item_kind(kind: str):
|
|
41
|
-
match kind:
|
|
42
|
-
case 'class':
|
|
43
|
-
return CompletionItemKind.Class
|
|
44
|
-
case 'function':
|
|
45
|
-
return CompletionItemKind.Function
|
|
46
|
-
case 'instance':
|
|
47
|
-
return CompletionItemKind.Reference
|
|
48
|
-
case 'keyword':
|
|
49
|
-
return CompletionItemKind.Keyword
|
|
50
|
-
case 'module':
|
|
51
|
-
return CompletionItemKind.Module
|
|
52
|
-
case 'param':
|
|
53
|
-
return CompletionItemKind.Variable
|
|
54
|
-
case 'path':
|
|
55
|
-
return CompletionItemKind.File
|
|
56
|
-
case 'property':
|
|
57
|
-
return CompletionItemKind.Property
|
|
58
|
-
case 'statement':
|
|
59
|
-
return CompletionItemKind.Variable
|
|
60
|
-
case _:
|
|
61
|
-
return CompletionItemKind.Text
|
|
62
|
-
|
|
63
|
-
def as_completion_item_sort_text(item: Completion) -> str:
|
|
64
|
-
"""Generate sorting text to arrange items alphabetically,
|
|
65
|
-
ensuring parameters are prioritized first
|
|
66
|
-
and private magic properties come last.
|
|
67
|
-
"""
|
|
68
|
-
completion_item_name = item.name
|
|
69
|
-
if completion_item_name is None or completion_item_name.startswith('_'):
|
|
70
|
-
return f"zz{completion_item_name}"
|
|
71
|
-
elif item.type == "param" and completion_item_name.endswith("="):
|
|
72
|
-
return f"aa{completion_item_name}"
|
|
73
|
-
else:
|
|
74
|
-
return f"bb{completion_item_name}"
|
|
75
|
-
|
|
76
|
-
def as_completion_item(completion: Completion, cursor_range: Range) -> Dict:
|
|
77
|
-
label = completion.name
|
|
78
|
-
return CompletionItem(
|
|
79
|
-
label=label,
|
|
80
|
-
filter_text=label,
|
|
81
|
-
sort_text=as_completion_item_sort_text(completion),
|
|
82
|
-
kind=as_completion_item_kind(completion.type),
|
|
83
|
-
documentation=completion.docstring(raw=True),
|
|
84
|
-
text_edit=TextEdit(range=cursor_range, new_text=label),
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
def get_text_edit_cursor_range(cursor_code_line: str, current_line_number: int, cursor_offset: int):
|
|
88
|
-
# Match the substring starting from cursor_offset ex: math<cursor>co, match co
|
|
89
|
-
matched_words = re.search(r'\\b\\w+\\b', cursor_code_line[cursor_offset :])
|
|
90
|
-
|
|
91
|
-
# Determine the length of the matched word characters
|
|
92
|
-
word_after_cursor_length = len(matched_words.group()) if matched_words else 0
|
|
93
|
-
|
|
94
|
-
# This will tell to code editors which text to edit/replace
|
|
95
|
-
return Range(
|
|
96
|
-
start=Position(
|
|
97
|
-
line=current_line_number, character=cursor_offset
|
|
98
|
-
),
|
|
99
|
-
end=Position(
|
|
100
|
-
line=current_line_number,
|
|
101
|
-
character=cursor_offset + word_after_cursor_length,
|
|
102
|
-
),
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
def get_code_completions(code: str, current_line_number: int, cursor_offset: int):
|
|
106
|
-
|
|
107
|
-
jedi_language_server = jedi.Script(code)
|
|
108
|
-
|
|
109
|
-
# jedi returns a zero-based array with lines
|
|
110
|
-
jedi_line_number_index = current_line_number -1
|
|
111
|
-
|
|
112
|
-
# In case if we are not getting any results back or the offset is wrong
|
|
113
|
-
# Just return empty list
|
|
114
|
-
if jedi_line_number_index >= len(jedi_language_server._code_lines):
|
|
115
|
-
return json.dumps({ "items": []})
|
|
116
|
-
|
|
117
|
-
jedi_completions_list = jedi_language_server.complete(
|
|
118
|
-
current_line_number,
|
|
119
|
-
cursor_offset,
|
|
120
|
-
fuzzy=False,
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
code_at_cursor = jedi_language_server._code_lines[jedi_line_number_index]
|
|
124
|
-
cursor_range = get_text_edit_cursor_range(code_at_cursor, current_line_number, cursor_offset)
|
|
125
|
-
|
|
126
|
-
# Convert jedi completion items as completion items compatible in language server
|
|
127
|
-
suggestions = CompletionList(
|
|
128
|
-
is_incomplete=False,
|
|
129
|
-
items=list(as_completion_item(completion, cursor_range) for completion in jedi_completions_list))
|
|
130
|
-
|
|
131
|
-
# Convert results to JSON so that we can use it in the worker
|
|
132
|
-
converter = lsp_converters.get_converter()
|
|
133
|
-
return json.dumps(converter.unstructure(suggestions, unstructure_as=CompletionList))
|
|
134
|
-
`)},me=async(o,c)=>{let d;try{if(d=c.globals.get("get_code_completions"),!d)return console.error("Can not generate suggestions list, the get_code_completions function is not defined"),{items:[]};const m=d(o.code,o.line,o.column);return m?JSON.parse(m):{items:[]}}catch(m){return console.error(m),{items:[]}}finally{d&&d.constructor.name==="PyProxy"&&d.destroy()}};let I=null;async function ge(o,c,d,m,l){const{entrypoint:e,files:t,archives:i,requirements:s,prebuiltPackageNames:n,wheels:r,pyodideUrl:a=o,streamlitConfig:p,idbfsMountpoints:S,nodefsMountpoints:b,moduleAutoLoad:h,env:v,languageServer:g}=d,_=U(s);if(I)l("Pyodide is already loaded."),console.debug("Pyodide is already loaded.");else{l("Loading Pyodide."),console.debug("Loading Pyodide."),I=le(a,{stdout:console.log,stderr:console.error});const f=[];r&&(f.push(r.streamlit),f.push(r.stliteLib)),g&&(f.push("jedi"),f.push("lsprotocol")),_.unshift(...f),console.debug("Loaded Pyodide")}const u=await I;if(v){console.debug("Setting environment variables",v);const f=u.pyimport("os");f.environ.update(u.toPy(v)),console.debug("Set environment variables",f.environ)}let w=!1;S&&(w=!0,S.forEach(f=>{u.FS.mkdir(f),u.FS.mount(u.FS.filesystems.IDBFS,{},f)}),await new Promise((f,y)=>{u.FS.syncfs(!0,k=>{k?y(k):f()})})),b&&Object.entries(b).forEach(([f,y])=>{u.FS.mkdir(f),u.FS.mount(u.FS.filesystems.NODEFS,{root:y},f)}),l("Mounting files.");const P=[];await Promise.all(Object.keys(t).map(async f=>{const y=t[f];f=F(c,f);let k;"url"in y?(console.debug(`Fetch a file from ${y.url}`),k=await fetch(y.url).then(A=>A.arrayBuffer()).then(A=>new Uint8Array(A))):k=y.data,console.debug(`Write a file "${f}"`),q(u,f,k,t.opts),f.endsWith(".py")&&P.push(f)})),l("Unpacking archives."),await Promise.all(i.map(async f=>{let y;"url"in f?(console.debug(`Fetch an archive from ${f.url}`),y=await fetch(f.url).then(X=>X.arrayBuffer())):y=f.buffer;const{format:k,options:A}=f;console.debug("Unpack an archive",{format:k,options:A}),u.unpackArchive(y,k,A)})),await u.loadPackage("micropip");const C=u.pyimport("micropip");if(l("Mocking some packages."),console.debug("Mock pyarrow"),ce(u),console.debug("Mocked pyarrow"),l("Installing packages."),console.debug("Installing the prebuilt packages:",n),await u.loadPackage(n),console.debug("Installed the prebuilt packages"),console.debug("Installing the requirements:",_),await C.install.callKwargs(_,{keep_going:!0}),console.debug("Installed the requirements"),h){const f=P.map(y=>u.FS.readFile(y,{encoding:"utf8"}));$(u,m,f)}await u.runPythonAsync(`
|
|
135
|
-
import importlib
|
|
136
|
-
importlib.invalidate_caches()
|
|
137
|
-
`),l("Loading streamlit package."),console.debug("Loading the Streamlit package"),await u.runPythonAsync(`
|
|
138
|
-
import streamlit.runtime
|
|
139
|
-
`),console.debug("Loaded the Streamlit package"),l("Setting up the loggers."),console.debug("Setting the loggers"),await u.runPythonAsync(`
|
|
140
|
-
import logging
|
|
141
|
-
import streamlit.logger
|
|
142
|
-
|
|
143
|
-
streamlit.logger.get_logger = logging.getLogger
|
|
144
|
-
streamlit.logger.setup_formatter = None
|
|
145
|
-
streamlit.logger.update_formatter = lambda *a, **k: None
|
|
146
|
-
streamlit.logger.set_log_level = lambda *a, **k: None
|
|
147
|
-
|
|
148
|
-
for name in streamlit.logger._loggers.keys():
|
|
149
|
-
if name == "root":
|
|
150
|
-
name = "streamlit"
|
|
151
|
-
logger = logging.getLogger(name)
|
|
152
|
-
logger.propagate = True
|
|
153
|
-
logger.handlers.clear()
|
|
154
|
-
logger.setLevel(logging.NOTSET)
|
|
155
|
-
|
|
156
|
-
streamlit.logger._loggers = {}
|
|
157
|
-
`);const L=(f,y)=>{f>=40?console.error(y):f>=30?console.warn(y):f>=20?console.info(y):console.debug(y)},H=u.runPython(`
|
|
158
|
-
def __setup_loggers__(streamlit_level, streamlit_message_format, callback):
|
|
159
|
-
class JsHandler(logging.Handler):
|
|
160
|
-
def emit(self, record):
|
|
161
|
-
msg = self.format(record)
|
|
162
|
-
callback(record.levelno, msg)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
root_message_format = "%(levelname)s:%(name)s:%(message)s"
|
|
166
|
-
|
|
167
|
-
root_logger = logging.getLogger()
|
|
168
|
-
root_logger.handlers.clear()
|
|
169
|
-
root_formatter = logging.Formatter(root_message_format)
|
|
170
|
-
root_handler = JsHandler()
|
|
171
|
-
root_handler.setFormatter(root_formatter)
|
|
172
|
-
root_logger.addHandler(root_handler)
|
|
173
|
-
root_logger.setLevel(logging.DEBUG)
|
|
174
|
-
|
|
175
|
-
streamlit_logger = logging.getLogger("streamlit")
|
|
176
|
-
streamlit_logger.propagate = False
|
|
177
|
-
streamlit_logger.handlers.clear()
|
|
178
|
-
streamlit_formatter = logging.Formatter(streamlit_message_format)
|
|
179
|
-
streamlit_handler = JsHandler()
|
|
180
|
-
streamlit_handler.setFormatter(streamlit_formatter)
|
|
181
|
-
streamlit_logger.addHandler(streamlit_handler)
|
|
182
|
-
streamlit_logger.setLevel(streamlit_level.upper())
|
|
183
|
-
|
|
184
|
-
__setup_loggers__`),W=((p==null?void 0:p["logger.level"])??"INFO").toString(),K=(p==null?void 0:p["logger.messageFormat"])??"%(asctime)s %(message)s";if(H(W,K,L),console.debug("Set the loggers"),l("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await u.runPythonAsync(`
|
|
185
|
-
import streamlit
|
|
186
|
-
|
|
187
|
-
def is_cacheable_msg(msg):
|
|
188
|
-
return False
|
|
189
|
-
|
|
190
|
-
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
|
|
191
|
-
`),console.debug("Mocked some Streamlit functions"),w){l("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let f=!1;const y=()=>{console.debug("The script has finished. Syncing the filesystem."),f||(f=!0,u.FS.syncfs(!1,A=>{f=!1,A&&console.error(A)}))};(await u.runPython(`
|
|
192
|
-
def __setup_script_finished_callback__(callback):
|
|
193
|
-
from streamlit.runtime.app_session import AppSession
|
|
194
|
-
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
|
|
195
|
-
|
|
196
|
-
def wrap_app_session_on_scriptrunner_event(original_method):
|
|
197
|
-
def wrapped(self, *args, **kwargs):
|
|
198
|
-
if "event" in kwargs:
|
|
199
|
-
event = kwargs["event"]
|
|
200
|
-
if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:
|
|
201
|
-
callback()
|
|
202
|
-
return original_method(self, *args, **kwargs)
|
|
203
|
-
return wrapped
|
|
204
|
-
|
|
205
|
-
AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
|
|
206
|
-
|
|
207
|
-
__setup_script_finished_callback__`))(y),console.debug("Set up the IndexedDB filesystem synchronizer")}if(g){l("Importing Language Server"),console.debug("Importing Language Server");try{await ue(u),console.debug("Imported Language Server")}catch(f){console.error("Error while importing Language Server",f)}}l("Booting up the Streamlit server."),console.debug("Setting up the Streamlit configuration");const J=await u.runPython(`
|
|
208
|
-
def __bootstrap__(main_script_path, flag_options, shared_worker_mode):
|
|
209
|
-
from stlite_lib.bootstrap import load_config_options, prepare
|
|
210
|
-
|
|
211
|
-
load_config_options(flag_options, shared_worker_mode)
|
|
212
|
-
|
|
213
|
-
prepare(main_script_path, [])
|
|
214
|
-
|
|
215
|
-
__bootstrap__`),M=F(c,e),G={"browser.gatherUsageStats":!1,...p,"runner.fastReruns":!1},V=c!=null;J(M,u.toPy(G),V),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server");const T=u.pyimport("stlite_lib.server.Server")(M,c?N(c):null);return await T.start(),console.debug("Booted up the Streamlit server"),{pyodide:u,httpServer:T,micropip:C,initData:d}}function D(o,c,d,m){function l(s){c({type:"event:progress",data:{message:s}})}const e=(s,n)=>{const r=new MessageChannel;c({type:"event:moduleAutoLoad",data:{packagesToLoad:s}},[r.port2]),n.then(a=>{r.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:a}}),r.port1.close()}).catch(a=>{throw r.port1.postMessage({type:"moduleAutoLoad:error",error:a}),r.port1.close(),a})};let t=null;const i=async s=>{const n=s.data;if(n.type==="initData"){const g=n.data,_={...d,...g};console.debug("Initial data",_),t=ge(o,m,_,e,l),t.then(()=>{c({type:"event:loaded"})}).catch(u=>{console.error(u),c({type:"event:error",data:{error:u}})});return}if(!t)throw new Error("Pyodide initialization has not been started yet.");const r=await t,a=r.pyodide;let p=r.httpServer;const S=r.micropip,{moduleAutoLoad:b}=r.initData,h=s.ports[0];function v(g){h.postMessage(g)}try{switch(n.type){case"reboot":{console.debug("Reboot the Streamlit server",n.data);const{entrypoint:g}=n.data;p.stop(),console.debug("Booting up the Streamlit server");const _=F(m,g);p=a.pyimport("stlite_lib.server.Server")(_),p.start(),console.debug("Booted up the Streamlit server"),v({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",n.data);const{path:g}=n.data;p.start_websocket(g,(_,u)=>{if(u){const w=_;try{const P=w.toJs(),C=P.buffer.slice(P.byteOffset,P.byteOffset+P.byteLength);c({type:"websocket:message",data:{payload:C}},[C])}finally{w.destroy()}}else c({type:"websocket:message",data:{payload:_}})}),v({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",n.data);const{payload:g}=n.data;p.receive_websocket_from_js(g);break}case"http:request":{console.debug("http:request",n.data);const{request:g}=n.data,_=(u,w,P)=>{const C=new Map(w.toJs()),L=P.toJs();console.debug({statusCode:u,headers:C,body:L}),v({type:"http:response",data:{response:{statusCode:u,headers:C,body:L}}})};p.receive_http_from_js(g.method,decodeURIComponent(g.path),g.headers,g.body,_);break}case"file:write":{const{path:g,data:_,opts:u}=n.data,w=F(m,g);b&&typeof _=="string"&&w.endsWith(".py")&&(console.debug(`Auto install the requirements in ${w}`),$(a,e,[_])),console.debug(`Write a file "${w}"`),q(a,w,_,u),v({type:"reply"});break}case"file:rename":{const{oldPath:g,newPath:_}=n.data,u=F(m,g),w=F(m,_);console.debug(`Rename "${u}" to ${w}`),ee(a,u,w),v({type:"reply"});break}case"file:unlink":{const{path:g}=n.data,_=F(m,g);console.debug(`Remove "${_}`),a.FS.unlink(_),v({type:"reply"});break}case"file:read":{const{path:g,opts:_}=n.data;console.debug(`Read "${g}"`);const u=a.FS.readFile(g,_);v({type:"reply:file:read",data:{content:u}});break}case"install":{const{requirements:g}=n.data,_=U(g);console.debug("Install the requirements:",_),await S.install.callKwargs(_,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),v({type:"reply"})});break}case"setEnv":{const{env:g}=n.data;a.pyimport("os").environ.update(a.toPy(g)),console.debug("Successfully set the environment variables",g),v({type:"reply"});break}case"language-server:code_completion":{const g=await me(n.data,a);v({type:"reply:language-server:code_completion",data:g});break}}}catch(g){if(console.error(g),!(g instanceof Error))throw g;const _=new Error(g.message);_.name=g.name,_.stack=g.stack,v({type:"reply",error:_})}};return c({type:"event:start"}),i}const B="abcdefghijklmnopqrstuvwxyz",fe=B.length;function pe(o){let c="";for(let d=0;d<o;d++){const m=Math.floor(Math.random()*fe);c+=B[m]}return c}const x="https://cdn.jsdelivr.net/pyodide/v0.27.6/full/pyodide.mjs";if("postMessage"in self)self.onmessage=D(x,(o,c)=>c?self.postMessage(o,c):self.postMessage(o));else{const o=[];self.onconnect=c=>{let d;do d=pe(4);while(o.includes(d));o.push(d),console.debug("SharedWorker mode.",{appId:d});const m=c.ports[0];m.onmessage=D(x,(l,e)=>e?m.postMessage(l,e):m.postMessage(l),void 0,d),m.start()}}
|