Improve debug logging in flake8-to-ruff (#1320)

This commit is contained in:
Charlie Marsh 2022-12-21 20:05:48 -05:00 committed by GitHub
parent 953d141ab2
commit 5c70f5044b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 6 deletions

2
Cargo.lock generated
View file

@ -735,6 +735,8 @@ dependencies = [
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
"strum",
"strum_macros",
"toml", "toml",
] ]

View file

@ -16,6 +16,8 @@ ruff = { path = "..", default-features = false }
rustc-hash = { version = "1.1.0" } rustc-hash = { version = "1.1.0" }
serde = { version = "1.0.147", features = ["derive"] } serde = { version = "1.0.147", features = ["derive"] }
serde_json = { version = "1.0.87" } serde_json = { version = "1.0.87" }
strum = { version = "0.24.1", features = ["strum_macros"] }
strum_macros = { version = "0.24.3" }
toml = { version = "0.5.9" } toml = { version = "0.5.9" }
[dev-dependencies] [dev-dependencies]

View file

@ -61,10 +61,18 @@ pub fn convert(
plugin::resolve_select( plugin::resolve_select(
flake8, flake8,
&plugins.unwrap_or_else(|| { &plugins.unwrap_or_else(|| {
plugin::infer_plugins_from_options(flake8) let from_options = plugin::infer_plugins_from_options(flake8);
.into_iter() if !from_options.is_empty() {
.chain(plugin::infer_plugins_from_codes(&referenced_codes)) eprintln!("Inferred plugins from settings: {from_options:#?}");
.collect() }
let from_codes = plugin::infer_plugins_from_codes(&referenced_codes);
if !from_codes.is_empty() {
eprintln!(
"Inferred plugins from referenced check codes: {:#?}",
from_codes
);
}
from_options.into_iter().chain(from_codes).collect()
}), }),
) )
}); });

View file

@ -1,10 +1,11 @@
use std::collections::{BTreeSet, HashMap}; use std::collections::{BTreeSet, HashMap};
use std::fmt;
use std::str::FromStr; use std::str::FromStr;
use anyhow::anyhow; use anyhow::anyhow;
use ruff::checks_gen::CheckCodePrefix; use ruff::checks_gen::CheckCodePrefix;
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)] #[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum Plugin { pub enum Plugin {
Flake8Annotations, Flake8Annotations,
Flake8Bandit, Flake8Bandit,
@ -42,7 +43,7 @@ impl FromStr for Plugin {
"flake8-datetimez" => Ok(Plugin::Flake8Datetimez), "flake8-datetimez" => Ok(Plugin::Flake8Datetimez),
"flake8-debugger" => Ok(Plugin::Flake8Debugger), "flake8-debugger" => Ok(Plugin::Flake8Debugger),
"flake8-docstrings" => Ok(Plugin::Flake8Docstrings), "flake8-docstrings" => Ok(Plugin::Flake8Docstrings),
"flake8-eradicate" => Ok(Plugin::Flake8BlindExcept), "flake8-eradicate" => Ok(Plugin::Flake8Eradicate),
"flake8-errmsg" => Ok(Plugin::Flake8ErrMsg), "flake8-errmsg" => Ok(Plugin::Flake8ErrMsg),
"flake8-print" => Ok(Plugin::Flake8Print), "flake8-print" => Ok(Plugin::Flake8Print),
"flake8-quotes" => Ok(Plugin::Flake8Quotes), "flake8-quotes" => Ok(Plugin::Flake8Quotes),
@ -58,6 +59,37 @@ impl FromStr for Plugin {
} }
} }
impl fmt::Debug for Plugin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Plugin::Flake8Annotations => "flake8-annotations",
Plugin::Flake8Bandit => "flake8-bandit",
Plugin::Flake8BlindExcept => "flake8-blind-except",
Plugin::Flake8Bugbear => "flake8-bugbear",
Plugin::Flake8Builtins => "flake8-builtins",
Plugin::Flake8Comprehensions => "flake8-comprehensions",
Plugin::Flake8Datetimez => "flake8-datetimez",
Plugin::Flake8Debugger => "flake8-debugger",
Plugin::Flake8Docstrings => "flake8-docstrings",
Plugin::Flake8Eradicate => "flake8-eradicate",
Plugin::Flake8ErrMsg => "flake8-errmsg",
Plugin::Flake8Print => "flake8-print",
Plugin::Flake8Quotes => "flake8-quotes",
Plugin::Flake8Return => "flake8-return",
Plugin::Flake8Simplify => "flake8-simplify",
Plugin::Flake8TidyImports => "flake8-tidy-imports",
Plugin::McCabe => "mccabe",
Plugin::PandasVet => "pandas-vet",
Plugin::PEP8Naming => "pep8-naming",
Plugin::Pyupgrade => "pyupgrade",
}
)
}
}
impl Plugin { impl Plugin {
pub fn default(&self) -> CheckCodePrefix { pub fn default(&self) -> CheckCodePrefix {
match self { match self {