Skip to content

[MAINT] switch to ruff#261

Merged
Remi-Gau merged 4 commits intocpp-lln-lab:mainfrom
Remi-Gau:ruff
Mar 23, 2026
Merged

[MAINT] switch to ruff#261
Remi-Gau merged 4 commits intocpp-lln-lab:mainfrom
Remi-Gau:ruff

Conversation

@Remi-Gau
Copy link
Copy Markdown
Contributor

@Remi-Gau Remi-Gau commented Mar 3, 2026

Summary by Sourcery

Adopt Ruff as the primary Python linter/formatter and adjust project tooling and code style accordingly.

Enhancements:

  • Replace isort and flake8 with Ruff configuration in pyproject and pre-commit, including linting, formatting, and complexity/pylint limits.
  • Tighten mypy settings and pytest configuration, including enabled error codes and treating warnings as errors.
  • Apply small code cleanups and style adjustments in the Python package to satisfy new linting rules and improve clarity.

CI:

  • Refine pre-commit CI metadata, including autofix commit messages and monthly autoupdates.

Chores:

  • Expand and reorganize general pre-commit hooks, including AST/TOML checks and reStructuredText validations, and remove the obsolete .flake8 configuration file.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 3, 2026

Reviewer's Guide

Switches the project from isort/flake8 to Ruff for linting and formatting, updates pre-commit and pytest configs accordingly, and applies small code changes to satisfy Ruff and tighten some tooling settings.

File-Level Changes

Change Details Files
Replace isort/flake8-based linting with Ruff configuration in pyproject and remove legacy lint config.
  • Remove [tool.isort] section from pyproject configuration.
  • Add comprehensive [tool.ruff] sections (format, lint, per-file ignores, pylint-style limits) targeting project source, tools, and docs.
  • Delete standalone .flake8 config file.
pyproject.toml
.flake8
Update pre-commit hooks to use Ruff and improve general repo checks.
  • Remove isort and flake8 hooks and add ruff-check and ruff-format hooks with autofix options.
  • Adjust import-linter hook to run in Python and with verbose output.
  • Expand core pre-commit checks (AST, TOML, mixed-line-ending) and add reStructuredText validation hooks.
  • Configure pre-commit CI messages and schedules for autofix and autoupdate.
.pre-commit-config.yaml
Tighten mypy and pytest configuration to work better with the new tooling.
  • Enable additional mypy error codes (redundant-expr, truthy-bool) and add TODO comments for future tightening (ignore-without-code, warn_unreachable).
  • Configure pytest to treat warnings as errors, set log level explicitly, and preserve existing options.
pyproject.toml
Apply Ruff/formatter-driven style changes and small logic cleanups across the codebase.
  • Normalize Plotly configuration to use literal dicts instead of dict() calls and adjust string concatenation in CLI description.
  • Fix path checks to use Path.exists() instead of truthiness and simplify attribute comparisons for the 'run' argument handling.
  • Simplify dataset description conditional logic, remove redundant Path('.') default, and avoid in-place pandas modification by reassigning dropna() result.
  • Minor cleanup of unused blank line in report entry point.
bidsmreye/visualize.py
bidsmreye/configuration.py
bidsmreye/bids_utils.py
bidsmreye/_parsers.py
bidsmreye/methods.py
bidsmreye/quality_control.py
bidsmreye/report.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The boolean condition in bids_utils.check_layout is still quite hard to read; consider extracting intermediate booleans (e.g. has_dataset_type, is_derivative) or refactoring into a small helper to make the logic easier to understand and maintain.
  • The ruff-check pre-commit hook is configured with --fix and --unsafe-fixes, which can rewrite code non-trivially; you may want to confine unsafe fixes to local runs (e.g. via a separate hook or config flag) to avoid surprising changes in shared/CI workflows.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The boolean condition in `bids_utils.check_layout` is still quite hard to read; consider extracting intermediate booleans (e.g. `has_dataset_type`, `is_derivative`) or refactoring into a small helper to make the logic easier to understand and maintain.
- The `ruff-check` pre-commit hook is configured with `--fix` and `--unsafe-fixes`, which can rewrite code non-trivially; you may want to confine unsafe fixes to local runs (e.g. via a separate hook or config flag) to avoid surprising changes in shared/CI workflows.

## Individual Comments

### Comment 1
<location path="bidsmreye/configuration.py" line_range="239" />
<code_context>
         config_file = my_path / default

-    if config_file is None or not Path(config_file).exists():
+    if not Path(config_file).exists():
         raise FileNotFoundError(f"Config file {config_file} not found")

</code_context>
<issue_to_address>
**issue (bug_risk):** Calling get_config with default="" now attempts to open a directory as a file.

With this change, when `config_file` is `None` and `default` is `""`, `config_file` becomes `my_path / ""` (the `config` directory). `Path(config_file).exists()` will be `True`, so you’ll now hit an `IsADirectoryError` from `open(config_file)` instead of the previous `FileNotFoundError`.

To keep the clearer failure mode, consider either restoring the `config_file is None` check, enforcing a non-empty `default` before building the path, or using `Path(config_file).is_file()` instead of `exists()`.
</issue_to_address>

### Comment 2
<location path=".pre-commit-config.yaml" line_range="69-71" />
<code_context>
+-   repo: https://github.com/astral-sh/ruff-pre-commit
+    rev: v0.15.1
+    hooks:
+    -   id: ruff-check
+        # args: [--statistics]
+        args: [--fix, --show-fixes, --unsafe-fixes]
+    -   id: ruff-format
+        # args: [--diff]
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using --unsafe-fixes in ruff-check may introduce semantic changes during pre-commit runs.

Since these transformations can alter runtime behaviour and are applied automatically on developer machines, they may introduce subtle bugs. Consider removing `--unsafe-fixes` from the pre-commit hook and instead running them only in an explicit context (e.g. a dedicated script or CI job), while keeping pre-commit limited to safer auto-fixes.

```suggestion
    -   id: ruff-check
        # args: [--statistics]
        args: [--fix, --show-fixes]
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

config_file = my_path / default

if config_file is None or not Path(config_file).exists():
if not Path(config_file).exists():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Calling get_config with default="" now attempts to open a directory as a file.

With this change, when config_file is None and default is "", config_file becomes my_path / "" (the config directory). Path(config_file).exists() will be True, so you’ll now hit an IsADirectoryError from open(config_file) instead of the previous FileNotFoundError.

To keep the clearer failure mode, consider either restoring the config_file is None check, enforcing a non-empty default before building the path, or using Path(config_file).is_file() instead of exists().

Comment on lines +69 to +71
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes, --unsafe-fixes]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Using --unsafe-fixes in ruff-check may introduce semantic changes during pre-commit runs.

Since these transformations can alter runtime behaviour and are applied automatically on developer machines, they may introduce subtle bugs. Consider removing --unsafe-fixes from the pre-commit hook and instead running them only in an explicit context (e.g. a dedicated script or CI job), while keeping pre-commit limited to safer auto-fixes.

Suggested change
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes, --unsafe-fixes]
- id: ruff-check
# args: [--statistics]
args: [--fix, --show-fixes]

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.73%. Comparing base (1bcca23) to head (8d09b79).
⚠️ Report is 123 commits behind head on main.

Files with missing lines Patch % Lines
bidsmreye/methods.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #261      +/-   ##
==========================================
+ Coverage   79.91%   81.73%   +1.82%     
==========================================
  Files          13       16       +3     
  Lines         926     1046     +120     
  Branches      119        0     -119     
==========================================
+ Hits          740      855     +115     
- Misses        144      191      +47     
+ Partials       42        0      -42     
Flag Coverage Δ
tests 81.73% <88.88%> (+1.93%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@Remi-Gau Remi-Gau merged commit 05ffa31 into cpp-lln-lab:main Mar 23, 2026
13 of 15 checks passed
@Remi-Gau Remi-Gau deleted the ruff branch March 23, 2026 13:44
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.

1 participant