mirror of https://github.com/astral-sh/ruff
[ty] Fix playground crash when file name includes path separator (#21151)
This commit is contained in:
parent
47e41ac6b6
commit
f79044478c
|
|
@ -103,11 +103,17 @@ function Content({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SANDBOX_BASE_DIRECTORY = "/playground/";
|
||||||
|
|
||||||
function Run({ files, theme }: { files: ReadonlyFiles; theme: Theme }) {
|
function Run({ files, theme }: { files: ReadonlyFiles; theme: Theme }) {
|
||||||
const [runOutput, setRunOutput] = useState<Promise<string> | null>(null);
|
const [runOutput, setRunOutput] = useState<Promise<string> | null>(null);
|
||||||
const handleRun = () => {
|
const handleRun = () => {
|
||||||
const output = (async () => {
|
const output = (async () => {
|
||||||
const pyodide = await loadPyodide();
|
const pyodide = await loadPyodide({
|
||||||
|
env: {
|
||||||
|
HOME: SANDBOX_BASE_DIRECTORY,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
let combined_output = "";
|
let combined_output = "";
|
||||||
|
|
||||||
|
|
@ -122,7 +128,17 @@ function Run({ files, theme }: { files: ReadonlyFiles; theme: Theme }) {
|
||||||
|
|
||||||
let fileName = "main.py";
|
let fileName = "main.py";
|
||||||
for (const file of files.index) {
|
for (const file of files.index) {
|
||||||
pyodide.FS.writeFile(file.name, files.contents[file.id]);
|
const last_separator = file.name.lastIndexOf("/");
|
||||||
|
|
||||||
|
if (last_separator !== -1) {
|
||||||
|
const directory =
|
||||||
|
SANDBOX_BASE_DIRECTORY + file.name.slice(0, last_separator);
|
||||||
|
pyodide.FS.mkdirTree(directory);
|
||||||
|
}
|
||||||
|
pyodide.FS.writeFile(
|
||||||
|
SANDBOX_BASE_DIRECTORY + file.name,
|
||||||
|
files.contents[file.id],
|
||||||
|
);
|
||||||
|
|
||||||
if (file.id === files.selected) {
|
if (file.id === files.selected) {
|
||||||
fileName = file.name;
|
fileName = file.name;
|
||||||
|
|
@ -133,7 +149,7 @@ function Run({ files, theme }: { files: ReadonlyFiles; theme: Theme }) {
|
||||||
const globals = dict();
|
const globals = dict();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Patch up reveal types
|
// Patch `reveal_type` to print runtime values
|
||||||
pyodide.runPython(`
|
pyodide.runPython(`
|
||||||
import builtins
|
import builtins
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue