Skip to content

[ENH] Format with Ruff#1231

Open
bendhouseart wants to merge 8 commits intomainfrom
format-with-ruff
Open

[ENH] Format with Ruff#1231
bendhouseart wants to merge 8 commits intomainfrom
format-with-ruff

Conversation

@bendhouseart
Copy link
Copy Markdown
Contributor

@bendhouseart bendhouseart commented Mar 19, 2026

Just ran ruff across pybids to make future PR's a bit easier to parse.

Dragging this library into the formatting future, PR is large because of it, so I've added the relevant files that should be looked at in this comment below.

I'd really like to enforce a single ruff.toml (or as much can be) for all of our python repo's going forward, so you're going to have a hard time convincing me that what I've done with noqa is necessarily a bad thing.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 84.24705% with 227 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.51%. Comparing base (91fcdde) to head (fbbebe5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/bids/cli.py 48.33% 31 Missing ⚠️
src/bids/layout/layout.py 78.30% 20 Missing and 3 partials ⚠️
src/bids/modeling/statsmodels.py 66.15% 18 Missing and 4 partials ⚠️
src/bids/modeling/hrf.py 55.26% 16 Missing and 1 partial ⚠️
src/bids/variables/io.py 65.00% 14 Missing ⚠️
src/bids/modeling/report/utils.py 47.61% 11 Missing ⚠️
src/bids/layout/models.py 89.88% 8 Missing and 1 partial ⚠️
src/bids/modeling/report/base.py 30.76% 9 Missing ⚠️
src/bids/variables/variables.py 76.92% 8 Missing and 1 partial ⚠️
src/bids/modeling/report/viz.py 33.33% 8 Missing ⚠️
... and 25 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1231      +/-   ##
==========================================
- Coverage   89.58%   89.51%   -0.07%     
==========================================
  Files          70       70              
  Lines        7860     7851       -9     
  Branches      956      955       -1     
==========================================
- Hits         7041     7028      -13     
- Misses        580      584       +4     
  Partials      239      239              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bendhouseart
Copy link
Copy Markdown
Contributor Author

bendhouseart commented Mar 20, 2026

This is fun, moved ruff ignores into code with # noqa: <code number> where able. Some of the fixes required by ruff were breaking changes, so I figured that we can ignore them for now on legacy code, but enforce them on new changes.

Ruff also got up to some nonsense with docstring and __*__.py files, but I think that's fixed as the build step of the CI is now passing.

Assuming the rest of checks go, I'll add in a precommit config and call this done.

@bendhouseart bendhouseart requested a review from effigies March 20, 2026 16:25
@bendhouseart bendhouseart marked this pull request as ready for review March 20, 2026 16:25
Suppression counts added (by Ruff code): UP031 (79), D102 (48),
D103 (33), D101 (31), F601 (22), D417 (20), C408 (16), B006 (13),
C403 (13), D100 (11), E741 (11), B904 (11), B028 (10), B007 (9),
C414 (9), D104 (7), B905 (7), A002 (6), F841 (6), E501 (6),
E402 (4), D404 (3), BLE001 (3), B019 (3), S101 (3), C401 (2),
C419 (2), C416 (2), UP030 (2), F811 (2),
and EXE002/A001/DTZ011/D301/B004/S110/S307/DTZ005/S701/E711/E721/E731 (1 each).

Total # noqa lines added: 389. Total code entries across those lines: 406

Intention is to resolve errors (eventually) in the form of PR's by
error code to make reviewing unsafe fixes manageable.
@bendhouseart
Copy link
Copy Markdown
Contributor Author

bendhouseart commented Mar 26, 2026

Solved some self made issues here and have included links to the relevant files for review with this formatting PR:

  1. Code base (where able) has been formatted with ruff, no unsafe fixes or major refactors applied to keep things stable.
  2. Kept ruff.toml as minimal as possible by adding error codes to offending lines in pybids with # noqa: <error code>.
  3. Added pre-commit config to help enforce ruffing
  4. Added new job to workflow that counts the number of # noqa's floating around, if they increase it's a CI fail. Intention is to keep the non-ruffness (smoothness?) of the library from spreading to new contributions.

Going forward I'll start chipping away at the following errors so we're super consistent and able to get away from #noqa, just need to knock these out:

Suppression counts added (by Ruff code): UP031 (79), D102 (48),
D103 (33), D101 (31), F601 (22), D417 (20), C408 (16), B006 (13),
C403 (13), D100 (11), E741 (11), B904 (11), B028 (10), B007 (9),
C414 (9), D104 (7), B905 (7), A002 (6), F841 (6), E501 (6),
E402 (4), D404 (3), BLE001 (3), B019 (3), S101 (3), C401 (2),
C419 (2), C416 (2), UP030 (2), F811 (2),
and EXE002/A001/DTZ011/D301/B004/S110/S307/DTZ005/S701/E711/E721/E731 (1 each).

@bendhouseart
Copy link
Copy Markdown
Contributor Author

hurrah, the noqa workflow works.

@bendhouseart bendhouseart requested a review from Remi-Gau March 26, 2026 22:22
@bendhouseart bendhouseart self-assigned this Mar 26, 2026
@@ -0,0 +1,20 @@
ci:
autoupdate_schedule: monthly
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
autoupdate_schedule: monthly
autoupdate_schedule: quarterly

Comment on lines +112 to +115
[dependency-groups]
dev = [
"ruff>=0.15.7",
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
[dependency-groups]
dev = [
"ruff>=0.15.7",
]

I would remove this and let pre-commit deal with installing ruff otherwise you may have different ruff version (one in pyproject.toml and the other precommit cfg)

fetch-depth: 0
- name: Ensure '# noqa' count does not increase
run: |
python tools/check_noqa_budget.py --base-ref "origin/${{ github.base_ref }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

given this is in the tox.ini, could we use tox to run it in CI?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

my hunch is that things in external we should not touch, no?

@Remi-Gau
Copy link
Copy Markdown
Contributor

AFAICT ruff is not run in CI, right?
wanna do it in this PR (either using the pre-commit github action) or by hooking up the repo with pre-commit CI?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the approach of making sure the number noqa will go down over time, however I think I would first go with a blanket approach of (the 2 approach are not mutually exclusive):

  • ignore the error in this PR for now
  • fix all the instances of a given error in a follow up PR
  • only leave noqa where errors should be ignored on specific lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants