Conversation
Reviewer's GuideSwitches 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The boolean condition in
bids_utils.check_layoutis 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-checkpre-commit hook is configured with--fixand--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>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(): |
There was a problem hiding this comment.
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().
| - id: ruff-check | ||
| # args: [--statistics] | ||
| args: [--fix, --show-fixes, --unsafe-fixes] |
There was a problem hiding this comment.
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.
| - id: ruff-check | |
| # args: [--statistics] | |
| args: [--fix, --show-fixes, --unsafe-fixes] | |
| - id: ruff-check | |
| # args: [--statistics] | |
| args: [--fix, --show-fixes] |
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by Sourcery
Adopt Ruff as the primary Python linter/formatter and adjust project tooling and code style accordingly.
Enhancements:
CI:
Chores: