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

Use 'classifiers' instead of 'classifier' #416

Merged
merged 1 commit into from
Feb 13, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 38 additions & 7 deletions src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ impl CargoToml {
}
}

/// Returns the trove classifier
pub fn classifier(&self) -> Vec<String> {
/// Returns the trove classifiers
pub fn classifiers(&self) -> Vec<String> {
match self.package.metadata {
Some(CargoTomlMetadata {
maturin:
Some(RemainingCoreMetadata {
classifier: Some(ref classifier),
classifiers: Some(ref classifier),
..
}),
}) => classifier.clone(),
Expand Down Expand Up @@ -112,7 +112,9 @@ struct CargoTomlMetadata {
pub struct RemainingCoreMetadata {
pub name: Option<String>,
pub scripts: Option<HashMap<String, String>>,
pub classifier: Option<Vec<String>>,
// For backward compatibility, we also allow classifier.
#[serde(alias = "classifier")]
pub classifiers: Option<Vec<String>>,
pub maintainer: Option<String>,
pub maintainer_email: Option<String>,
pub requires_dist: Option<Vec<String>>,
Expand Down Expand Up @@ -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"]
"#
);
Expand All @@ -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 <konstin@mailbox.org>"]
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);
}
}
20 changes: 10 additions & 10 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Metadata21 {
pub maintainer: Option<String>,
pub maintainer_email: Option<String>,
pub license: Option<String>,
pub classifier: Vec<String>,
pub classifiers: Vec<String>,
pub requires_dist: Vec<String>,
pub provides_dist: Vec<String>,
pub obsoletes_dist: Vec<String>,
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Metadata21 {
) -> Result<Metadata21> {
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())
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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/" }
"#
Expand All @@ -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
Expand Down Expand Up @@ -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"
"#
Expand All @@ -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
Expand Down Expand Up @@ -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"
"#
);
Expand All @@ -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 <konstin@mailbox.org>
Expand Down