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

examples: maturin and setuptools_rust examples #1537

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Apr 1, 2021

This builds upon my experience writing the maturin and setuptools_rust examples in #1269

This time I rearrange the example modules as follows:

pyo3_benchmarks -> pyo3-benchmarks
rustapi_module  -> pyo3-pytests
*new example*      maturin-starter
*new example*      setuptools-rust-starter

The two existing packages got a bit of a clean-up. The two new examples maturin-starter and setuptools-rust-starter are copies of each other tailored to the two different build systems.

I made good use of the trick in #1517 (comment) to make importing the submodules easy, and I wanted to show this off in all the examples. (e.g. from maturin_starter.submodule import SubmoduleClass).

Closes #807

@davidhewitt
Copy link
Member Author

cc @konstin I've finally almost completed a working set of maturin examples for PyO3!

Unfortunately it appears that maturin doesn't build under MSRV. That's ok as long as there's a wheel to install from. I'll need PyO3/maturin#482 merged and included in a release, and then fingers crossed we'll be able to merge this PR here!

@davidhewitt
Copy link
Member Author

Many thanks @konstin - CI is all green here using maturin 0.10.0! 🚀

@kngwyu
Copy link
Member

kngwyu commented Apr 3, 2021

Thanks!
Though I didn't fully check the code, I like the renaming, especially rustapi-module. Maybe we can close #1515 after merging this.

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small things, looks really nice otherwise

examples/maturin-starter/pyproject.toml Outdated Show resolved Hide resolved
examples/pyo3-pytests/pyproject.toml Outdated Show resolved Hide resolved
examples/pyo3-pytests/tox.ini Outdated Show resolved Hide resolved
examples/setuptools-rust-starter/tox.ini Outdated Show resolved Hide resolved
Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

examples/maturin-starter/README.md Outdated Show resolved Hide resolved
Comment on lines +21 to +27
for each in 6..version {
println!("cargo:rustc-cfg=Py_3_{}", each);
}

if implementation == "PyPy" {
println!("cargo:rustc-cfg=PyPy");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be in setup.py, but we now build the tests with maturin instead of setuptools-rust.

We need it because some tests only compile on certain python / PyPy combinations.

IMO this build.rs method is better anyway because it would still work if we changed the examples back to setuptools_rust.

It's a little ugly to have to call a Python interpreter here. I have an idea how to split some of pyo3's build.rs logic into a separate crate pyo3-build-config, which this build.rs could then re-use. I've been torn for a while on whether that refactoring is worth the additional complexity; maybe I should hurry up and push that PR for a while so that others can see what they think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to move this into a new issue so that it doesn't block this PR with all the new examples, which I think has value even if there's this this wart.

examples/setuptools-rust-starter/README.md Outdated Show resolved Hide resolved
@davidhewitt davidhewitt merged commit 990bbb5 into PyO3:main Apr 7, 2021
@davidhewitt davidhewitt deleted the maturin-examples-v2 branch February 5, 2022 15:05
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 examples
4 participants