From 8d18aaf0021a0b1ae8d210dd23680fb1da7e0412 Mon Sep 17 00:00:00 2001 From: Abdo Date: Mon, 23 Jun 2025 10:40:56 +0300 Subject: [PATCH] Add fix:ruff action --- build/configure/src/python.rs | 33 ++++++++++++++++++++------------- build/ninja_gen/src/python.rs | 7 +++++-- docs/development.md | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/build/configure/src/python.rs b/build/configure/src/python.rs index dfaa16a0d..cb8fae8c2 100644 --- a/build/configure/src/python.rs +++ b/build/configure/src/python.rs @@ -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(()) } diff --git a/build/ninja_gen/src/python.rs b/build/ninja_gen/src/python.rs index d4f04134f..b5d75f503 100644 --- a/build/ninja_gen/src/python.rs +++ b/build/ninja_gen/src/python.rs @@ -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}")); } } diff --git a/docs/development.md b/docs/development.md index c963aec02..defe9ef1e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -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