From b56c7a542fdb921075f1c861b9614bccc6be0afa Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 18 Jul 2021 10:21:05 +0800 Subject: [PATCH] `pyproject.toml` should be relative to Python source directory --- src/metadata.rs | 24 ++++++++++++++++++- .../{ => python}/pyproject.toml | 0 2 files changed, 23 insertions(+), 1 deletion(-) rename test-crates/pyo3-mixed-py-subdir/{ => python}/pyproject.toml (100%) diff --git a/src/metadata.rs b/src/metadata.rs index 66342b73e..c256f1ce2 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -356,7 +356,13 @@ impl Metadata21 { gui_scripts: HashMap::new(), entry_points: HashMap::new(), }; - metadata.merge_pyproject_toml(manifest_path)?; + + let manifest_path = manifest_path.as_ref(); + let py_src = extra_metadata + .python_source + .map(|src| manifest_path.join(src)) + .unwrap_or_else(|| manifest_path.to_path_buf()); + metadata.merge_pyproject_toml(py_src)?; Ok(metadata) } @@ -776,4 +782,20 @@ mod test { let pkginfo: Result = content.parse(); assert!(pkginfo.is_ok()); } + + #[test] + fn test_merge_metadata_from_pyproject_toml_with_customized_python_source_dir() { + let cargo_toml_str = + fs_err::read_to_string("test-crates/pyo3-mixed-py-subdir/Cargo.toml").unwrap(); + let cargo_toml: CargoToml = toml::from_str(&cargo_toml_str).unwrap(); + let metadata = + Metadata21::from_cargo_toml(&cargo_toml, "test-crates/pyo3-mixed-py-subdir").unwrap(); + // defined in Cargo.toml + assert_eq!( + metadata.summary, + Some("Implements a dummy function combining rust and python".to_string()) + ); + // defined in pyproject.toml + assert_eq!(metadata.scripts["get_42"], "pyo3_mixed_py_subdir:get_42"); + } } diff --git a/test-crates/pyo3-mixed-py-subdir/pyproject.toml b/test-crates/pyo3-mixed-py-subdir/python/pyproject.toml similarity index 100% rename from test-crates/pyo3-mixed-py-subdir/pyproject.toml rename to test-crates/pyo3-mixed-py-subdir/python/pyproject.toml