diff --git a/src/module_writer.rs b/src/module_writer.rs index 309d0890b..b6d5850d5 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -1286,8 +1286,17 @@ pub fn write_python_part( } for package in python_packages { - for absolute in WalkBuilder::new(package).hidden(false).build() { + for absolute in WalkBuilder::new(&project_layout.rust_module) + .hidden(false) + .parents(false) + .git_global(false) + .git_exclude(false) + .build() + { let absolute = absolute?.into_path(); + if !absolute.starts_with(package.as_path()) { + continue; + } let relative = absolute.strip_prefix(python_dir).unwrap(); if absolute.is_dir() { writer.add_directory(relative)?; diff --git a/test-crates/pyo3-mixed-implicit/.gitignore b/test-crates/pyo3-mixed-implicit/.gitignore new file mode 100644 index 000000000..18880a5ac --- /dev/null +++ b/test-crates/pyo3-mixed-implicit/.gitignore @@ -0,0 +1 @@ +*.py[cdo] diff --git a/test-crates/pyo3-mixed-include-exclude/.gitignore b/test-crates/pyo3-mixed-include-exclude/.gitignore new file mode 100644 index 000000000..18880a5ac --- /dev/null +++ b/test-crates/pyo3-mixed-include-exclude/.gitignore @@ -0,0 +1 @@ +*.py[cdo] diff --git a/test-crates/pyo3-mixed-py-subdir/.gitignore b/test-crates/pyo3-mixed-py-subdir/.gitignore new file mode 100644 index 000000000..18880a5ac --- /dev/null +++ b/test-crates/pyo3-mixed-py-subdir/.gitignore @@ -0,0 +1 @@ +*.py[cdo] diff --git a/test-crates/pyo3-mixed-src/.gitignore b/test-crates/pyo3-mixed-src/.gitignore new file mode 100644 index 000000000..18880a5ac --- /dev/null +++ b/test-crates/pyo3-mixed-src/.gitignore @@ -0,0 +1 @@ +*.py[cdo] diff --git a/test-crates/pyo3-mixed/.gitignore b/test-crates/pyo3-mixed/.gitignore new file mode 100644 index 000000000..18880a5ac --- /dev/null +++ b/test-crates/pyo3-mixed/.gitignore @@ -0,0 +1 @@ +*.py[cdo] diff --git a/tests/run.rs b/tests/run.rs index d5383563c..7455faabb 100644 --- a/tests/run.rs +++ b/tests/run.rs @@ -730,6 +730,7 @@ fn pyo3_mixed_include_exclude_sdist() { SdistGenerator::Cargo, expect![[r#" { + "pyo3_mixed_include_exclude-2.1.3/.gitignore", "pyo3_mixed_include_exclude-2.1.3/Cargo.lock", "pyo3_mixed_include_exclude-2.1.3/Cargo.toml", "pyo3_mixed_include_exclude-2.1.3/PKG-INFO", @@ -759,6 +760,7 @@ fn pyo3_mixed_include_exclude_git_sdist_generator() { SdistGenerator::Git, expect![[r#" { + "pyo3_mixed_include_exclude-2.1.3/.gitignore", "pyo3_mixed_include_exclude-2.1.3/Cargo.lock", "pyo3_mixed_include_exclude-2.1.3/Cargo.toml", "pyo3_mixed_include_exclude-2.1.3/PKG-INFO",