From 02eb3d51ecf42f16c8136fb4e0dd91e2531d5ba1 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Thu, 3 Sep 2026 10:06:58 -0500 Subject: [PATCH] ENH: Declare ruff's vendored-file excludes once in pyproject.toml versioneer.py and monai/_version.py were excluded from ruff twice, independently: .pre-commit-config.yaml's ruff hook via its own "exclude:" regex, and runtests.sh via hardcoded --exclude flags on the CLI invocation. Neither read from pyproject.toml, so a third direct "ruff check" invocation (an editor, a one-off shell command) would lint and offer to rewrite both files -- 200 violations today. extend-exclude in [tool.ruff] gives runtests.sh's directory-walk invocation (and any other caller that lets ruff discover its own config) the same exclusion pre-commit's hook already applies, so the CLI flags on the runtests.sh invocation are redundant and dropped. Verified: 'ruff check' with pyproject.toml's new extend-exclude, given the directory the way runtests.sh gives it, still reports 'All checks passed!' for the tree, and 'runtests.sh --ruff' is unaffected end to end. Ruff ignores config exclude when handed explicit filenames instead of a directory (the pre-commit hook path, already governed by its own hook-level exclude, and not something this PR touches). Signed-off-by: Hans Johnson --- pyproject.toml | 2 ++ runtests.sh | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 684d905002..f7a38926b2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -292,6 +292,8 @@ exclude = ''' [tool.ruff] line-length = 120 target-version = "py310" +# .pre-commit-config.yaml's ruff hook excludes these separately at the pre-commit layer +extend-exclude = ["versioneer.py", "monai/_version.py"] [tool.ruff.lint] select = [ diff --git a/runtests.sh b/runtests.sh index 0fc18b36ec..af1835c11d 100755 --- a/runtests.sh +++ b/runtests.sh @@ -599,9 +599,9 @@ then if [ $doRuffFix = true ] then - ruff check --fix --unsafe-fixes --exclude versioneer.py --exclude "monai/_version.py" "$homedir" + ruff check --fix --unsafe-fixes "$homedir" else - ruff check --exclude versioneer.py --exclude "monai/_version.py" "$homedir" + ruff check "$homedir" fi ruff_status=$?