Skip to content

Commit

Permalink
fix: dev time console bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Jul 1, 2024
1 parent ae754e1 commit 2c023d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/components/console/HeadlessConsole.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import type { ConsoleAPI } from "$py/app/console";
import { getPy } from "$lib/pyodide";
import { onMount } from "svelte";
import { onDestroy, onMount } from "svelte";
export let ready = false;
export let status: Status = "complete";
Expand All @@ -37,6 +37,8 @@
ready = true;
});
onDestroy(() => pyConsole?.destroy());
export function pushLog(item: Item, behind?: Item) {
if (!log.length)
return void (log = [item]);
Expand Down
4 changes: 3 additions & 1 deletion src/python/app/console.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PyProxy } from "pyodide/ffi";

export class Result<T> {
status: "complete" | "incomplete" | "syntax-error";
future: Promise<T>;
Expand All @@ -11,7 +13,7 @@ class EnhancedConsole {
pop(): void;
}

export class ConsoleAPI {
export class ConsoleAPI extends PyProxy {
complete(source: string): [string[], number];
console: EnhancedConsole;
push(line: string): Result<any>;
Expand Down
6 changes: 6 additions & 0 deletions src/python/app/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
patch_linecache()

for path in sys.path[:]:
if (file := Path(path) / self.filename).is_file():
file.unlink()
sys.path.remove(path)

with TemporaryDirectory(delete=False) as tempdir:
sys.path.append(tempdir)
self.fake_file = Path(tempdir) / self.filename
Expand All @@ -48,6 +53,7 @@ def __init__(self, *args, **kwargs):

def __del__(self):
with suppress(Exception):
self.fake_file.unlink()
sys.path.remove(str(self.fake_file.parent))

def _append_source_file(self, source: str):
Expand Down

0 comments on commit 2c023d7

Please sign in to comment.