Add fix:ruff action

This commit is contained in:
Abdo 2025-06-23 10:40:56 +03:00
parent 7a4f8fdeaf
commit 8d18aaf002
3 changed files with 26 additions and 16 deletions

View file

@ -197,21 +197,28 @@ pub fn check_python(build: &mut Build) -> Result<()> {
},
)?;
let ruff_folders = &[
"qt/aqt",
"ftl",
"pylib/tools",
"tools",
"python",
];
let ruff_deps = inputs![
glob!["{pylib,ftl,qt,python,tools}/**/*.py"],
":pylib:anki",
":qt:aqt"
];
build.add_action("check:ruff", RuffCheck {
folders: &[
"qt/aqt",
"ftl",
"pylib/tools",
"tools",
"python",
],
deps: inputs![
glob!["{pylib,ftl,qt,python,tools}/**/*.py"],
":pylib:anki",
":qt:aqt"
],
folders: ruff_folders,
deps: ruff_deps.clone(),
check_only: true,
})?;
build.add_action("fix:ruff", RuffCheck {
folders: ruff_folders,
deps: ruff_deps,
check_only: false,
})?;
Ok(())
}

View file

@ -247,20 +247,23 @@ pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Resu
pub struct RuffCheck {
pub folders: &'static [&'static str],
pub deps: BuildInput,
pub check_only: bool,
}
impl BuildAction for RuffCheck {
fn command(&self) -> &str {
"$ruff check $folders"
"$ruff check $folders $mode"
}
fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("", &self.deps);
build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_variable("folders", self.folders.join(" "));
build.add_variable("mode", if self.check_only { "" } else { "--fix" });
let hash = simple_hash(&self.deps);
build.add_output_stamp(format!("tests/python_ruff_check.{hash}"));
let kind = if self.check_only { "check" } else { "fix" };
build.add_output_stamp(format!("tests/python_ruff.{kind}.{hash}"));
}
}

View file

@ -85,7 +85,7 @@ When formatting issues are reported, they can be fixed with
./ninja format
```
## Fixing eslint/copyright header issues
## Fixing ruff/eslint/copyright header issues
```
./ninja fix