Skip to content

PyO3 submodules in Rust/Python mixed projects #1540

Discussion options

You must be logged in to vote

Summary of the solution:

  1. Using maturin 0.14.16 or higher
  2. Set module-name = "nyx_space._nyx_space" in pyproject.toml
  3. Use _nyx_space as #[pymodule] function name
  4. Use from ._nyx_space import cosmic in python/nyx_space/init.py
  5. In the register_ functions that add the submodule, make sure to use the package name without the underscore, e.g. py_run!(py, sm, "import sys; sys.modules['nyx_space.cosmic'] = sm");

Now, you can expand the __init__.py file to include additional attributes like __all__:

from . import _nyx_space

from nyx_space import time, cosmic, mission_design, orbit_determination

__all__ = ["time", "cosmic", "mission_design", "orbit_determination"]
    Finished dev [unoptimized +…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@messense
Comment options

@ChristopherRabotin
Comment options

@messense
Comment options

@messense
Comment options

@ChristopherRabotin
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ChristopherRabotin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants