Skip to content

Commit

Permalink
Merge pull request #1282 from messense/fix-1281
Browse files Browse the repository at this point in the history
Tighten src-layout detection logic
  • Loading branch information
messense authored Nov 21, 2022
2 parents 3cfd886 + cccbe9d commit 82d584b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 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]

* Tighten src-layout detection logic in [#1281](https://github.com/PyO3/maturin/pull/1282)

## [0.14.1] - 2022-11-20

* Downgrade `cargo_metadata` to 0.15.0 to fix `maturin build` on old Rust versions like 1.48.0 in [#1279](https://github.com/PyO3/maturin/pull/1279)
Expand Down
26 changes: 23 additions & 3 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ impl ProjectResolver {
Some(project_name) => {
// Detect src layout
let import_name = project_name.replace('-', "_");
if project_root.join("src").join(import_name).is_dir() {
let rust_cargo_toml_found =
project_root.join("rust").join("Cargo.toml").is_file();
let python_src_found = project_root
.join("src")
.join(import_name)
.join("__init__.py")
.is_file();
if rust_cargo_toml_found && python_src_found {
project_root.join("src")
} else {
project_root.to_path_buf()
Expand Down Expand Up @@ -255,14 +262,20 @@ impl ProjectResolver {
// └── src
// └── lib.rs
let path = current_dir.join("rust").join("Cargo.toml");
if path.exists() {
if path.is_file() {
debug!("Python first src-layout detected");
if pyproject.python_source().is_some() {
// python source directory is specified in pyproject.toml
return Ok((path, pyproject_file));
} else if let Some(project_name) = pyproject.project_name() {
// Check if python source directory in `src/<project_name>`
let import_name = project_name.replace('-', "_");
if current_dir.join("src").join(import_name).is_dir() {
if current_dir
.join("src")
.join(import_name)
.join("__init__.py")
.is_file()
{
return Ok((path, pyproject_file));
}
}
Expand Down Expand Up @@ -339,6 +352,13 @@ impl ProjectLayout {
module_name.to_string(),
)
};
debug!(
project_root = %project_root.display(),
rust_module = %rust_module.display(),
python_module = %python_module.display(),
extension_name = %extension_name,
"Project layout resolved"
);

let data = if let Some(data) = data {
if !data.is_dir() {
Expand Down

0 comments on commit 82d584b

Please sign in to comment.