-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Configurable Description-Content-Type #360
Changes from 1 commit
e779f77
e1b32c1
caa5f8d
b40da7c
fef38f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,23 +76,26 @@ impl Metadata21 { | |
None | ||
}; | ||
|
||
let description_content_type = if description.is_some() { | ||
// I'm not hundred percent sure if that's the best preset | ||
Some("text/markdown; charset=UTF-8; variant=GFM".to_owned()) | ||
} else { | ||
None | ||
}; | ||
|
||
let classifier = cargo_toml.classifier(); | ||
|
||
let extra_metadata = cargo_toml.remaining_core_metadata(); | ||
|
||
let author_email = if authors.contains('@') { | ||
Some(authors.clone()) | ||
} else { | ||
None | ||
}; | ||
|
||
let extra_metadata = cargo_toml.remaining_core_metadata(); | ||
|
||
// See https://packaging.python.org/specifications/core-metadata/#description-content-type | ||
let description_content_type = extra_metadata.description_content_type.or_else(|| { | ||
if description.is_some() { | ||
// I'm not hundred percent sure if that's the best preset | ||
Some("text/markdown; charset=UTF-8; variant=GFM".to_owned()) | ||
} else { | ||
None | ||
} | ||
}); | ||
|
||
Ok(Metadata21 { | ||
metadata_version: "2.1".to_owned(), | ||
|
||
|
@@ -243,16 +246,7 @@ mod test { | |
use indoc::indoc; | ||
use std::io::Write; | ||
|
||
#[test] | ||
fn test_metadata_from_cargo_toml() { | ||
let readme = indoc!( | ||
r#" | ||
# Some test package | ||
|
||
This is the readme for a test package | ||
"# | ||
); | ||
|
||
fn assert_metadata_from_cargo_toml(readme: &str, cargo_toml: &str, expected: &str) { | ||
let mut readme_md = tempfile::NamedTempFile::new().unwrap(); | ||
|
||
let readme_path = if cfg!(windows) { | ||
|
@@ -263,6 +257,39 @@ mod test { | |
|
||
readme_md.write_all(readme.as_bytes()).unwrap(); | ||
|
||
let cargo_toml = cargo_toml.replace("readme.md", &readme_path); | ||
|
||
let cargo_toml: CargoToml = toml::from_str(&cargo_toml).unwrap(); | ||
|
||
let metadata = | ||
Metadata21::from_cargo_toml(&cargo_toml, &readme_md.path().parent().unwrap()).unwrap(); | ||
|
||
let actual = metadata.to_file_contents(); | ||
|
||
if actual.trim() != expected.trim() { | ||
panic!( | ||
"Actual metadata differed from expected\nEXPECTED:\n{}\n\nGOT:\n{}", | ||
expected, actual | ||
); | ||
} | ||
|
||
assert_eq!(actual.trim(), expected.trim()); | ||
|
||
if metadata.get_dist_info_dir() != PathBuf::from("info_project-0.1.0.dist-info") { | ||
panic!("Dist info dir differed from expected"); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_metadata_from_cargo_toml() { | ||
let readme = indoc!( | ||
r#" | ||
# Some test package | ||
|
||
This is the readme for a test package | ||
"# | ||
); | ||
|
||
let cargo_toml = indoc!( | ||
r#" | ||
[package] | ||
|
@@ -285,13 +312,7 @@ mod test { | |
classifier = ["Programming Language :: Python"] | ||
requires-dist = ["flask~=1.1.0", "toml==0.10.0"] | ||
"# | ||
) | ||
.replace("readme.md", &readme_path); | ||
|
||
let cargo_toml: CargoToml = toml::from_str(&cargo_toml).unwrap(); | ||
|
||
let metadata = | ||
Metadata21::from_cargo_toml(&cargo_toml, &readme_md.path().parent().unwrap()).unwrap(); | ||
); | ||
|
||
let expected = indoc!( | ||
r#" | ||
|
@@ -314,13 +335,61 @@ mod test { | |
"# | ||
); | ||
|
||
let actual = metadata.to_file_contents(); | ||
assert_metadata_from_cargo_toml(readme, cargo_toml, expected); | ||
} | ||
|
||
assert_eq!(actual.trim(), expected.trim()); | ||
#[test] | ||
fn test_metadata_from_cargo_toml_rst() { | ||
let readme = indoc!( | ||
r#" | ||
# Some test package | ||
"# | ||
); | ||
|
||
let cargo_toml = indoc!( | ||
r#" | ||
[package] | ||
authors = ["konstin <[email protected]>"] | ||
name = "info-project" | ||
version = "0.1.0" | ||
description = "A test project" | ||
homepage = "https://example.org" | ||
readme = "readme.md" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be but it doesn't have to be, as this test just needs to prove that the metadata gets through. I'll fix it for clarity, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second look, it doesn't actually matter because the substring is replaced by the path of the temporary file created to write the readme contents into; I've changed the name to make that more clear, as well as explicitly checking for some expected hardcoded values. |
||
keywords = ["ffi", "test"] | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
name = "pyo3_pure" | ||
|
||
[package.metadata.maturin.scripts] | ||
ph = "maturin:print_hello" | ||
|
||
[package.metadata.maturin] | ||
classifier = ["Programming Language :: Python"] | ||
requires-dist = ["flask~=1.1.0", "toml==0.10.0"] | ||
description-content-type = "text/x-rst" | ||
"# | ||
); | ||
|
||
let expected = indoc!( | ||
r#" | ||
Metadata-Version: 2.1 | ||
Name: info-project | ||
Version: 0.1.0 | ||
Classifier: Programming Language :: Python | ||
Requires-Dist: flask~=1.1.0 | ||
Requires-Dist: toml==0.10.0 | ||
Summary: A test project | ||
Keywords: ffi test | ||
Home-Page: https://example.org | ||
Author: konstin <[email protected]> | ||
Author-Email: konstin <[email protected]> | ||
Description-Content-Type: text/x-rst | ||
|
||
# Some test package | ||
"# | ||
); | ||
|
||
assert_eq!( | ||
metadata.get_dist_info_dir(), | ||
PathBuf::from("info_project-0.1.0.dist-info") | ||
) | ||
assert_metadata_from_cargo_toml(readme, cargo_toml, expected); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass a message and formatter options as third and following parameters to assert_eq (example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, that was a leftover from a slightly different implementation, I'll change that.