Skip to content

Commit

Permalink
Merge pull request #751 from PyO3/fix-reddit-problems
Browse files Browse the repository at this point in the history
Fix reddit problems
  • Loading branch information
konstin committed Dec 20, 2021
2 parents 79f348f + 483546d commit fa66292
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ which requires the right compilers to be installed. Installing a wheel is much f

When you publish a package to be installable with `pip install`, you upload it to [pypi](https://pypi.org/), the official package repository.
For testing, you can use [test pypi](https://test.pypi.org/) instead, which you can use with `pip install --index-url https://test.pypi.org/simple/`.
Note that for publishing for linux, [you need to use the manylinux docker container](#manylinux-and-auditwheel).
Note that for publishing for linux, [you need to use the manylinux docker container](#manylinux-and-auditwheel), while for publishing from your repository you can use the [messense/maturin-action github action](https://github.com/messense/maturin-action).

## pyo3 and rust-cpython

Expand Down
41 changes: 35 additions & 6 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,39 @@ impl Metadata21 {

let extra_metadata = cargo_toml.remaining_core_metadata();

let description: Option<String>;
let description_content_type: Option<String>;
let mut description: Option<String> = None;
let mut description_content_type: Option<String> = None;
// See https://packaging.python.org/specifications/core-metadata/#description
if let Some(ref readme) = cargo_toml.package.readme {
// and https://doc.rust-lang.org/cargo/reference/manifest.html#the-readme-field
if cargo_toml.package.readme == Some("false".to_string()) {
// > You can suppress this behavior by setting this field to false
} else if let Some(ref readme) = cargo_toml.package.readme {
let readme_path = manifest_path.as_ref().join(readme);
description = Some(fs::read_to_string(&readme_path).context(format!(
"Failed to read readme specified in Cargo.toml, which should be at {}",
"Failed to read Readme specified in Cargo.toml, which should be at {}",
readme_path.display()
))?);

description_content_type = extra_metadata
.description_content_type
.or_else(|| Some(path_to_content_type(&readme_path)));
} else {
description = None;
description_content_type = None;
// > If no value is specified for this field, and a file named
// > README.md, README.txt or README exists in the package root
// Even though it's not what cargo does, we also search for README.rst
// since it's still popular in the python world
for readme_guess in ["README.md", "README.txt", "README.rst", "README"] {
let guessed_readme = manifest_path.as_ref().join(readme_guess);
if guessed_readme.exists() {
let context = format!(
"Readme at {} exists, but can't be read",
guessed_readme.display()
);
description = Some(fs::read_to_string(&guessed_readme).context(context)?);
description_content_type = Some(path_to_content_type(&guessed_readme));
break;
}
}
};
let name = extra_metadata
.name
Expand Down Expand Up @@ -794,4 +811,16 @@ mod test {
// defined in pyproject.toml
assert_eq!(metadata.scripts["get_42"], "pyo3_mixed_py_subdir:get_42");
}

#[test]
fn test_implicit_readme() {
let cargo_toml_str = fs_err::read_to_string("test-crates/pyo3-mixed/Cargo.toml").unwrap();
let cargo_toml = toml::from_str(&cargo_toml_str).unwrap();
let metadata = Metadata21::from_cargo_toml(&cargo_toml, "test-crates/pyo3-mixed").unwrap();
assert!(metadata.description.unwrap().starts_with("# pyo3-mixed"));
assert_eq!(
metadata.description_content_type.unwrap(),
"text/markdown; charset=UTF-8; variant=GFM"
);
}
}
1 change: 0 additions & 1 deletion test-crates/pyo3-mixed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ authors = ["konstin <konstin@mailbox.org>"]
name = "pyo3-mixed"
version = "2.1.3"
description = "Implements a dummy function combining rust and python"
readme = "Readme.md"
edition = "2018"

[dependencies]
Expand Down
File renamed without changes.

0 comments on commit fa66292

Please sign in to comment.