MCPcopy Index your code
hub / github.com/pyscript/pyscript / execute

Function execute

core/src/plugins/py-editor.js:44–161  ·  view source on GitHub ↗
({ currentTarget, script }, onBeforeRun = "")

Source from the content-addressed store, hash-verified

42};
43
44async function execute({ currentTarget, script }, onBeforeRun = "") {
45 const { env, pySrc, outDiv } = this;
46 const hasRunButton = !!currentTarget;
47
48 if (hasRunButton) {
49 currentTarget.classList.add("running");
50 currentTarget.innerHTML = STOP_BUTTON;
51 outDiv.innerHTML = "";
52 }
53
54 if (!envs.has(env)) {
55 const srcLink = URL.createObjectURL(new Blob([""]));
56 const details = {
57 type: this.interpreter,
58 serviceWorker: this.serviceWorker,
59 };
60 const { config } = this;
61 if (config) {
62 // verify that config can be parsed and used
63 try {
64 details.configURL = relative_url(config);
65 if (config.endsWith(".toml")) {
66 const [{ parse }, toml] = await Promise.all([
67 import(
68 /* webpackIgnore: true */ "../3rd-party/toml.js"
69 ),
70 fetch(config).then((r) => r.ok && r.text()),
71 ]);
72 details.config = parse(validate(config, toml));
73 } else if (config.endsWith(".json")) {
74 const json = await fetch(config).then(
75 (r) => r.ok && r.json(),
76 );
77 details.config = validate(config, json);
78 } else {
79 details.configURL = relative_url("./config.txt");
80 details.config = JSON.parse(config);
81 }
82 details.version = offline_interpreter(details.config);
83 } catch (error) {
84 notify(error);
85 return;
86 }
87 } else {
88 details.config = {};
89 }
90
91 const xworker = XWorker.call(new Hook(null, hooks), srcLink, details);
92
93 // expose xworker like in terminal or other workers to allow
94 // creation and destruction of editors on the fly
95 if (hasRunButton) {
96 for (const type of TYPES.keys()) {
97 script = getRelatedScript(currentTarget, type);
98 if (script) break;
99 }
100 }
101

Callers 1

index.jsFile · 0.85

Calls 15

relative_urlFunction · 0.90
offline_interpreterFunction · 0.90
notifyFunction · 0.90
validateFunction · 0.85
getRelatedScriptFunction · 0.85
resolveFunction · 0.85
hasMethod · 0.80
errorMethod · 0.80
fetchFunction · 0.50
parseFunction · 0.50
addMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected