@@ -274,6 +274,15 @@ pub fn check_sdist_mtimes(
274274}
275275
276276fn build_wheel_files ( package : impl AsRef < Path > , unique_name : & str ) -> Result < ZipArchive < File > > {
277+ let target_dir = crate :: common:: shared_target_dir ( & package) ;
278+ build_wheel_files_with_target_dir ( package, target_dir, unique_name)
279+ }
280+
281+ fn build_wheel_files_with_target_dir (
282+ package : impl AsRef < Path > ,
283+ target_dir : PathBuf ,
284+ unique_name : & str ,
285+ ) -> Result < ZipArchive < File > > {
277286 let manifest_path = package. as_ref ( ) . join ( "Cargo.toml" ) ;
278287 let wheel_directory = Path :: new ( "test-crates" ) . join ( "wheels" ) . join ( unique_name) ;
279288
@@ -285,7 +294,7 @@ fn build_wheel_files(package: impl AsRef<Path>, unique_name: &str) -> Result<Zip
285294 cargo : CargoOptions {
286295 manifest_path : Some ( manifest_path) ,
287296 quiet : true ,
288- target_dir : Some ( crate :: common :: shared_target_dir ( & package ) ) ,
297+ target_dir : Some ( target_dir ) ,
289298 ..Default :: default ( )
290299 } ,
291300 platform : PlatformOptions {
@@ -737,6 +746,31 @@ pub fn test_unreadable_dir() -> Result<()> {
737746 Ok ( ( ) )
738747}
739748
749+ /// Test that a target directory inside the python package isn't packaged outside of git.
750+ ///
751+ /// See https://github.com/PyO3/maturin/issues/3319
752+ pub fn test_target_dir_in_python_package ( ) -> Result < ( ) > {
753+ let temp_dir = tempfile:: tempdir ( ) ?;
754+ let project_dir = temp_dir. path ( ) . join ( "bin-with-python-module" ) ;
755+ copy_dir_recursive (
756+ Path :: new ( "test-crates/bin-with-python-module" ) ,
757+ & project_dir,
758+ ) ?;
759+
760+ let target_dir = project_dir. join ( "bin_with_python_module/target" ) ;
761+ let wheel = build_wheel_files_with_target_dir (
762+ & project_dir,
763+ target_dir,
764+ "wheel-files-bin-with-python-module-target-dir" ,
765+ ) ?;
766+ let package_files: Vec < _ > = wheel
767+ . file_names ( )
768+ . filter ( |name| name. starts_with ( "bin_with_python_module/" ) )
769+ . collect ( ) ;
770+ assert_eq ! ( package_files, [ "bin_with_python_module/__init__.py" ] ) ;
771+ Ok ( ( ) )
772+ }
773+
740774/// Test that building wheels from an sdist works correctly.
741775/// This simulates the `maturin build --sdist` workflow: build sdist first,
742776/// unpack it, then build wheels from the unpacked sdist.
0 commit comments