Skip to content

Commit

Permalink
Upgrade to toml v0.5.11 (#2040)
Browse files Browse the repository at this point in the history
In #1680, we moved over to `toml_edit`. But it looks like `toml` now uses `toml_edit`, and has implemented some improvements (e.g., this closes #1894).
  • Loading branch information
charliermarsh authored Jan 20, 2023
1 parent a0e3347 commit 20a9252
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 51 deletions.
39 changes: 4 additions & 35 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 @@ -62,7 +62,7 @@ strum_macros = { version = "0.24.3" }
textwrap = { version = "0.16.0" }
thiserror = { version = "1.0" }
titlecase = { version = "2.2.1" }
toml_edit = { version = "0.17.1", features = ["easy"] }
toml = { version = "0.5.11" }

# https://docs.rs/getrandom/0.2.7/getrandom/#webassembly-support
# For (future) wasm-pack support
Expand Down
2 changes: 1 addition & 1 deletion flake8_to_ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde = { version = "1.0.147", features = ["derive"] }
serde_json = { version = "1.0.87" }
strum = { version = "0.24.1", features = ["strum_macros"] }
strum_macros = { version = "0.24.3" }
toml_edit = { version = "0.17.1", features = ["easy"] }
toml = { version = "0.5.11" }

[dev-dependencies]

Expand Down
2 changes: 1 addition & 1 deletion flake8_to_ruff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() -> Result<()> {

// Create Ruff's pyproject.toml section.
let pyproject = flake8_to_ruff::convert(&config, black.as_ref(), cli.plugin)?;
println!("{}", toml_edit::easy::to_string_pretty(&pyproject)?);
println!("{}", toml::to_string_pretty(&pyproject)?);

Ok(())
}
2 changes: 1 addition & 1 deletion src/flake8_to_ruff/black.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Pyproject {

pub fn parse_black_options<P: AsRef<Path>>(path: P) -> Result<Option<Black>> {
let contents = std::fs::read_to_string(path)?;
Ok(toml_edit::easy::from_str::<Pyproject>(&contents)?
Ok(toml::from_str::<Pyproject>(&contents)?
.tool
.and_then(|tool| tool.black))
}
24 changes: 12 additions & 12 deletions src/settings/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ impl Pyproject {
/// Parse a `ruff.toml` file.
fn parse_ruff_toml<P: AsRef<Path>>(path: P) -> Result<Options> {
let contents = fs::read_file(path)?;
toml_edit::easy::from_str(&contents).map_err(Into::into)
toml::from_str(&contents).map_err(Into::into)
}

/// Parse a `pyproject.toml` file.
fn parse_pyproject_toml<P: AsRef<Path>>(path: P) -> Result<Pyproject> {
let contents = fs::read_file(path)?;
toml_edit::easy::from_str(&contents).map_err(Into::into)
toml::from_str(&contents).map_err(Into::into)
}

/// Return `true` if a `pyproject.toml` contains a `[tool.ruff]` section.
Expand Down Expand Up @@ -144,17 +144,17 @@ mod tests {

#[test]
fn deserialize() -> Result<()> {
let pyproject: Pyproject = toml_edit::easy::from_str(r#""#)?;
let pyproject: Pyproject = toml::from_str(r#""#)?;
assert_eq!(pyproject.tool, None);

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
"#,
)?;
assert_eq!(pyproject.tool, Some(Tools { ruff: None }));

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
})
);

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
Expand Down Expand Up @@ -275,7 +275,7 @@ line-length = 79
})
);

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
Expand Down Expand Up @@ -336,7 +336,7 @@ exclude = ["foo.py"]
})
);

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
Expand Down Expand Up @@ -397,7 +397,7 @@ select = ["E501"]
})
);

let pyproject: Pyproject = toml_edit::easy::from_str(
let pyproject: Pyproject = toml::from_str(
r#"
[tool.black]
[tool.ruff]
Expand Down Expand Up @@ -459,7 +459,7 @@ ignore = ["E501"]
})
);

assert!(toml_edit::easy::from_str::<Pyproject>(
assert!(toml::from_str::<Pyproject>(
r#"
[tool.black]
[tool.ruff]
Expand All @@ -468,7 +468,7 @@ line_length = 79
)
.is_err());

assert!(toml_edit::easy::from_str::<Pyproject>(
assert!(toml::from_str::<Pyproject>(
r#"
[tool.black]
[tool.ruff]
Expand All @@ -477,7 +477,7 @@ select = ["E123"]
)
.is_err());

assert!(toml_edit::easy::from_str::<Pyproject>(
assert!(toml::from_str::<Pyproject>(
r#"
[tool.black]
[tool.ruff]
Expand Down

0 comments on commit 20a9252

Please sign in to comment.