@innovatorved/code-lab 0.3.0 → 0.3.2
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/ARCHITECTURE.md +4 -2
- package/CHANGELOG.md +38 -0
- package/README.md +15 -5
- package/dist/code-lab.css +52 -2
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +1533 -396
- package/dist/code-lab.js +1532 -395
- package/dist/diagnostics.d.ts +5 -0
- package/dist/extensions/cpp.d.ts +8 -0
- package/dist/extensions/cpp.esm.js +333 -10
- package/dist/extensions/cpp.js +333 -10
- package/dist/extensions/guided-lab.esm.js +1 -1
- package/dist/extensions/guided-lab.js +1 -1
- package/dist/extensions/python.esm.js +117 -104
- package/dist/extensions/python.js +117 -104
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +34 -17
- package/dist/runtime.esm.js +38 -31
- package/dist/runtime.js +38 -31
- package/dist/schemas.d.ts +4 -4
- package/dist/schemas.esm.js +1 -1
- package/dist/schemas.js +1 -1
- package/dist/scm.d.ts +13 -2
- package/dist/search.d.ts +5 -1
- package/dist/shell.esm.js +72 -16
- package/dist/shell.js +72 -16
- package/dist/terminal.esm.js +183 -54
- package/dist/terminal.js +183 -54
- package/dist/workbench/index.d.ts +1 -1
- package/dist/workbench/styles.d.ts +1 -1
- package/dist/zip.d.ts +4 -3
- package/package.json +1 -1
- package/src/code-lab.css +52 -2
- package/src/csp.ts +7 -10
- package/src/diagnostics.ts +42 -3
- package/src/extensions/cpp.ts +303 -9
- package/src/extensions/python.ts +128 -116
- package/src/index.ts +1 -1
- package/src/preview-sw.js +25 -5
- package/src/runtime.ts +36 -29
- package/src/schemas.ts +2 -2
- package/src/scm.ts +106 -19
- package/src/search.ts +71 -27
- package/src/shell.ts +70 -14
- package/src/terminal.ts +181 -52
- package/src/workbench/diff-editor.ts +41 -13
- package/src/workbench/drawer.ts +17 -8
- package/src/workbench/guided-pane.ts +12 -2
- package/src/workbench/share.ts +37 -8
- package/src/workbench/styles.ts +2 -1
- package/src/workbench/toolbar.ts +15 -4
- package/src/workbench.ts +484 -91
- package/src/zip.ts +29 -7
- package/dist/runtime/module-loader.d.ts +0 -11
- package/dist/runtime/vfs.d.ts +0 -31
- package/dist/runtime/wasi-host.d.ts +0 -33
- package/dist/shell/lexer-parser.d.ts +0 -26
|
@@ -4092,7 +4092,7 @@ var GuidedLabExtensionOptionsSchema = external_exports.object({
|
|
|
4092
4092
|
onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
|
|
4093
4093
|
});
|
|
4094
4094
|
var CppToolchainProgressSchema = external_exports.object({
|
|
4095
|
-
stage: external_exports.enum(["downloading", "caching", "extracting", "compiling", "linking", "ready"]),
|
|
4095
|
+
stage: external_exports.enum(["downloading", "caching", "extracting", "compiling", "linking", "ready", "error"]),
|
|
4096
4096
|
loadedBytes: external_exports.number().optional(),
|
|
4097
4097
|
totalBytes: external_exports.number().optional(),
|
|
4098
4098
|
percent: external_exports.number().optional(),
|
|
@@ -5035,68 +5035,73 @@ var PythonToolchainManager = class {
|
|
|
5035
5035
|
if (this.pyodide) return this.pyodide;
|
|
5036
5036
|
if (this._loadingPromise) return this._loadingPromise;
|
|
5037
5037
|
this._loadingPromise = (async () => {
|
|
5038
|
-
|
|
5039
|
-
stage: "downloading",
|
|
5040
|
-
percent: 10,
|
|
5041
|
-
message: "Initializing CPython 3.12 WebAssembly (Pyodide)..."
|
|
5042
|
-
});
|
|
5043
|
-
if (typeof window !== "undefined") {
|
|
5044
|
-
const cdn = this.options.cdnBaseUrl || DEFAULT_PYTHON_CDN_BASE_URL;
|
|
5045
|
-
if (!window.loadPyodide) {
|
|
5046
|
-
await new Promise((resolve, reject) => {
|
|
5047
|
-
const script = document.createElement("script");
|
|
5048
|
-
script.src = `${cdn.replace(/\/+$/, "")}/pyodide.js`;
|
|
5049
|
-
script.onload = () => resolve();
|
|
5050
|
-
script.onerror = () => reject(new Error(`Failed to load pyodide.js from ${script.src}`));
|
|
5051
|
-
document.head.appendChild(script);
|
|
5052
|
-
});
|
|
5053
|
-
}
|
|
5038
|
+
try {
|
|
5054
5039
|
this._emitProgress({
|
|
5055
|
-
stage: "
|
|
5056
|
-
percent:
|
|
5057
|
-
message: "
|
|
5040
|
+
stage: "downloading",
|
|
5041
|
+
percent: 10,
|
|
5042
|
+
message: "Initializing CPython 3.12 WebAssembly (Pyodide)..."
|
|
5058
5043
|
});
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5044
|
+
if (typeof window !== "undefined") {
|
|
5045
|
+
const cdn = this.options.cdnBaseUrl || DEFAULT_PYTHON_CDN_BASE_URL;
|
|
5046
|
+
if (!window.loadPyodide) {
|
|
5047
|
+
await new Promise((resolve, reject) => {
|
|
5048
|
+
const script = document.createElement("script");
|
|
5049
|
+
script.src = `${cdn.replace(/\/+$/, "")}/pyodide.js`;
|
|
5050
|
+
script.onload = () => resolve();
|
|
5051
|
+
script.onerror = () => reject(new Error(`Failed to load pyodide.js from ${script.src}`));
|
|
5052
|
+
document.head.appendChild(script);
|
|
5053
|
+
});
|
|
5054
|
+
}
|
|
5055
|
+
this._emitProgress({
|
|
5056
|
+
stage: "extracting",
|
|
5057
|
+
percent: 50,
|
|
5058
|
+
message: "Bootstrapping Python runtime environment..."
|
|
5059
|
+
});
|
|
5060
|
+
const loadPyodideFn = window.loadPyodide;
|
|
5061
|
+
this.pyodide = await loadPyodideFn({
|
|
5062
|
+
indexURL: cdn
|
|
5063
|
+
});
|
|
5064
|
+
} else {
|
|
5065
|
+
this.pyodide = {
|
|
5066
|
+
FS: {
|
|
5067
|
+
files: /* @__PURE__ */ new Map(),
|
|
5068
|
+
writeFile(p, content) {
|
|
5069
|
+
this.files.set(p, typeof content === "string" ? content : String(content));
|
|
5070
|
+
},
|
|
5071
|
+
readFile(p, opts) {
|
|
5072
|
+
return this.files.get(p) || "";
|
|
5073
|
+
},
|
|
5074
|
+
unlink(p) {
|
|
5075
|
+
this.files.delete(p);
|
|
5076
|
+
},
|
|
5077
|
+
mkdirTree(_p) {
|
|
5078
|
+
}
|
|
5075
5079
|
},
|
|
5076
|
-
|
|
5080
|
+
runPythonAsync: async (code) => {
|
|
5081
|
+
return `Execution mock: ${code.slice(0, 30)}`;
|
|
5077
5082
|
}
|
|
5078
|
-
}
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
if (typeof this.pyodide.loadPackage === "function") {
|
|
5088
|
-
await this.pyodide.loadPackage(pkg);
|
|
5083
|
+
};
|
|
5084
|
+
}
|
|
5085
|
+
if (this.options.preloadPackages && Array.isArray(this.options.preloadPackages)) {
|
|
5086
|
+
for (const pkg of this.options.preloadPackages) {
|
|
5087
|
+
try {
|
|
5088
|
+
if (typeof this.pyodide.loadPackage === "function") {
|
|
5089
|
+
await this.pyodide.loadPackage(pkg);
|
|
5090
|
+
}
|
|
5091
|
+
} catch (err) {
|
|
5089
5092
|
}
|
|
5090
|
-
} catch (err) {
|
|
5091
5093
|
}
|
|
5092
5094
|
}
|
|
5095
|
+
this._emitProgress({
|
|
5096
|
+
stage: "ready",
|
|
5097
|
+
percent: 100,
|
|
5098
|
+
message: "Python 3.12 WebAssembly Toolchain Ready"
|
|
5099
|
+
});
|
|
5100
|
+
return this.pyodide;
|
|
5101
|
+
} catch (err) {
|
|
5102
|
+
this._loadingPromise = null;
|
|
5103
|
+
throw err;
|
|
5093
5104
|
}
|
|
5094
|
-
this._emitProgress({
|
|
5095
|
-
stage: "ready",
|
|
5096
|
-
percent: 100,
|
|
5097
|
-
message: "Python 3.12 WebAssembly Toolchain Ready"
|
|
5098
|
-
});
|
|
5099
|
-
return this.pyodide;
|
|
5100
5105
|
})();
|
|
5101
5106
|
return this._loadingPromise;
|
|
5102
5107
|
}
|
|
@@ -5140,18 +5145,34 @@ var PythonToolchainManager = class {
|
|
|
5140
5145
|
};
|
|
5141
5146
|
const pyodide = await this.ensureLoaded();
|
|
5142
5147
|
if (req.vfs && pyodide.FS) {
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
if (!req.vfs.statSync(fullPath).isDirectory()) {
|
|
5148
|
-
const content = req.vfs.readFileSync(fullPath, "utf8");
|
|
5149
|
-
pyodide.FS.mkdirTree("/workspace");
|
|
5150
|
-
pyodide.FS.writeFile(fullPath, content);
|
|
5148
|
+
const syncVfsDir = (dirPath) => {
|
|
5149
|
+
try {
|
|
5150
|
+
if (typeof pyodide.FS.mkdirTree === "function") {
|
|
5151
|
+
pyodide.FS.mkdirTree(dirPath);
|
|
5151
5152
|
}
|
|
5153
|
+
const entries = req.vfs.readdirSync(dirPath);
|
|
5154
|
+
for (const entry of entries) {
|
|
5155
|
+
if (!entry || entry === "." || entry === "..") continue;
|
|
5156
|
+
const fullPath = `${dirPath === "/" ? "" : dirPath}/${entry}`;
|
|
5157
|
+
try {
|
|
5158
|
+
const st = req.vfs.statSync(fullPath);
|
|
5159
|
+
if (st && typeof st.isDirectory === "function" && st.isDirectory()) {
|
|
5160
|
+
syncVfsDir(fullPath);
|
|
5161
|
+
} else {
|
|
5162
|
+
const parentDir = fullPath.slice(0, fullPath.lastIndexOf("/")) || "/workspace";
|
|
5163
|
+
if (typeof pyodide.FS.mkdirTree === "function") {
|
|
5164
|
+
pyodide.FS.mkdirTree(parentDir);
|
|
5165
|
+
}
|
|
5166
|
+
const content = req.vfs.readFileSync(fullPath, "utf8");
|
|
5167
|
+
pyodide.FS.writeFile(fullPath, content);
|
|
5168
|
+
}
|
|
5169
|
+
} catch (err) {
|
|
5170
|
+
}
|
|
5171
|
+
}
|
|
5172
|
+
} catch (err) {
|
|
5152
5173
|
}
|
|
5153
|
-
}
|
|
5154
|
-
|
|
5174
|
+
};
|
|
5175
|
+
syncVfsDir("/workspace");
|
|
5155
5176
|
}
|
|
5156
5177
|
if (pyodide.FS) {
|
|
5157
5178
|
try {
|
|
@@ -5197,45 +5218,19 @@ var PythonToolchainManager = class {
|
|
|
5197
5218
|
}
|
|
5198
5219
|
});
|
|
5199
5220
|
}
|
|
5200
|
-
const
|
|
5201
|
-
const
|
|
5202
|
-
const bodyLines = [];
|
|
5203
|
-
let inDocstring = false;
|
|
5204
|
-
let docChar = "";
|
|
5205
|
-
for (const l of rawLines) {
|
|
5206
|
-
const t = l.trim();
|
|
5207
|
-
if (!inDocstring && (t.startsWith('"""') || t.startsWith("'''"))) {
|
|
5208
|
-
if (t.length > 3 && (t.endsWith('"""') || t.endsWith("'''"))) {
|
|
5209
|
-
bodyLines.push(l);
|
|
5210
|
-
continue;
|
|
5211
|
-
}
|
|
5212
|
-
inDocstring = true;
|
|
5213
|
-
docChar = t.slice(0, 3);
|
|
5214
|
-
bodyLines.push(l);
|
|
5215
|
-
continue;
|
|
5216
|
-
}
|
|
5217
|
-
if (inDocstring) {
|
|
5218
|
-
if (t.endsWith(docChar)) inDocstring = false;
|
|
5219
|
-
bodyLines.push(l);
|
|
5220
|
-
continue;
|
|
5221
|
-
}
|
|
5222
|
-
if (/^from\s+__future__\s+import\s+/.test(t)) {
|
|
5223
|
-
futureImports.push(t);
|
|
5224
|
-
} else {
|
|
5225
|
-
bodyLines.push(l);
|
|
5226
|
-
}
|
|
5227
|
-
}
|
|
5221
|
+
const fileLabel = JSON.stringify(req.entry || "<exec>");
|
|
5222
|
+
const encodedCode = JSON.stringify(codeToRun);
|
|
5228
5223
|
const runnerWrapper = `
|
|
5229
|
-
${futureImports.join("\n")}
|
|
5230
5224
|
import sys, tracemalloc
|
|
5231
5225
|
if '/usr/lib/python' not in sys.path:
|
|
5232
5226
|
sys.path.insert(0, '/usr/lib/python')
|
|
5233
5227
|
if '/workspace' not in sys.path:
|
|
5234
5228
|
sys.path.insert(0, '/workspace')
|
|
5235
5229
|
|
|
5230
|
+
_cl_user_code = ${encodedCode}
|
|
5236
5231
|
tracemalloc.start()
|
|
5237
5232
|
try:
|
|
5238
|
-
|
|
5233
|
+
exec(compile(_cl_user_code, ${fileLabel}, 'exec'), globals())
|
|
5239
5234
|
finally:
|
|
5240
5235
|
_, _peak = tracemalloc.get_traced_memory()
|
|
5241
5236
|
tracemalloc.stop()
|
|
@@ -5278,20 +5273,38 @@ finally:
|
|
|
5278
5273
|
}
|
|
5279
5274
|
}
|
|
5280
5275
|
if (req.vfs && pyodide.FS && typeof pyodide.FS.readdir === "function") {
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5276
|
+
const syncBackPyodideDir = (dirPath) => {
|
|
5277
|
+
try {
|
|
5278
|
+
const entries = pyodide.FS.readdir(dirPath);
|
|
5279
|
+
for (const f of entries) {
|
|
5280
|
+
if (!f || f === "." || f === "..") continue;
|
|
5281
|
+
const p = `${dirPath}/${f}`;
|
|
5286
5282
|
try {
|
|
5287
|
-
|
|
5288
|
-
|
|
5283
|
+
let isDir = false;
|
|
5284
|
+
if (typeof pyodide.FS.stat === "function" && typeof pyodide.FS.isDir === "function") {
|
|
5285
|
+
const st = pyodide.FS.stat(p);
|
|
5286
|
+
isDir = Boolean(pyodide.FS.isDir(st.mode));
|
|
5287
|
+
}
|
|
5288
|
+
if (isDir) {
|
|
5289
|
+
if (typeof req.vfs.mkdirSync === "function" && !req.vfs.existsSync(p)) {
|
|
5290
|
+
req.vfs.mkdirSync(p, { recursive: true });
|
|
5291
|
+
}
|
|
5292
|
+
syncBackPyodideDir(p);
|
|
5293
|
+
} else {
|
|
5294
|
+
const parentDir = p.slice(0, p.lastIndexOf("/")) || "/workspace";
|
|
5295
|
+
if (typeof req.vfs.mkdirSync === "function" && !req.vfs.existsSync(parentDir)) {
|
|
5296
|
+
req.vfs.mkdirSync(parentDir, { recursive: true });
|
|
5297
|
+
}
|
|
5298
|
+
const content = pyodide.FS.readFile(p, { encoding: "utf8" });
|
|
5299
|
+
req.vfs.writeFileSync(p, content);
|
|
5300
|
+
}
|
|
5289
5301
|
} catch (err) {
|
|
5290
5302
|
}
|
|
5291
5303
|
}
|
|
5304
|
+
} catch (err) {
|
|
5292
5305
|
}
|
|
5293
|
-
}
|
|
5294
|
-
|
|
5306
|
+
};
|
|
5307
|
+
syncBackPyodideDir("/workspace");
|
|
5295
5308
|
}
|
|
5296
5309
|
const durationMs = performance.now() - start;
|
|
5297
5310
|
return {
|
|
@@ -4125,7 +4125,7 @@ var CodeLabPython = (() => {
|
|
|
4125
4125
|
onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
|
|
4126
4126
|
});
|
|
4127
4127
|
var CppToolchainProgressSchema = external_exports.object({
|
|
4128
|
-
stage: external_exports.enum(["downloading", "caching", "extracting", "compiling", "linking", "ready"]),
|
|
4128
|
+
stage: external_exports.enum(["downloading", "caching", "extracting", "compiling", "linking", "ready", "error"]),
|
|
4129
4129
|
loadedBytes: external_exports.number().optional(),
|
|
4130
4130
|
totalBytes: external_exports.number().optional(),
|
|
4131
4131
|
percent: external_exports.number().optional(),
|
|
@@ -5068,68 +5068,73 @@ assert_false = ASSERT_FALSE
|
|
|
5068
5068
|
if (this.pyodide) return this.pyodide;
|
|
5069
5069
|
if (this._loadingPromise) return this._loadingPromise;
|
|
5070
5070
|
this._loadingPromise = (async () => {
|
|
5071
|
-
|
|
5072
|
-
stage: "downloading",
|
|
5073
|
-
percent: 10,
|
|
5074
|
-
message: "Initializing CPython 3.12 WebAssembly (Pyodide)..."
|
|
5075
|
-
});
|
|
5076
|
-
if (typeof window !== "undefined") {
|
|
5077
|
-
const cdn = this.options.cdnBaseUrl || DEFAULT_PYTHON_CDN_BASE_URL;
|
|
5078
|
-
if (!window.loadPyodide) {
|
|
5079
|
-
await new Promise((resolve, reject) => {
|
|
5080
|
-
const script = document.createElement("script");
|
|
5081
|
-
script.src = `${cdn.replace(/\/+$/, "")}/pyodide.js`;
|
|
5082
|
-
script.onload = () => resolve();
|
|
5083
|
-
script.onerror = () => reject(new Error(`Failed to load pyodide.js from ${script.src}`));
|
|
5084
|
-
document.head.appendChild(script);
|
|
5085
|
-
});
|
|
5086
|
-
}
|
|
5071
|
+
try {
|
|
5087
5072
|
this._emitProgress({
|
|
5088
|
-
stage: "
|
|
5089
|
-
percent:
|
|
5090
|
-
message: "
|
|
5073
|
+
stage: "downloading",
|
|
5074
|
+
percent: 10,
|
|
5075
|
+
message: "Initializing CPython 3.12 WebAssembly (Pyodide)..."
|
|
5091
5076
|
});
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5077
|
+
if (typeof window !== "undefined") {
|
|
5078
|
+
const cdn = this.options.cdnBaseUrl || DEFAULT_PYTHON_CDN_BASE_URL;
|
|
5079
|
+
if (!window.loadPyodide) {
|
|
5080
|
+
await new Promise((resolve, reject) => {
|
|
5081
|
+
const script = document.createElement("script");
|
|
5082
|
+
script.src = `${cdn.replace(/\/+$/, "")}/pyodide.js`;
|
|
5083
|
+
script.onload = () => resolve();
|
|
5084
|
+
script.onerror = () => reject(new Error(`Failed to load pyodide.js from ${script.src}`));
|
|
5085
|
+
document.head.appendChild(script);
|
|
5086
|
+
});
|
|
5087
|
+
}
|
|
5088
|
+
this._emitProgress({
|
|
5089
|
+
stage: "extracting",
|
|
5090
|
+
percent: 50,
|
|
5091
|
+
message: "Bootstrapping Python runtime environment..."
|
|
5092
|
+
});
|
|
5093
|
+
const loadPyodideFn = window.loadPyodide;
|
|
5094
|
+
this.pyodide = await loadPyodideFn({
|
|
5095
|
+
indexURL: cdn
|
|
5096
|
+
});
|
|
5097
|
+
} else {
|
|
5098
|
+
this.pyodide = {
|
|
5099
|
+
FS: {
|
|
5100
|
+
files: /* @__PURE__ */ new Map(),
|
|
5101
|
+
writeFile(p, content) {
|
|
5102
|
+
this.files.set(p, typeof content === "string" ? content : String(content));
|
|
5103
|
+
},
|
|
5104
|
+
readFile(p, opts) {
|
|
5105
|
+
return this.files.get(p) || "";
|
|
5106
|
+
},
|
|
5107
|
+
unlink(p) {
|
|
5108
|
+
this.files.delete(p);
|
|
5109
|
+
},
|
|
5110
|
+
mkdirTree(_p) {
|
|
5111
|
+
}
|
|
5108
5112
|
},
|
|
5109
|
-
|
|
5113
|
+
runPythonAsync: async (code) => {
|
|
5114
|
+
return `Execution mock: ${code.slice(0, 30)}`;
|
|
5110
5115
|
}
|
|
5111
|
-
}
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
if (typeof this.pyodide.loadPackage === "function") {
|
|
5121
|
-
await this.pyodide.loadPackage(pkg);
|
|
5116
|
+
};
|
|
5117
|
+
}
|
|
5118
|
+
if (this.options.preloadPackages && Array.isArray(this.options.preloadPackages)) {
|
|
5119
|
+
for (const pkg of this.options.preloadPackages) {
|
|
5120
|
+
try {
|
|
5121
|
+
if (typeof this.pyodide.loadPackage === "function") {
|
|
5122
|
+
await this.pyodide.loadPackage(pkg);
|
|
5123
|
+
}
|
|
5124
|
+
} catch (err) {
|
|
5122
5125
|
}
|
|
5123
|
-
} catch (err) {
|
|
5124
5126
|
}
|
|
5125
5127
|
}
|
|
5128
|
+
this._emitProgress({
|
|
5129
|
+
stage: "ready",
|
|
5130
|
+
percent: 100,
|
|
5131
|
+
message: "Python 3.12 WebAssembly Toolchain Ready"
|
|
5132
|
+
});
|
|
5133
|
+
return this.pyodide;
|
|
5134
|
+
} catch (err) {
|
|
5135
|
+
this._loadingPromise = null;
|
|
5136
|
+
throw err;
|
|
5126
5137
|
}
|
|
5127
|
-
this._emitProgress({
|
|
5128
|
-
stage: "ready",
|
|
5129
|
-
percent: 100,
|
|
5130
|
-
message: "Python 3.12 WebAssembly Toolchain Ready"
|
|
5131
|
-
});
|
|
5132
|
-
return this.pyodide;
|
|
5133
5138
|
})();
|
|
5134
5139
|
return this._loadingPromise;
|
|
5135
5140
|
}
|
|
@@ -5173,18 +5178,34 @@ assert_false = ASSERT_FALSE
|
|
|
5173
5178
|
};
|
|
5174
5179
|
const pyodide = await this.ensureLoaded();
|
|
5175
5180
|
if (req.vfs && pyodide.FS) {
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
if (!req.vfs.statSync(fullPath).isDirectory()) {
|
|
5181
|
-
const content = req.vfs.readFileSync(fullPath, "utf8");
|
|
5182
|
-
pyodide.FS.mkdirTree("/workspace");
|
|
5183
|
-
pyodide.FS.writeFile(fullPath, content);
|
|
5181
|
+
const syncVfsDir = (dirPath) => {
|
|
5182
|
+
try {
|
|
5183
|
+
if (typeof pyodide.FS.mkdirTree === "function") {
|
|
5184
|
+
pyodide.FS.mkdirTree(dirPath);
|
|
5184
5185
|
}
|
|
5186
|
+
const entries = req.vfs.readdirSync(dirPath);
|
|
5187
|
+
for (const entry of entries) {
|
|
5188
|
+
if (!entry || entry === "." || entry === "..") continue;
|
|
5189
|
+
const fullPath = `${dirPath === "/" ? "" : dirPath}/${entry}`;
|
|
5190
|
+
try {
|
|
5191
|
+
const st = req.vfs.statSync(fullPath);
|
|
5192
|
+
if (st && typeof st.isDirectory === "function" && st.isDirectory()) {
|
|
5193
|
+
syncVfsDir(fullPath);
|
|
5194
|
+
} else {
|
|
5195
|
+
const parentDir = fullPath.slice(0, fullPath.lastIndexOf("/")) || "/workspace";
|
|
5196
|
+
if (typeof pyodide.FS.mkdirTree === "function") {
|
|
5197
|
+
pyodide.FS.mkdirTree(parentDir);
|
|
5198
|
+
}
|
|
5199
|
+
const content = req.vfs.readFileSync(fullPath, "utf8");
|
|
5200
|
+
pyodide.FS.writeFile(fullPath, content);
|
|
5201
|
+
}
|
|
5202
|
+
} catch (err) {
|
|
5203
|
+
}
|
|
5204
|
+
}
|
|
5205
|
+
} catch (err) {
|
|
5185
5206
|
}
|
|
5186
|
-
}
|
|
5187
|
-
|
|
5207
|
+
};
|
|
5208
|
+
syncVfsDir("/workspace");
|
|
5188
5209
|
}
|
|
5189
5210
|
if (pyodide.FS) {
|
|
5190
5211
|
try {
|
|
@@ -5230,45 +5251,19 @@ assert_false = ASSERT_FALSE
|
|
|
5230
5251
|
}
|
|
5231
5252
|
});
|
|
5232
5253
|
}
|
|
5233
|
-
const
|
|
5234
|
-
const
|
|
5235
|
-
const bodyLines = [];
|
|
5236
|
-
let inDocstring = false;
|
|
5237
|
-
let docChar = "";
|
|
5238
|
-
for (const l of rawLines) {
|
|
5239
|
-
const t = l.trim();
|
|
5240
|
-
if (!inDocstring && (t.startsWith('"""') || t.startsWith("'''"))) {
|
|
5241
|
-
if (t.length > 3 && (t.endsWith('"""') || t.endsWith("'''"))) {
|
|
5242
|
-
bodyLines.push(l);
|
|
5243
|
-
continue;
|
|
5244
|
-
}
|
|
5245
|
-
inDocstring = true;
|
|
5246
|
-
docChar = t.slice(0, 3);
|
|
5247
|
-
bodyLines.push(l);
|
|
5248
|
-
continue;
|
|
5249
|
-
}
|
|
5250
|
-
if (inDocstring) {
|
|
5251
|
-
if (t.endsWith(docChar)) inDocstring = false;
|
|
5252
|
-
bodyLines.push(l);
|
|
5253
|
-
continue;
|
|
5254
|
-
}
|
|
5255
|
-
if (/^from\s+__future__\s+import\s+/.test(t)) {
|
|
5256
|
-
futureImports.push(t);
|
|
5257
|
-
} else {
|
|
5258
|
-
bodyLines.push(l);
|
|
5259
|
-
}
|
|
5260
|
-
}
|
|
5254
|
+
const fileLabel = JSON.stringify(req.entry || "<exec>");
|
|
5255
|
+
const encodedCode = JSON.stringify(codeToRun);
|
|
5261
5256
|
const runnerWrapper = `
|
|
5262
|
-
${futureImports.join("\n")}
|
|
5263
5257
|
import sys, tracemalloc
|
|
5264
5258
|
if '/usr/lib/python' not in sys.path:
|
|
5265
5259
|
sys.path.insert(0, '/usr/lib/python')
|
|
5266
5260
|
if '/workspace' not in sys.path:
|
|
5267
5261
|
sys.path.insert(0, '/workspace')
|
|
5268
5262
|
|
|
5263
|
+
_cl_user_code = ${encodedCode}
|
|
5269
5264
|
tracemalloc.start()
|
|
5270
5265
|
try:
|
|
5271
|
-
|
|
5266
|
+
exec(compile(_cl_user_code, ${fileLabel}, 'exec'), globals())
|
|
5272
5267
|
finally:
|
|
5273
5268
|
_, _peak = tracemalloc.get_traced_memory()
|
|
5274
5269
|
tracemalloc.stop()
|
|
@@ -5311,20 +5306,38 @@ finally:
|
|
|
5311
5306
|
}
|
|
5312
5307
|
}
|
|
5313
5308
|
if (req.vfs && pyodide.FS && typeof pyodide.FS.readdir === "function") {
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5309
|
+
const syncBackPyodideDir = (dirPath) => {
|
|
5310
|
+
try {
|
|
5311
|
+
const entries = pyodide.FS.readdir(dirPath);
|
|
5312
|
+
for (const f of entries) {
|
|
5313
|
+
if (!f || f === "." || f === "..") continue;
|
|
5314
|
+
const p = `${dirPath}/${f}`;
|
|
5319
5315
|
try {
|
|
5320
|
-
|
|
5321
|
-
|
|
5316
|
+
let isDir = false;
|
|
5317
|
+
if (typeof pyodide.FS.stat === "function" && typeof pyodide.FS.isDir === "function") {
|
|
5318
|
+
const st = pyodide.FS.stat(p);
|
|
5319
|
+
isDir = Boolean(pyodide.FS.isDir(st.mode));
|
|
5320
|
+
}
|
|
5321
|
+
if (isDir) {
|
|
5322
|
+
if (typeof req.vfs.mkdirSync === "function" && !req.vfs.existsSync(p)) {
|
|
5323
|
+
req.vfs.mkdirSync(p, { recursive: true });
|
|
5324
|
+
}
|
|
5325
|
+
syncBackPyodideDir(p);
|
|
5326
|
+
} else {
|
|
5327
|
+
const parentDir = p.slice(0, p.lastIndexOf("/")) || "/workspace";
|
|
5328
|
+
if (typeof req.vfs.mkdirSync === "function" && !req.vfs.existsSync(parentDir)) {
|
|
5329
|
+
req.vfs.mkdirSync(parentDir, { recursive: true });
|
|
5330
|
+
}
|
|
5331
|
+
const content = pyodide.FS.readFile(p, { encoding: "utf8" });
|
|
5332
|
+
req.vfs.writeFileSync(p, content);
|
|
5333
|
+
}
|
|
5322
5334
|
} catch (err) {
|
|
5323
5335
|
}
|
|
5324
5336
|
}
|
|
5337
|
+
} catch (err) {
|
|
5325
5338
|
}
|
|
5326
|
-
}
|
|
5327
|
-
|
|
5339
|
+
};
|
|
5340
|
+
syncBackPyodideDir("/workspace");
|
|
5328
5341
|
}
|
|
5329
5342
|
const durationMs = performance.now() - start;
|
|
5330
5343
|
return {
|
package/dist/index.d.ts
CHANGED