MCPcopy Create free account
hub / github.com/SplootCode/splootcode / initialize

Function initialize

packages/runtime-python/src/webworker.ts:250–312  ·  view source on GitHub ↗
(urls: StaticURLs, typeshedPath: string)

Source from the content-addressed store, hash-verified

248}
249
250export const initialize = async (urls: StaticURLs, typeshedPath: string) => {
251 staticURLs = urls
252
253 await tryModuleLoadPyodide()
254
255 executorCode = await (await fetch(urls.executorURL)).text()
256 moduleLoaderCode = await (await fetch(urls.moduleLoaderURL)).text()
257 textGenerationCode = await (await fetch(urls.textGeneratorURL)).text()
258
259 pyodide = await setupPyodide([])
260
261 pyodide.registerJsModule('fakeprint', {
262 stdout: stdout,
263 stderr: stderr,
264 stdin: stdin,
265 })
266 pyodide.registerJsModule('nodetree', {
267 getNodeTree: () => {
268 const nodeTree = getWorkspace().get('main.py').content
269 return pyodide.toPy(nodeTree)
270 },
271 getIterationLimit: () => {
272 if (rerun) {
273 return pyodide.toPy(10000)
274 }
275 return pyodide.toPy(0)
276 },
277 getRunType: () => {
278 return runType as string
279 },
280 getEventData: () => {
281 return pyodide.toPy(eventData)
282 },
283 })
284 pyodide.registerJsModule('runtime_capture', {
285 report: (json_dump) => {
286 const captureMap = new Map()
287 captureMap.set('main.py', JSON.parse(json_dump))
288 sendMessage({
289 type: 'runtime_capture',
290 captures: captureMap,
291 })
292 },
293 })
294 pyodide.registerJsModule('web_response', {
295 report: (json_dump) => {
296 sendMessage({
297 type: 'web_response',
298 response: JSON.parse(json_dump),
299 })
300 },
301 })
302 pyodide.registerJsModule('__splootcode_internal', {
303 sync_fetch: syncFetch,
304 })
305
306 pyodide.globals.set('__name__', '__main__')
307 pyodide.runPython(moduleLoaderCode)

Callers 3

index.tsFile · 0.90

Calls 4

tryModuleLoadPyodideFunction · 0.90
setupPyodideFunction · 0.90
getWorkspaceFunction · 0.85
sendMessageFunction · 0.70

Tested by

no test coverage detected