[stdlib] Enable Python module-level Mojo imports
Adds module-level imports to MojoImporter.
This enables shipping Python packages with mojo code, where the package only needs a runtime dependency on the Mojo package.
from awesome_package.extensions.mojo import factorial
factorial(123)
The compiler and hashing logic are the same. The importer will create a __mojocache__ directory in the module path. I.e. <package_path>/autumn_package/extensions/mojo/__mojocache__/factorial.ae43a431b521.so.
- Improved clarity, renamed helper functions and removed implicit comments.
- Replaced
assertwith meaningfulImportErrorraises. - Implemented
invalidate_caches, removing compiled Mojo extension. https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches - Compiled files: Removed implicit
hash-prefix from filename - Docs: Added documentation of module-level Python imports
All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I hereby sign the CLA
!sync
Hi @miili thank you so much for making this all around great contribution, especially from a first-time contributor! 🔥
This is a nice improvement to the UX of Python package authors, enabling them to better encapsulate their Mojo extensions. I've started the process of syncing this in to our internal sources. I may make a few minor changes as I integrate this, but all around this looks really good, and thank you again 🙂
!sync