Skip to content

Commit

Permalink
Make Cargo.toml's authors field optional
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jun 21, 2021
1 parent 7d9fe4a commit 3b91f14
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
30 changes: 29 additions & 1 deletion src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub(crate) struct CargoTomlPackage {
// https://doc.rust-lang.org/cargo/reference/manifest.html#the-package-section
pub(crate) name: String,
pub(crate) version: String,
pub(crate) authors: Vec<String>,
// All other fields are optional
pub(crate) authors: Option<Vec<String>>,
pub(crate) description: Option<String>,
pub(crate) documentation: Option<String>,
pub(crate) homepage: Option<String>,
Expand Down Expand Up @@ -200,4 +200,32 @@ mod test {

assert_eq!(cargo_toml.classifiers(), classifiers);
}

#[test]
fn test_metadata_from_cargo_toml_without_authors() {
let cargo_toml = indoc!(
r#"
[package]
name = "info-project"
version = "0.1.0"
description = "A test project"
homepage = "https://example.org"
keywords = ["ffi", "test"]
[lib]
crate-type = ["cdylib"]
name = "pyo3_pure"
[package.metadata.maturin.scripts]
ph = "maturin:print_hello"
[package.metadata.maturin]
classifiers = ["Programming Language :: Python"]
requires-dist = ["flask~=1.1.0", "toml==0.10.0"]
"#
);

let cargo_toml: Result<CargoToml, _> = toml::from_str(&cargo_toml);
assert!(cargo_toml.is_ok());
}
}
20 changes: 13 additions & 7 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,21 @@ impl Metadata21 {
cargo_toml: &CargoToml,
manifest_path: impl AsRef<Path>,
) -> Result<Metadata21> {
let authors = cargo_toml.package.authors.join(", ");
let authors = cargo_toml
.package
.authors
.as_ref()
.map(|authors| authors.join(", "));

let classifiers = cargo_toml.classifiers();

let author_email = if authors.contains('@') {
Some(authors.clone())
} else {
None
};
let author_email = authors.as_ref().and_then(|authors| {
if authors.contains('@') {
Some(authors.clone())
} else {
None
}
});

let extra_metadata = cargo_toml.remaining_core_metadata();

Expand Down Expand Up @@ -313,7 +319,7 @@ impl Metadata21 {
home_page: cargo_toml.package.homepage.clone(),
download_url: None,
// Cargo.toml has no distinction between author and author email
author: Some(authors),
author: authors,
author_email,
license: cargo_toml.package.license.clone(),

Expand Down

0 comments on commit 3b91f14

Please sign in to comment.