diff --git a/Changelog.md b/Changelog.md index 69b29a056..889855bad 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) diff --git a/src/project_layout.rs b/src/project_layout.rs index 3c8f6e309..c9f954311 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -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() @@ -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/` 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)); } } @@ -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() {