sim: Ensure custom import machinery doesn't hide builtin modules#302
Open
edwinbalani wants to merge 1 commit into
Open
sim: Ensure custom import machinery doesn't hide builtin modules#302edwinbalani wants to merge 1 commit into
edwinbalani wants to merge 1 commit into
Conversation
The UnderscoreFinder is intended to override the import-time finding of selected modules, but it is implemented by completely wrapping the original BuiltinImporter that would be found in sys.meta_path at startup. Therefore the UnderscoreFinder is obliged to pass through all find_spec() calls that it doesn't otherwise override, to avoid accidentally breaking importation of other modules. (It doesn't have to consult the wrapped PathFinder by default, because we add another PathFinder to sys.meta_path.)
edwinbalani
commented
May 15, 2026
Comment on lines
+52
to
+53
| # Suppress the simulator's sys.path prefixed entries temporarily while | ||
| # looking for 'json' or 'tarfile'. |
Member
Author
There was a problem hiding this comment.
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?
Member
Author
|
Here's the explanation I wrote in the commit message description - worth a fact-check by anyone who knows better, particularly as to the intent of the UnderscoreFinder: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
There have been a couple of reports in the badge channel of weird failures to import Python standard library modules while trying to start the simulator, in September and again today. I wrote off the first as a weird/broken Python installation, even though I'd noted there were some
importlibshenanigans going on insim/run.py, but the second occurrence (happening to another person) led me to look closely at the shenanigans.I think these changes are the fix required to the sim's custom meta path finder. However I haven't worked on one of these before and I'd appreciate some eyes and more diverse testing than just my system.
Issue links
Resolves #278 - even though this issue was closed by the author, a
ModuleNotFoundErrortrying to import_astis exactly the reported issue in the second occurrence reported on the badge channel, so I'm fairly sure the cause is the same.