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

Allow stubs-only mixed project layout #914

Merged
merged 1 commit into from
May 13, 2022
Merged

Conversation

messense
Copy link
Member

Fixes #792

Note that this only allows it to build, it doesn't re-export the Rust module to top module level as in

// Reexport the shared library as if it were the top level module
writer.add_bytes(
&module.join("__init__.py"),
format!(
r#"from .{module_name} import *
__doc__ = {module_name}.__doc__
if hasattr({module_name}, "__all__"):
__all__ = {module_name}.__all__"#,
module_name = module_name
)
.as_bytes(),
)?;

@kevinheavey I'd love to know more about your requirements.

@netlify
Copy link

netlify bot commented May 13, 2022

Deploy Preview for maturin-guide ready!

Name Link
🔨 Latest commit 214e288
🔍 Latest deploy log https://app.netlify.com/sites/maturin-guide/deploys/627e20c4290caf00089b5b01
😎 Deploy Preview https://deploy-preview-914--maturin-guide.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@kevinheavey
Copy link

@kevinheavey I'd love to know more about your requirements.

So for my use case, I just want to mimic the standard experience of a Python project with multiple submodules (from mypackage.module_a import foo, from mypackage.module_b import bar. This is just because I'm working on something where the namespace will get very polluted otherwise.

it doesn't re-export the Rust module to top module level

I don't understand what this entails. I'm guessing it means there's something that I can't do if I use this approach?

@messense

This comment was marked as resolved.

@kevinheavey
Copy link

So how does one import the package then?

@messense
Copy link
Member Author

So how does one import the package then?

Never mind, I think that's a problem with my IPython setup, using python3 works.

@kevinheavey
Copy link

Nice, and with this approach, do things like maturin develop and maturin publish "just work"? And everything gets uploaded to PyPI in one package?

@messense
Copy link
Member Author

I think it should, note that you need to add a py.typed file to python module folder to actually enable type hints.

@kevinheavey
Copy link

Sounds awsome! The last thing I'm curious about is why we're referring to a mixed project layout. In my head this is just a pure Rust layout but with a directory of stub files instead of a single one

@messense
Copy link
Member Author

messense commented May 13, 2022

Using a mixed project layout is the simplest solution, and we actually generate a mixed project layout for pure Rust project internally anyway. (See #558)

@messense messense marked this pull request as ready for review May 13, 2022 09:11
@messense messense merged commit f5710d4 into PyO3:main May 13, 2022
@messense messense deleted the pure-stubs branch May 13, 2022 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maturin breaks when you have a directory of stub files instead of a single stub file
2 participants