Skip to content

Commit

Permalink
Merge pull request #1608 from PyO3/use_project_name_for_module_name
Browse files Browse the repository at this point in the history
When determining the python module name, use pyproject.toml `project.name` over Cargo.toml `package.name`.
  • Loading branch information
messense authored May 13, 2023
2 parents e378ddd + 02f5764 commit 243b8ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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

0 comments on commit 243b8ec

Please sign in to comment.