Skip to content

Run always uses the current project files; reset command restarts Python - #31

Merged
cedricvogel-leo merged 2 commits into
mainfrom
fix/stale-imports
Oct 25, 2026
Merged

cedricvogel-leo merged 2 commits into
mainfrom
fix/stale-imports

Conversation

@cedricvogel-leo

@cedricvogel-leo cedricvogel-leo commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Two small changes for the next release (v0.1.12). The import fix is needed in the IDE before Etappe 4 (v0.1.12 bump after this PR).

1. No stale imported modules (needed before Etappe 4)

The question: does ▶ Ausführen reload changed imported project files (e.g. parser.py next to auswerter.py)?

Measured in Pyodide (programs of several files, run in quick succession):

Case main this PR
helfer.py changed, same size, run right away (twice) new code ✓ ✓
changed, other size ✓ ✓
a new file found ✓ ✓
helfer.py removed, import helfer old module still runs (wert 40) ModuleNotFoundError: No module named 'helfer'
renamed to helfer2.py, old name imported old module still runs ModuleNotFoundError

Changed files were always reloaded: each Run, Tests and Visualize drops the modules of the files it mounts. The modules of files mounted the time before stayed, though, so a removed or renamed file kept running its old code under its old name. CPython would raise ModuleNotFoundError.

Fix (session.py):

  • _glpython_invalidate_modules remembers the paths mounted last time and drops their modules too.
  • It calls importlib.invalidate_caches().
  • sys.dont_write_bytecode = True, so no stale .pyc is possible for a file changed within the same second.

The new scripts/check-runtime-imports.py (in test:runtime) covers changed files (same size, right away), a new file, a removed and a renamed file, and parser.py changed underneath auswerter.py. It fails on main with exactly the two stale cases.

2. { type: 'reset' } restarts Python

The workspace command reset only cleared the console and the visualization. It now does what the Reset button does: restart Python and clear the console. The embed is unaffected, since its Reset remounts the workspace. The IDE's «Python neu starten» (glpython-edu/glpython-edu.github.io#16) remounts the workspace for now, because it pins v0.1.11. It can switch to this command, which avoids remounting the editor, with the v0.1.12 bump.

Lint (known warning only), both builds, test:protocol, test:runtime (now 9 scripts) and test:hints pass.

🤖 Generated with Claude Code

cedricvogel-leo and others added 2 commits October 26, 2026 00:04
A file removed or renamed since the last Run stayed importable under its
old name: its module was only dropped if the file was still mounted, so
`import helfer` kept running the old code instead of raising
ModuleNotFoundError as CPython does. _glpython_invalidate_modules now also
drops the modules of the files mounted the time before, clears the import
system's caches, and no bytecode is written (no stale .pyc for a file
changed within a second). Applies to Run, Tests and Visualize.

check-runtime-imports.py: changed files (same size, at once), a new file,
a removed and a renamed file, parser.py imported through auswerter.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
{ type: 'reset' } only cleared the console and the visualization; Python
kept its namespace. It now does what Reset does (restart and clear), so a
host can offer it elsewhere - the IDE's «Python neu starten» in its menu.
The embed is unaffected: its Reset remounts the workspace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cedricvogel-leo
cedricvogel-leo merged commit 15157d7 into main Oct 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant