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

No way to give Rust and Python project a different name. #1520

Closed
1 task done
flying-sheep opened this issue Mar 9, 2023 · 6 comments · Fixed by #1524
Closed
1 task done

No way to give Rust and Python project a different name. #1520

flying-sheep opened this issue Mar 9, 2023 · 6 comments · Fixed by #1524
Labels
bug Something isn't working

Comments

@flying-sheep
Copy link

flying-sheep commented Mar 9, 2023

Bug Description

Apologies if there is a way, I searched for quite a while and didn’t find it.

I want to create a crate that is also deployed to PyPI.

On crates.io, it has the name xdot (already published), on PyPI it’s supposed to have the name xdot-rs (and be importable as import xdot_rs)

This doesn’t seem to be possible as [tool.maturin] doesn’t seem to have an option for this, and when just using the intended names, maturin complains:

⚠️ Warning: Couldn't find the symbol PyInit_xdot in the native library. Python will fail to import this module. If you're using pyo3, check that #[pymodule] uses xdot as module name

This advice isn’t actionable, since I can neither use xdot as Python package name (it already exists) nor am I able (or want to) rename the Rust crate to xdot-rs.

Your maturin version (maturin --version)

0.14.15

Your Python version (python -V)

3.10.9

Your pip version (pip -V)

23.0.1

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

Steps to Reproduce

Cargo.toml

[package]
name = 'xdot'
...

[dependencies]
...
pyo3 = { version = '0.18.1', optional = true, features = ['extension-module']}

pyproject.toml

[build-system]
...
[project]
name = 'xdot-rs'
...
[tool.maturin]
features = ['pyo3']

src/lib.rs

...

#[cfg(feature = "pyo3")]
#[pyo3::pymodule]
#[pyo3(name = "xdot_rs")]
pub fn pymodule(py: pyo3::Python, m: &pyo3::types::PyModule) -> pyo3::PyResult<()> {
    ...
    Ok(())
}
@flying-sheep flying-sheep added the bug Something isn't working label Mar 9, 2023
@messense
Copy link
Member

messense commented Mar 9, 2023

Have you tried

[package.metadata.maturin]
name = "xdot_rs"

?

The module name has to be aligned with the dylib name which defaults to package.name in Cargo.toml and can be override with package.metadata.maturin.name.

@flying-sheep
Copy link
Author

flying-sheep commented Mar 9, 2023

This kinda works, but the python module included in the .whl is named xdot.

@messense
Copy link
Member

messense commented Mar 9, 2023

The configuration is very likely going to be changed in #1493 (comment).

@messense
Copy link
Member

messense commented Mar 9, 2023

It would be helpful if you can provide a git repo for repro.

@flying-sheep
Copy link
Author

sure, can do.

@flying-sheep
Copy link
Author

flying-sheep commented Mar 9, 2023

Here you go: https://github.com/flying-sheep/maturin-names-reproducer

I’m not sure if I understand the purpose of all the names completely, but the point is that the generated python package has the rust crate name still (and is broken as it does from .<rust crate name> import * instead of from .<dylib name> import *)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants