py/builtinimport.c: Implement a "frozen overlay" using the filesystem. #8922
+82
−13
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.
Draft/WIP.
Haven't given much thought to code size (especially when the feature is disabled). The
allow_frozen
flag to thestat_
methods in particular needs some thought.I considered a few other ways of implementing this, in particular making it detect the filesystem version of the file while searching sys.path but this creates a complicated interaction with things like loading the parent modules. Instead this approach says "a frozen file can be overridden by a filesystem file" rather than interfering with file discovery.
Filesystem means "VFS", so note this would work with
mpremote mount
too... (perhaps via #8914 we could have a way to make mpremote construct this "files that have changed relative to freezing" directory to mount)This allows frozen files to be overridden by filesystem .py or .mpy files from a specific path specified in
micropython.frozen_overlay
.The idea is that during development, a whole directory tree might be frozen
but for fast testing iteration it can be useful to just replace a couple
of files. This allows the same directory structure to be defined, but any
time a file is about to be loaded from frozen, the same path is attempted
in the overlay path.
Note: the overlay path should not be part of sys.path, otherwise it will
prevent the frozen path from being found.