Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sim/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,26 @@ def __init__(self, builtin, pathfinder):
self.pathfinder = pathfinder

def find_spec(self, fullname, path, target=None):
# Our fake 'time' module wants to import _time as a backdoor to the
# original time module, which is a builtin C module. Invoke the
# BuiltinImporter with "time" to satisfy this.
if fullname == "_time":
return self.builtin.find_spec("time", path, target)
if fullname in ["random", "math"]:
return self.builtin.find_spec(fullname, path, target)

# Suppress the simulator's sys.path prefixed entries temporarily while
# looking for 'json' or 'tarfile'.
Comment on lines +52 to +53

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find an obvious other json or tarfile that would have been found if we didn't do this workaround. However, out of the sys.path entries that the sim adds below, I don't have a .../build-tilgdagon/frozen_mpy (presumably I have to compile something).

Does anyone know if a json/tarfile in that location is what these lines are trying to avoid?

if fullname in ["json", "tarfile"]:
sys_path_saved = sys.path
sys.path = sys_path_orig
res = self.pathfinder.find_spec(fullname, path, target)
sys.path = sys_path_saved
return res

# Provide a general fallback to other builtin (C) modules.
# It's OK to do this indiscriminately as the BuiltinImporter won't find
# modules that aren't builtin.
return self.builtin.find_spec(fullname, path, target)


# sys.meta_path.insert(0, Hook())

Expand Down
Loading