Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Cargo.toml's authors field optional #573

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Support i386 on OpenBSD in [#568](https://github.com/PyO3/maturin/pull/568)
* Support Aarch64 on OpenBSD in [#570](https://github.com/PyO3/maturin/pull/570)
* Support Aarch64 on FreeBSD in [#571](https://github.com/PyO3/maturin/pull/571)
* `Cargo.toml`'s `authors` field is now optional per Rust [RFC 3052](https://github.com/rust-lang/rfcs/blob/master/text/3052-optional-authors-field.md) in [#573](https://github.com/PyO3/maturin/pull/573)

## 0.10.6 - 2021-05-21

Expand Down
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