shared/runtime/pyexec: Set __file__ for file input when enabled.

When `MICROPY_MODULE___FILE__` is enabled and parsing file input, set the
global `__file__` variable to the source filename. This matches the
behavior of the unix port and provides the current filename to the
executing script.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit is contained in:
Andrew Leech
2025-05-26 19:28:40 +10:00
committed by Damien George
parent 5b3c928f53
commit 3b2b8dd538
3 changed files with 11 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
# Test that __file__ is set correctly for script execution
try:
print("__file__ =", __file__)
except NameError:
print("__file__ not defined")

View File

@@ -0,0 +1 @@
__file__ = cmdline/cmd_file_variable.py