diff --git a/Cargo.toml b/Cargo.toml index 97a520810..c6b889369 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [package.metadata.maturin] requires-python = ">=3.5" -classifier = [ +classifiers = [ "Topic :: Software Development :: Build Tools", "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", diff --git a/Changelog.md b/Changelog.md index d87a23fb6..0ad3101ee 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Error when the `abi3` feature is selected but no minimum version * Support building universal2 wheels (x86 and aarch64 in a single file) by messense in [#403](https://github.com/PyO3/maturin/pull/403) * Recognize `PYO3_CROSS_LIB_DIR` for cross compiling with abi3 targeting windows. + * `package.metadata.maturin.classifier` is renamed to `classifiers` ## 0.9.0 - 2020-01-10 diff --git a/Readme.md b/Readme.md index 63459d8dc..50fc1c9fc 100644 --- a/Readme.md +++ b/Readme.md @@ -124,13 +124,15 @@ Pip allows adding so called console scripts, which are shell commands that execu get_42 = "my_project:DummyClass.get_42" ``` -You can also specify [trove classifiers](https://pypi.org/classifiers/) in your Cargo.toml under `package.metadata.maturin.classifier`: +You can also specify [trove classifiers](https://pypi.org/classifiers/) in your Cargo.toml under `package.metadata.maturin.classifiers`: ```toml [package.metadata.maturin] -classifier = ["Programming Language :: Python"] +classifiers = ["Programming Language :: Python"] ``` +Note that `package.metadata.maturin.classifier` is + You can use other fields from the [python core metadata](https://packaging.python.org/specifications/core-metadata/) in the `[package.metadata.maturin]` section, specifically ` maintainer`, `maintainer-email` and `requires-python` (string fields), as well as `requires-external` and `provides-extra` (lists of strings) and `project-url` (dictionary string to string) ## pyproject.toml diff --git a/src/cargo_toml.rs b/src/cargo_toml.rs index 076e4ef7b..a5f987244 100644 --- a/src/cargo_toml.rs +++ b/src/cargo_toml.rs @@ -70,13 +70,13 @@ impl CargoToml { } } - /// Returns the trove classifier - pub fn classifier(&self) -> Vec { + /// Returns the trove classifiers + pub fn classifiers(&self) -> Vec { match self.package.metadata { Some(CargoTomlMetadata { maturin: Some(RemainingCoreMetadata { - classifier: Some(ref classifier), + classifiers: Some(ref classifier), .. }), }) => classifier.clone(), @@ -112,7 +112,9 @@ struct CargoTomlMetadata { pub struct RemainingCoreMetadata { pub name: Option, pub scripts: Option>, - pub classifier: Option>, + // For backward compatibility, we also allow classifier. + #[serde(alias = "classifier")] + pub classifiers: Option>, pub maintainer: Option, pub maintainer_email: Option, pub requires_dist: Option>, @@ -148,7 +150,7 @@ mod test { ph = "maturin:print_hello" [package.metadata.maturin] - classifier = ["Programming Language :: Python"] + classifiers = ["Programming Language :: Python"] requires-dist = ["flask~=1.1.0", "toml==0.10.0"] "# ); @@ -158,15 +160,44 @@ mod test { let mut scripts = HashMap::new(); scripts.insert("ph".to_string(), "maturin:print_hello".to_string()); - let classifier = vec!["Programming Language :: Python".to_string()]; + let classifiers = vec!["Programming Language :: Python".to_string()]; let requires_dist = Some(vec!["flask~=1.1.0".to_string(), "toml==0.10.0".to_string()]); assert_eq!(cargo_toml.scripts(), scripts); - assert_eq!(cargo_toml.classifier(), classifier); + assert_eq!(cargo_toml.classifiers(), classifiers); assert_eq!( cargo_toml.remaining_core_metadata().requires_dist, requires_dist ); } + + #[test] + fn test_old_classifier_works() { + let cargo_toml = indoc!( + r#" + [package] + authors = ["konstin "] + 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] + # Not classifiers + classifier = ["Programming Language :: Python"] + "# + ); + + let cargo_toml: CargoToml = toml::from_str(&cargo_toml).unwrap(); + + let classifiers = vec!["Programming Language :: Python".to_string()]; + + assert_eq!(cargo_toml.classifiers(), classifiers); + } } diff --git a/src/metadata.rs b/src/metadata.rs index 575cdcced..036f89209 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -44,7 +44,7 @@ pub struct Metadata21 { pub maintainer: Option, pub maintainer_email: Option, pub license: Option, - pub classifier: Vec, + pub classifiers: Vec, pub requires_dist: Vec, pub provides_dist: Vec, pub obsoletes_dist: Vec, @@ -85,7 +85,7 @@ impl Metadata21 { ) -> Result { let authors = cargo_toml.package.authors.join(", "); - let classifier = cargo_toml.classifier(); + let classifiers = cargo_toml.classifiers(); let author_email = if authors.contains('@') { Some(authors.clone()) @@ -137,7 +137,7 @@ impl Metadata21 { license: cargo_toml.package.license.clone(), // Values provided through `[project.metadata.maturin]` - classifier, + classifiers, maintainer: extra_metadata.maintainer, maintainer_email: extra_metadata.maintainer_email, requires_dist: extra_metadata.requires_dist.unwrap_or_default(), @@ -175,7 +175,7 @@ impl Metadata21 { add_vec("Supported-Platform", &self.supported_platform); add_vec("Platform", &self.platform); add_vec("Supported-Platform", &self.supported_platform); - add_vec("Classifier", &self.classifier); + add_vec("Classifiers", &self.classifiers); add_vec("Requires-Dist", &self.requires_dist); add_vec("Provides-Dist", &self.provides_dist); add_vec("Obsoletes-Dist", &self.obsoletes_dist); @@ -345,7 +345,7 @@ mod test { ph = "maturin:print_hello" [package.metadata.maturin] - classifier = ["Programming Language :: Python"] + classifiers = ["Programming Language :: Python"] requires-dist = ["flask~=1.1.0", "toml==0.10.0"] project-url = { "Bug Tracker" = "http://bitbucket.org/tarek/distribute/issues/" } "# @@ -356,7 +356,7 @@ mod test { Metadata-Version: 2.1 Name: info-project Version: 0.1.0 - Classifier: Programming Language :: Python + Classifiers: Programming Language :: Python Requires-Dist: flask~=1.1.0 Requires-Dist: toml==0.10.0 Summary: A test project @@ -404,7 +404,7 @@ mod test { ph = "maturin:print_hello" [package.metadata.maturin] - classifier = ["Programming Language :: Python"] + classifiers = ["Programming Language :: Python"] requires-dist = ["flask~=1.1.0", "toml==0.10.0"] description-content-type = "text/x-rst" "# @@ -415,7 +415,7 @@ mod test { Metadata-Version: 2.1 Name: info-project Version: 0.1.0 - Classifier: Programming Language :: Python + Classifiers: Programming Language :: Python Requires-Dist: flask~=1.1.0 Requires-Dist: toml==0.10.0 Summary: A test project @@ -453,7 +453,7 @@ mod test { [package.metadata.maturin] name = "info" - classifier = ["Programming Language :: Python"] + classifiers = ["Programming Language :: Python"] description-content-type = "text/x-rst" "# ); @@ -463,7 +463,7 @@ mod test { Metadata-Version: 2.1 Name: info Version: 0.1.0 - Classifier: Programming Language :: Python + Classifiers: Programming Language :: Python Summary: A test project Home-Page: https://example.org Author: konstin