Skip to content

Commit

Permalink
pyproject.toml should be relative to Python source directory
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 5, 2021
1 parent dba8a5f commit b56c7a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -776,4 +782,20 @@ mod test {
let pkginfo: Result<python_pkginfo::Metadata, _> = 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");
}
}

0 comments on commit b56c7a5

Please sign in to comment.