User C submodule? #14171
-
Hello! We have currently a well-working set of custom C modules. They are imported and used in the Python code like this:
To avoid any name conflicts between our and MicroPython builtin modules (current and future), we would like to import our modules as submodules like this:
After imported like this, "module_x" should be usable like before, for example:
and not like this:
Also, if possible, the modules such as "module_x" should be imported only when explicitly listed like above, meaning that if our_package is imported like this:
it shouldn't import all of the subpackages. Is it possible to use subpackages with user C modules, and are they the correct way to achieve the described behavior? Thanks in advance for any advice. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think the only way to do this right now is to override |
Beta Was this translation helpful? Give feedback.
-
@MHe999 You can implement built-in "sub" modules -- you need to enable See https://github.com/micropython/micropython/blob/master/py/mpconfig.h#L894 and https://github.com/micropython/micropython/tree/master/examples/usercmodule/subpackage |
Beta Was this translation helpful? Give feedback.
-
Thanks @dlech and @jimmo for your replies. Jimmo's way seems to do just what I wanted, perfect! |
Beta Was this translation helpful? Give feedback.
@MHe999 You can implement built-in "sub" modules -- you need to enable
MICROPY_MODULE_BUILTIN_SUBPACKAGES
See https://github.com/micropython/micropython/blob/master/py/mpconfig.h#L894 and https://github.com/micropython/micropython/tree/master/examples/usercmodule/subpackage