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

Switch back to toml_edit #839

Merged
merged 1 commit into from
Mar 11, 2022
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
59 changes: 56 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sha2 = "0.10.0"
shlex = "1.0.0"
tar = "0.4.33"
tempfile = "3.2.0"
toml = "0.5.8"
toml_edit = { version = "0.13.4", features = ["easy"] }
zip = "0.5.5"
thiserror = "1.0.24"
dirs = "4.0.0"
Expand Down
8 changes: 4 additions & 4 deletions src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl CargoToml {
"Can't read Cargo.toml at {}",
manifest_file.as_ref().display(),
))?;
let cargo_toml = toml::from_str(&contents).context(format!(
let cargo_toml = toml_edit::easy::from_str(&contents).context(format!(
"Failed to parse Cargo.toml at {}",
manifest_file.as_ref().display()
))?;
Expand Down Expand Up @@ -156,7 +156,7 @@ mod test {
"#
);

let cargo_toml: CargoToml = toml::from_str(cargo_toml).unwrap();
let cargo_toml: CargoToml = toml_edit::easy::from_str(cargo_toml).unwrap();

let mut scripts = HashMap::new();
scripts.insert("ph".to_string(), "maturin:print_hello".to_string());
Expand Down Expand Up @@ -195,7 +195,7 @@ mod test {
"#
);

let cargo_toml: CargoToml = toml::from_str(cargo_toml).unwrap();
let cargo_toml: CargoToml = toml_edit::easy::from_str(cargo_toml).unwrap();

let classifiers = vec!["Programming Language :: Python".to_string()];

Expand Down Expand Up @@ -226,7 +226,7 @@ mod test {
"#
);

let cargo_toml: Result<CargoToml, _> = toml::from_str(cargo_toml);
let cargo_toml: Result<CargoToml, _> = toml_edit::easy::from_str(cargo_toml);
assert!(cargo_toml.is_ok());
}
}
10 changes: 5 additions & 5 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ mod test {

let toml_with_path = cargo_toml.replace("REPLACE_README_PATH", &readme_path);

let cargo_toml_struct: CargoToml = toml::from_str(&toml_with_path).unwrap();
let cargo_toml_struct: CargoToml = toml_edit::easy::from_str(&toml_with_path).unwrap();

let metadata =
Metadata21::from_cargo_toml(&cargo_toml_struct, &readme_md.path().parent().unwrap())
Expand Down Expand Up @@ -718,7 +718,7 @@ mod test {
"#
);

let cargo_toml_struct: CargoToml = toml::from_str(cargo_toml).unwrap();
let cargo_toml_struct: CargoToml = toml_edit::easy::from_str(cargo_toml).unwrap();
let metadata =
Metadata21::from_cargo_toml(&cargo_toml_struct, "/not/exist/manifest/path").unwrap();
let actual = metadata.to_file_contents();
Expand Down Expand Up @@ -763,7 +763,7 @@ mod test {
#[test]
fn test_merge_metadata_from_pyproject_toml() {
let cargo_toml_str = fs_err::read_to_string("test-crates/pyo3-pure/Cargo.toml").unwrap();
let cargo_toml: CargoToml = toml::from_str(&cargo_toml_str).unwrap();
let cargo_toml: CargoToml = toml_edit::easy::from_str(&cargo_toml_str).unwrap();
let metadata = Metadata21::from_cargo_toml(&cargo_toml, "test-crates/pyo3-pure").unwrap();
assert_eq!(
metadata.summary,
Expand Down Expand Up @@ -824,7 +824,7 @@ mod test {
fn test_merge_metadata_from_pyproject_toml_with_customized_python_source_dir() {
let cargo_toml_str =
fs_err::read_to_string("test-crates/pyo3-mixed-py-subdir/Cargo.toml").unwrap();
let cargo_toml: CargoToml = toml::from_str(&cargo_toml_str).unwrap();
let cargo_toml: CargoToml = toml_edit::easy::from_str(&cargo_toml_str).unwrap();
let metadata =
Metadata21::from_cargo_toml(&cargo_toml, "test-crates/pyo3-mixed-py-subdir").unwrap();
// defined in Cargo.toml
Expand All @@ -839,7 +839,7 @@ mod test {
#[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 cargo_toml = toml_edit::easy::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!(
Expand Down
2 changes: 1 addition & 1 deletion src/pyproject_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl PyProjectToml {
"Couldn't find pyproject.toml at {}",
path.display()
))?;
let pyproject: PyProjectToml = toml::from_str(&contents)
let pyproject: PyProjectToml = toml_edit::easy::from_str(&contents)
.map_err(|err| format_err!("pyproject.toml is not PEP 517 compliant: {}", err))?;
Ok(pyproject)
}
Expand Down
8 changes: 4 additions & 4 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn rewrite_cargo_toml(
"Can't read Cargo.toml at {}",
manifest_path.as_ref().display(),
))?;
let mut data = toml::from_str::<toml::value::Table>(&text).context(format!(
let mut data = text.parse::<toml_edit::Document>().context(format!(
"Failed to parse Cargo.toml at {}",
manifest_path.as_ref().display()
))?;
Expand Down Expand Up @@ -60,10 +60,10 @@ fn rewrite_cargo_toml(
}
// This is the location of the targeted crate in the source distribution
table[&dep_name]["path"] = if root_crate {
format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name).into()
toml_edit::value(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, dep_name))
} else {
// Cargo.toml contains relative paths, and we're already in LOCAL_DEPENDENCIES_FOLDER
format!("../{}", dep_name).into()
toml_edit::value(format!("../{}", dep_name))
};
rewritten = true;
if !known_path_deps.contains_key(&dep_name) {
Expand All @@ -79,7 +79,7 @@ fn rewrite_cargo_toml(
}
}
if rewritten {
Ok(toml::to_string(&data)?)
Ok(data.to_string())
} else {
Ok(text)
}
Expand Down