Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crates with multiple modules / submodules #266

Open
davidhewitt opened this issue Feb 16, 2020 · 6 comments
Open

Crates with multiple modules / submodules #266

davidhewitt opened this issue Feb 16, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@davidhewitt
Copy link
Member

davidhewitt commented Feb 16, 2020

This is a continuation of PyO3/pyo3#759

If a shared library exposes multiple modules, then it is possible to make all of them importable from Python by (ab)using symlinks, one for each module exposed, all pointing to the built .so.

Would it make sense for maturin to handle this case (presumably with some extra configuration)?

@konstin
Copy link
Member

konstin commented Feb 20, 2020

How do other projects such as numpy, pandas, etc. handle this?

@konstin konstin added the enhancement New feature or request label Feb 20, 2020
@davidhewitt
Copy link
Member Author

That's a great question. I suspect they set up a series of Python files to wrap the c extensions, but I'd need to do further research...

@messense
Copy link
Member

I think this isn't hard to support for pure Rust layout since we're already emitting __init__.py, and we can get a list of PyInit__XYZ symbols from the .so file and treat the ones that are not the same as the main module name as submodules and add them to sys.modules.

The limitation is that this will only support submodules like x.y not x.y.z.....

@konstin
Copy link
Member

konstin commented Jan 28, 2022

I think the best solution to this is to export one _native module that links all other modules and then create the real module structure that you want in python (e.g. create a foo.py with from _native.foo import *)

@WillAyd
Copy link

WillAyd commented May 21, 2023

How do other projects such as numpy, pandas, etc. handle this?

In pandas we build almost all of our extensions into a _libs folder in the source, and every module maps back to an individual shared lib

@Czaki
Copy link

Czaki commented Dec 17, 2024

Multiple projects (numpy, pandas etc) are collections of multiple .so files.
Sometimes these files are accessed by wrapping python modules, sometimes directly.

It is useful sometimes (for example when freezing aplication)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants