← index #8209PR #8922
Related · high · value 1.750
QUERY · ISSUE

Frozen MPY in fodler are overrided by folder on VFS

openby petrkropened 2022-01-25updated 2022-01-27
py-core

in 1.18 (exact commit do not know) was proabbly changed behavior with FROZEN modules.

Consider situation you frozed few libraries in custom build under some path, like
FROZEN: /utils/foo.mpy

when you go to REPL, you can use it by
import utils.foo

But when you create folder on VFS /utils and upload another library bar.py (or bar.mpy), then foo stop works

>>> import utils.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'utils.foo

in some older revisions this works fine and prioritized search in frozen, then /if not found/ used VFS path.

if '.frozen' and '' are swapped in sys.path, then frozen modules start works, but VFS stop works

CANDIDATE · PULL REQUEST

py/builtinimport.c: Implement a "frozen overlay" using the filesystem.

openby jimmoopened 2022-07-18updated 2024-03-07
py-core

Draft/WIP.

Haven't given much thought to code size (especially when the feature is disabled). The allow_frozen flag to the stat_ 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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied