Consider an application that has the following module file:
foo/bar/quux.py
Put an import statement in some other file:
When freezing the module with mpy-tool.py, the names foo.bar and quux are collected. However:
foo.bar.quux is not collected, which will be created as a qstr at runtime, because sys.modules uses it as a key
- neither
foo nor bar is collected. bar will be created as a qstr at runtime, because the dict of foo needs to insert it as a key
Of course, if we use relative imports, there's a similar problem: in foo/bar/baz.py, from . import quux should (but can't really know to) also collect foo.bar.quux despite the string not existing anywhere in the file.
I'm not sure if this is something to solve in mpy-tool itself, or whether there should be a separate step that collects symbols in this way. But it seems that using file names to generate both the fully qualified module name and the individual components would be the right thing to do. (that is basically the workaround i'm using: generate all_modules.py that walk the filesystem and convert every py file name to import that.file.name, which collects "that.file.name", and that.file.name which collects "that"", "file" and "name")
Consider an application that has the following module file:
foo/bar/quux.pyPut an import statement in some other file:
When freezing the module with
mpy-tool.py, the namesfoo.barandquuxare collected. However:foo.bar.quuxis not collected, which will be created as a qstr at runtime, becausesys.modulesuses it as a keyfoonorbaris collected.barwill be created as a qstr at runtime, because the dict offooneeds to insert it as a keyOf course, if we use relative imports, there's a similar problem: in
foo/bar/baz.py,from . import quuxshould (but can't really know to) also collectfoo.bar.quuxdespite the string not existing anywhere in the file.I'm not sure if this is something to solve in
mpy-toolitself, or whether there should be a separate step that collects symbols in this way. But it seems that using file names to generate both the fully qualified module name and the individual components would be the right thing to do. (that is basically the workaround i'm using: generateall_modules.pythat walk the filesystem and convert every py file name toimport that.file.name, which collects"that.file.name", andthat.file.namewhich collects"that"","file"and"name")