Skip to content

Commit 180f104

Browse files
committed
All fields except Metadata-Version, Name and Version are optional
See https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata-specifications
1 parent 0e5b4e3 commit 180f104

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ thiserror = "1.0.30"
2323
xz = { version = "0.1.0", optional = true }
2424
zip = { version = "0.6.0", default-features = false, features = ["bzip2", "deflate", "time"] }
2525

26+
[dev-dependencies]
27+
serde_json = "1.0.99"
28+
2629
[features]
2730
deprecated-formats = ["bzip2", "xz"]

src/metadata.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,29 @@ pub struct Metadata {
2525
#[cfg_attr(feature = "serde", serde(default))]
2626
pub supported_platforms: Vec<String>,
2727
/// A one-line summary of what the distribution does.
28+
#[cfg_attr(feature = "serde", serde(default))]
2829
pub summary: Option<String>,
2930
/// A longer description of the distribution that can run to several paragraphs.
31+
#[cfg_attr(feature = "serde", serde(default))]
3032
pub description: Option<String>,
3133
/// A list of additional keywords, separated by commas, to be used to
3234
/// assist searching for the distribution in a larger catalog.
35+
#[cfg_attr(feature = "serde", serde(default))]
3336
pub keywords: Option<String>,
3437
/// A string containing the URL for the distribution’s home page.
38+
#[cfg_attr(feature = "serde", serde(default))]
3539
pub home_page: Option<String>,
3640
/// A string containing the URL from which this version of the distribution can be downloaded.
41+
#[cfg_attr(feature = "serde", serde(default))]
3742
pub download_url: Option<String>,
3843
/// A string containing the author’s name at a minimum; additional contact information may be provided.
44+
#[cfg_attr(feature = "serde", serde(default))]
3945
pub author: Option<String>,
4046
/// A string containing the author’s e-mail address. It can contain a name and e-mail address in the legal forms for a RFC-822 `From:` header.
47+
#[cfg_attr(feature = "serde", serde(default))]
4148
pub author_email: Option<String>,
4249
/// Text indicating the license covering the distribution where the license is not a selection from the `License` Trove classifiers.
50+
#[cfg_attr(feature = "serde", serde(default))]
4351
pub license: Option<String>,
4452
/// Each entry is a string giving a single classification value for the distribution.
4553
#[cfg_attr(feature = "serde", serde(default))]
@@ -58,14 +66,17 @@ pub struct Metadata {
5866
///
5967
/// Note that this field is intended for use when a project is being maintained by someone other than the original author:
6068
/// it should be omitted if it is identical to `author`.
69+
#[cfg_attr(feature = "serde", serde(default))]
6170
pub maintainer: Option<String>,
6271
/// A string containing the maintainer’s e-mail address.
6372
/// It can contain a name and e-mail address in the legal forms for a RFC-822 `From:` header.
6473
///
6574
/// Note that this field is intended for use when a project is being maintained by someone other than the original author:
6675
/// it should be omitted if it is identical to `author_email`.
76+
#[cfg_attr(feature = "serde", serde(default))]
6777
pub maintainer_email: Option<String>,
6878
/// This field specifies the Python version(s) that the distribution is guaranteed to be compatible with.
79+
#[cfg_attr(feature = "serde", serde(default))]
6980
pub requires_python: Option<String>,
7081
/// Each entry contains a string describing some dependency in the system that the distribution is to be used.
7182
#[cfg_attr(feature = "serde", serde(default))]
@@ -79,6 +90,7 @@ pub struct Metadata {
7990
pub provides_extras: Vec<String>,
8091
/// A string stating the markup syntax (if any) used in the distribution’s description,
8192
/// so that tools can intelligently render the description.
93+
#[cfg_attr(feature = "serde", serde(default))]
8294
pub description_content_type: Option<String>,
8395
/// A string containing the name of another core metadata field.
8496
#[cfg_attr(feature = "serde", serde(default))]
@@ -224,4 +236,11 @@ mod tests {
224236
assert_eq!(meta.author.as_deref(), Some("中文"));
225237
assert_eq!(meta.description.as_deref(), Some("一个 Python 包"));
226238
}
239+
240+
#[cfg(feature = "serde")]
241+
#[test]
242+
fn test_serde_deserialize() {
243+
let input = r#"{"metadata_version": "2.3", "name": "example", "version": "1.0.0"}"#;
244+
let _metadata: Metadata = serde_json::from_str(input).unwrap();
245+
}
227246
}

0 commit comments

Comments
 (0)