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 determining the python module name, use pyproject.toml project.name over Cargo.toml package.name. #1608

Merged
merged 1 commit into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* When determining the python module name, use pyproject.toml `project.name` over Cargo.toml `package.name`.

## [0.15.1] - 2023-05-07

* Fix finding interpreters from bundled sysconfigs in [#1598](https://github.com/PyO3/maturin/pull/1598)
Expand Down
21 changes: 12 additions & 9 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,20 @@ impl ProjectResolver {

// If the package name contains minuses, you must declare a module with
// underscores as lib name
let module_name = cargo_toml
.lib
.as_ref()
.and_then(|lib| lib.name.as_ref())
// Precedence:
// * Explicitly declared pyproject.toml `tool.maturin.module-name`
// * Cargo.toml `lib.name`
// * pyproject.toml `project.name`
// * Cargo.toml `package.name`
let module_name = pyproject
.and_then(|x| x.module_name())
.or(cargo_toml.lib.as_ref().and_then(|lib| lib.name.as_deref()))
.or(pyproject
.and_then(|pyproject| pyproject.project.as_ref())
.map(|project| project.name.as_str()))
.unwrap_or(crate_name)
.to_owned();

let extension_name = pyproject
.and_then(|x| x.module_name())
.unwrap_or(&module_name);

let project_root = if pyproject_file.is_file() {
pyproject_file.parent().unwrap_or(manifest_dir)
} else {
Expand Down Expand Up @@ -176,7 +179,7 @@ impl ProjectResolver {
}
});
let project_layout =
ProjectLayout::determine(project_root, extension_name, py_root, python_packages, data)?;
ProjectLayout::determine(project_root, &module_name, py_root, python_packages, data)?;
Ok(Self {
project_layout,
cargo_toml_path: manifest_file,
Expand Down