modular icon indicating copy to clipboard operation
modular copied to clipboard

[stdlib] Enable Python module-level Mojo imports

Open miili opened this issue 4 months ago • 4 comments

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 assert with meaningful ImportError raises.
  • 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

miili avatar Oct 27 '25 11:10 miili

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Oct 27 '25 11:10 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA

miili avatar Oct 27 '25 11:10 miili

!sync

ConnorGray avatar Oct 31 '25 14:10 ConnorGray

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 🙂

ConnorGray avatar Oct 31 '25 14:10 ConnorGray

!sync

ConnorGray avatar Nov 18 '25 18:11 ConnorGray