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

When cargo building pyo3 projects auto-add in the extension-module feature please #325

Closed
gilescope opened this issue Jul 8, 2020 · 8 comments

Comments

@gilescope
Copy link

At the moment maturin warns if a pyo3 project is built without the extension-module feature.

We can already do:

maturin develop --cargo-extra-args="--features pyo3/extension-module"

Why not add that flag in automatically if it's clear that it's not there? Having pyo3/extension-module turned on as a default feature seems like a footgun as people will just run cargo test and expect stuff to work on cli, IDEs etc. but will run into linking problems if they don't use --no-default-features. It's both unergonomic and confusing as the linker errors give no clue that you should have disabled a feature so it's tough on new users.

It would be great if maturin just by default did the right thing :-) -
(it could still squark that it wasn't found so adding it in explicitly.)

thoughs?

@davidhewitt
Copy link
Member

I think that's a very good idea!

@konstin
Copy link
Member

konstin commented Jul 29, 2020

Blocked on PyO3/pyo3#1040 being resolved.

@messense
Copy link
Member

messense commented Aug 17, 2021

After #605 lands, you can add the cargo-extra-args = "--features pyo3/extension-module" to the [tool.maturin] section in pyproject.toml and maturin will pick it up automatically.

Edit: if you are using maturin 0.13.0 and later, --cargo-extra-args was removed, add the following to pyproject.toml instead.

[tool.maturin]
features = ["pyo3/extension-module"]

@konstin
Copy link
Member

konstin commented May 29, 2022

I believe [tool.maturin] features is the way to go

@konstin konstin closed this as completed May 29, 2022
@messense messense removed the blocked Something is blocking this label Oct 22, 2022
@jmhodges
Copy link

jmhodges commented Feb 4, 2023

Reading between the lines here, I think this issue closing means we could take an update to getting_started.md's examples and maybe to the FAQ to allow folks to run cargo test work out of the box

I'm willing to do that, would like to confirm what's desired.

I think what we want is the example pyproject.toml to gain a

[tool.maturin]
features = ["pyo3/extension-module"]

while the example Cargo.toml's dependencies looks like:

[dependencies]
pyo3 = "0.18.0"

(Or I could be convinced to make that pyo3 = { version = "0.18", features = ["anyhow"] } since that's so handy)

@jmhodges
Copy link

jmhodges commented Feb 4, 2023

I could also be convinced that the recommended set up would be better as the mixed Python and Rust code per the maturin guide. I could be convinced since being able to write Python tests out of the box make it easier to ensure the Python API is ergonomic, while allowing cargo test and other cargo tools to work is useful for IDEs and rust analysis tools.

@messense
Copy link
Member

messense commented Feb 8, 2023

I could also be convinced that the recommended set up would be better as the mixed Python and Rust code

You can generate a mixed Python/Rust project with maturin new --mixed.

@messense
Copy link
Member

messense commented Feb 8, 2023

Reading between the lines here, I think this issue closing means we could take an update to getting_started.md's examples and maybe to the FAQ to allow folks to run cargo test work out of the box

Pull requests are welcome, I think we can also update the maturin new/init template:

{% if bindings == "pyo3" -%}
pyo3 = { version = "0.18.0", features = ["extension-module"] }

bors bot added a commit that referenced this issue Feb 13, 2023
1479: Enable `extension-module` feature in `pyproject.toml` in project templates r=konstin a=messense

Implements #325 (comment).

Thanks for the idea `@jmhodges!`

Co-authored-by: messense <messense@icloud.com>
bors bot added a commit that referenced this issue Feb 13, 2023
1479: Enable `extension-module` feature in `pyproject.toml` in project templates r=konstin a=messense

Implements #325 (comment).

Thanks for the idea `@jmhodges!`

Co-authored-by: messense <messense@icloud.com>
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

No branches or pull requests

5 participants