top: Replace umodule with module everywhere.#9069
Conversation
Looking at the massive number files that have been changed this looks like needing a lot of changes. |
af00296 to
7e6a9d1
Compare
|
I have updated the tests to translate to just
@robert-hh ... I did this as a series of (many!) one-liners. There was a bit of trial and error and some manual fixups. Almost all of the changes are outside the ports, but in terms of rebasing a port, the one-liner below should get you a long way though if you run this on your branch before doing the rebase. |
|
Thanks. I will try that when the time comes. |
e04e663 to
0b9e093
Compare
Codecov Report
@@ Coverage Diff @@
## master #9069 +/- ##
==========================================
- Coverage 98.40% 98.40% -0.01%
==========================================
Files 156 155 -1
Lines 20622 20539 -83
==========================================
- Hits 20294 20211 -83
Misses 328 328
|
|
Code size report: |
812ca18 to
3d083a1
Compare
|
Now that #11456 is merged I have rebased & updated this.
|
|
Added a mechanism to replace the former weak link system and make explicit the behavior defined in #11456 about extensible vs non-extensible modules. Updated the PR description with details. |
ca40556 to
1bd7804
Compare
|
OK all tests passing at last! @dlech @stinos @andrewleech I think this should alleviate the concerns from #9018. My intention with this PR is now that the only user-visible difference is the output of For people working in the codebase, the main change is the file and symbol renaming, but overall I believe this improves consistency and clarity. |
|
I have finished a full and detailed review of this PR. There are many changes done in the commits here, but a lot of them are simple renames, and most of those are in boilerplate code (eg defining modules and functions). It's definitely great to see things like the tests simplified to just do Overall the changes here are a really good step forward. It simplifies module naming, makes MicroPython behave more like CPython, still allows extensibility of built-ins. |
This renames the builtin-modules, such that help('modules') and printing
the module object will show "module" rather than "umodule".
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <[email protected]>
In order to keep "import umodule" working, the existing mechanism is replaced with a simple fallback to drop the "u". This makes importing of built-ins no longer touch the filesystem, which makes a typical built-in import take ~0.15ms rather than 3-5ms. (Weak links were added in c14a816) This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Also updates #includes. Signed-off-by: Jim Mussared <[email protected]>
Updates any includes, and references from Makefiles/CMake. This essentially reverts what was done long ago in commit 136b5cb This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Signed-off-by: Jim Mussared <[email protected]>
Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This replaces the previous QSTR_null entry in the globals dict which could leak out to Python (e.g. via iteration of mod.__dict__) and could lead to crashes. It results in smaller code size at the expense of turning a lookup into a loop, but the list it is looping over likely only contains one or two elements. To allow a module to register its custom attr function it can use the new `MP_REGISTER_MODULE_DELEGATION` macro. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
When compiling mpy-cross, there is no `sys` module, and so there will be no entries in the `mp_builtin_module_delegation_table`. MSVC doesn't like this, so instead pretend as if the feature isn't enabled at all. Signed-off-by: Jim Mussared <[email protected]>
Otherwise you can get into the confusing state where e.g. sys.ps1 is enabled in config (via `MICROPY_PY_SYS_PS1_PS2`) but still doesn't actually get enabled. Also verify that the required delegation options are enabled in modsys.c. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Previously sys.path could be modified by append/pop or slice assignment. This allows `sys.path = [...]`, which can be simpler in many cases, but also improves CPython compatibility. It also allows sys.path to be set to a tuple which means that you can clear sys.path (e.g. temporarily) with no allocations. This also makes sys.path (and sys.argv for consistency) able to be disabled via mpconfig. The unix port (and upytesthelper) require them, so they explicitly verify that they're enabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Make tests run in an isolated environment (i.e. `import io` would otherwise get the `tests/io` directory). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
- Update guide for extending built-in modules. - Remove any last trace of umodule in other docs. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
This is a MicroPython-specific module that existed to support the old version of uasyncio. It's undocumented and not enabled on all ports and takes up code size unnecessarily. Signed-off-by: Jim Mussared <[email protected]>
|
Thanks @jimmo for all the hard work on this one. |
for micropython/micropython#9069 handle MICROPY_PY_RANDOM_SEED_INIT_FUNC not being defined
Follow-up to #9018 -- this is the groundwork for doing the renaming of all built-in modules as well as renaming files and variables. I have always found the "u" prefix confusing, and although weak links provide a workaround there's still weirdness like the output of
help('modules')etc. See #9018 for more but I strongly feel we should move in a direction of CPython compatibility and consistency.Updated from an earlier version of this PR. This is now no longer a breaking change. It continues the decision in #11456 but makes the implementation of that more explicit by allowing modules to be defined as "extensible" or (default) "non-extensible" rather than inferring this from the u-prefix.
In summary:
umodulenaming anywhere in the code (file names, qstrs, symbols, macros).MP_REGISTER_MODULEorMP_REGISTER_EXTENSIBLE_MODULE. An extensible module can optionally be overridden from the filesystem, whereas a regular one will always bypass the filesystem. (An extensible module is what would have previously had auprefix, e.g.uos).uprefix will still work (this is kind of the inverse of weak links and is unconditionally enabled), and will bypass the filesystem. New code should prefer to use thesys.pathmechanism introduced in py/builtinimport: Allow built-in modules to be packages (v3) #11456 instead (and hopefully we can deprecate the special u-handling later).sys.pathis now assignable (using the same "mutable sys" mechansim assys.ps1etc).Reducing the size of the QSTRs has a small code size decrease (~100 bytes), but this is offset by the extra u-prefix handling and the split built-in modules maps, so there's a net negative code size increase (+12 bytes on PYBV11, +84 bytes on bare-arm). We could make the u-prefix handling conditional, but previously the minimal ports only supported "import umodule" so we should keep that working. However, this PR also removes the
timeqmodule which gives a net saving around -850 bytes on PYBV11.This work was funded through GitHub Sponsors.