Skip to content

Route runtests.sh ruff invocations through PY_EXE - #9089

Merged
ericspod merged 2 commits into
Project-MONAI:devfrom
BRAINSia:mono-runtests-ruff-pyexe
Sep 8, 2026
Merged

Route runtests.sh ruff invocations through PY_EXE#9089
ericspod merged 2 commits into
Project-MONAI:devfrom
BRAINSia:mono-runtests-ruff-pyexe

Conversation

@hjmjohnson

Copy link
Copy Markdown
Contributor

runtests.sh calls every other formatter (black, isort, pylint, pytype) through "${PY_EXE}" -m; the ruff invocations still called a bare ruff off PATH. is_pip_installed ruff checks $PY_EXE, so the guard and the invocation could disagree — in a clean venv built per CONTRIBUTING.md with no editable PATH entry, ./runtests.sh --codeformat fails with ruff: command not found even though ruff is installed and importable from $PY_EXE.

No behavior change when ruff happens to already be on PATH (the common case in an activated venv); this only fixes the case where it isn't.

Reproduced before/after

With $PY_EXE pointed at a venv holding ruff, and that venv absent from PATH:

$ MONAI_PY_EXE=/path/to/venv/bin/python bash -c 'PY_EXE=$MONAI_PY_EXE; ruff --version'
bash: line 1: ruff: command not found

$ MONAI_PY_EXE=/path/to/venv/bin/python bash -c 'PY_EXE=$MONAI_PY_EXE; "${PY_EXE}" -m ruff --version'
ruff 0.16.5

./runtests.sh --ruff with $PY_EXE set and the venv not on PATH now reaches All checks passed! instead of failing at the version check.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 1a50661b-109c-4c8e-820c-affd94b98651

📥 Commits

Reviewing files that changed from the base of the PR and between 303842d and 6b73bac.

📒 Files selected for processing (1)
  • runtests.sh

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

runtests.sh now runs the Ruff version check and both Ruff check variants through "${PY_EXE}" -m ruff. Existing fix, unsafe-fix, and file-exclusion options remain unchanged.

Priority: ⬇️ Low — Defer this Ruff invocation fix because it is a narrow three-line test-script change with no broader product impact.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to 6b73b

Ruff now runs from the selected Python environment, avoiding PATH-dependent failures while retaining existing lint options and behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the change, the failure scenario, and the expected behavior. It does not follow the repository template because it omits the issue reference, required section headings… Add the required Fixes # ... line, ### Description heading, and ### Types of changes checklist. Mark the applicable test and change categories, including whether the specified integration or quick tests were run.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: routing runtests.sh Ruff invocations through PY_EXE.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the change, the failure scenario, and the expected behavior. It does not follow the repository template because it omits the issue reference, required section headings, and the types-of-changes checklist.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

runtests.sh calls every other formatter (black, isort, pylint, pytype)
via "${PY_EXE}" -m so it targets the same interpreter the
is_pip_installed() guard checked. The ruff invocations still called a
bare `ruff` off PATH, so is_pip_installed("ruff") could pass against
$PY_EXE while the invocation ran a different (or absent) ruff from
PATH. In a clean venv built per CONTRIBUTING.md with no editable
PATH entry, ./runtests.sh --codeformat fails with
"ruff: command not found" even though ruff is installed and
importable from $PY_EXE.

Reproduced: with $PY_EXE pointed at a venv holding ruff and that
venv absent from PATH, the old `ruff --version` failed with
"command not found"; "${PY_EXE}" -m ruff --version succeeded.

Signed-off-by: Hans Johnson <hans-johnson@uiowa.edu>
@hjmjohnson
hjmjohnson force-pushed the mono-runtests-ruff-pyexe branch from 2da2aed to e213eae Compare September 5, 2026 17:51
ericspod
ericspod previously approved these changes Sep 8, 2026

@ericspod ericspod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thanks

ericspod added a commit that referenced this pull request Sep 8, 2026
`versioneer.py` and `monai/_version.py` were excluded from ruff twice,
independently: `.pre-commit-config.yaml`'s 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 the same exclusion pre-commit's hook already applies, so the
CLI flags there are now redundant and dropped.

Independent of #9089 (which routes the same block's `ruff` calls through
`PY_EXE`) — rebuilt directly off `dev` so the two PRs' diffs don't
overlap. Whichever lands first, the other needs a small rebase over the
same lines; neither depends on the other's content.

<details>
<summary>Verification</summary>

- `ruff check` given the directory the way `runtests.sh` gives it (not
explicit filenames) reports `All checks passed!` for the tree with the
new `extend-exclude` in place, and `runtests.sh --ruff` is unaffected
end to end.
- Confirmed the CLI `--exclude` flag being dropped was purely additive
over `extend-exclude`, not required for it to take effect: a synthetic
`pyproject.toml` with only `extend-exclude` set already hid the excluded
file from `ruff check .`, before any `--exclude` flag was added.
- Ruff ignores config `exclude`/`extend-exclude` when handed explicit
filenames instead of a directory — that's the pre-commit hook's path,
already governed by its own hook-level `exclude:`, and this PR doesn't
touch it.

</details>

<!--
provenance: claude-code session 2026-09-03, branch
mono-ruff-extend-exclude off dev @ 9ea04d4
(rebuilt disjoint from #9089 per user request; previously stacked on
that branch)
related: split out of #9067 (closed) as one of three narrower
follow-ups. Sibling: #9089
(independent, same file region), and #9091 (independent, version-pin
cross-reference comments).
-->

Signed-off-by: Hans Johnson <hans-johnson@uiowa.edu>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
@ericspod
ericspod enabled auto-merge (squash) September 8, 2026 15:32
@ericspod
ericspod merged commit 20df602 into Project-MONAI:dev Sep 8, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants