Skip to content

Conversation

@Borda
Copy link
Contributor

@Borda Borda commented Jan 13, 2026

This pull request removes support for flake8 in favor of using ruff as the primary Python linter and code style checker. It updates configuration files, scripts, and workflow definitions to reflect this change, and consolidates all linting rules and ignores into pyproject.toml under the [tool.ruff] section.

Migration from flake8 to ruff:

  • Removed all references to flake8 and its plugins from requirements-dev.txt, setup.cfg, and the runtests.sh script, making ruff the sole linter for code style checks. [1] [2] [3] [4] [5] [6] [7] [8]

  • Updated GitHub Actions workflow job names from flake8-py3 to lint-py3 to reflect the switch to ruff. [1] [2]

Ruff configuration enhancements:

  • Expanded the [tool.ruff.lint].select list in pyproject.toml to include additional rule sets previously covered by flake8 plugins (e.g., B for flake8-bugbear, C90 for mccabe, N for pep8-naming, etc.).

  • Migrated and extended ignore rules from flake8 to ruff, ensuring that all previously ignored warnings and errors are now managed through pyproject.toml.

  • Adjusted line-length in pyproject.toml from 133 to 120 to standardize formatting.

Cleanup:

  • Removed the [flake8] section from setup.cfg, consolidating all linting configuration into pyproject.toml.

Copilot AI review requested due to automatic review settings January 13, 2026 09:04
@Borda Borda requested a review from KumoLiu as a code owner January 13, 2026 09:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

This PR migrates the codebase from flake8 to ruff for linting. Changes include renaming GitHub Actions workflow job identifiers from flake8-py3 to lint-py3, removing flake8 from development dependencies and configuration, and expanding ruff lint rules in pyproject.toml with additional error codes and per-file ignores. The PR also removes redundant explicit pass statements across multiple files, updates import paths from relative to absolute, and deprecates the --flake8 CLI flag in runtests.sh in favor of --ruff. Documentation is updated to reflect the linting toolchain change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.87% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely summarizes the main change: replacing flake8 with ruff as the primary linter and updating related rules.
Description check ✅ Passed Description comprehensively explains the migration from flake8 to ruff, configuration changes in pyproject.toml, workflow updates, and cleanup actions. All required template sections are addressed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request migrates the project's Python linting infrastructure from flake8 to ruff, consolidating all linting configuration into pyproject.toml and removing flake8-related dependencies and scripts.

Changes:

  • Removed all flake8 and flake8-plugin dependencies from requirements-dev.txt
  • Deleted the [flake8] section from setup.cfg
  • Removed flake8-related flags, variables, and test sections from runtests.sh
  • Expanded ruff configuration in pyproject.toml with additional rule sets (B, C90, N, PIE, TID) and migrated ignore rules
  • Updated GitHub Actions workflow job names from flake8-py3 to lint-py3
  • Changed ruff line-length from 133 to 120 to match black's configuration

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
setup.cfg Removed the [flake8] configuration section including select, ignore, and exclude patterns
runtests.sh Removed flake8 command-line flags, shell variables, and the flake8 test execution block
requirements-dev.txt Removed flake8 and its plugins (flake8-bugbear, flake8-comprehensions) from development dependencies
pyproject.toml Expanded ruff lint rule selection and migrated flake8 ignore rules with documentation; adjusted line-length to 120
.github/workflows/weekly-preview.yml Renamed job from flake8-py3 to lint-py3
.github/workflows/pythonapp.yml Renamed job from flake8-py3 to lint-py3
Comments suppressed due to low confidence (1)

requirements-dev.txt:16

  • The packages mccabe, pep8-naming, pycodestyle, and pyflakes are now redundant since ruff includes all their functionality. These were previously used by flake8 and its plugins, but since flake8 has been removed, these dependencies should also be removed unless they are used by another tool in the project (e.g., if yesqa in .pre-commit-config.yaml still needs them).
mccabe
pep8-naming
pycodestyle
pyflakes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
pyproject.toml (2)

57-57: Consider enabling RUF100 to catch stale noqa directives.

With rule sets changing, some noqa comments may become obsolete. RUF100 auto-detects these.

Suggested change
   "NPY",         # NumPy specific rules
   "UP",          # pyupgrade
-  # "RUF100",      # aka yesqa
+  "RUF100",      # aka yesqa - catches unused noqa directives
 ]

65-66: Commented rules W503/W504 don't exist in ruff.

These were pycodestyle-only rules. Safe to remove the comments entirely.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 57fdd59 and dd5f392.

📒 Files selected for processing (18)
  • .github/workflows/pythonapp.yml
  • .github/workflows/weekly-preview.yml
  • monai/apps/detection/transforms/box_ops.py
  • monai/auto3dseg/algo_gen.py
  • monai/data/box_utils.py
  • monai/fl/client/client_algo.py
  • monai/networks/blocks/feature_pyramid_network.py
  • monai/networks/nets/dints.py
  • monai/networks/trt_compiler.py
  • monai/transforms/traits.py
  • monai/utils/profiling.py
  • pyproject.toml
  • requirements-dev.txt
  • runtests.sh
  • setup.cfg
  • tests/handlers/test_handler_regression_metrics.py
  • tests/integration/test_integration_classification_2d.py
  • tests/utils/type_conversion/test_convert_data_type.py
💤 Files with no reviewable changes (10)
  • setup.cfg
  • tests/integration/test_integration_classification_2d.py
  • tests/utils/type_conversion/test_convert_data_type.py
  • monai/auto3dseg/algo_gen.py
  • requirements-dev.txt
  • monai/networks/trt_compiler.py
  • monai/transforms/traits.py
  • monai/networks/blocks/feature_pyramid_network.py
  • monai/fl/client/client_algo.py
  • monai/networks/nets/dints.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.

Files:

  • monai/utils/profiling.py
  • monai/apps/detection/transforms/box_ops.py
  • monai/data/box_utils.py
  • tests/handlers/test_handler_regression_metrics.py
🪛 Ruff (0.14.10)
monai/utils/profiling.py

340-340: Unused noqa directive (non-enabled: N805)

Remove unused noqa directive

(RUF100)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: min-dep-os (macOS-latest)
  • GitHub Check: min-dep-pytorch (2.6.0)
  • GitHub Check: min-dep-pytorch (2.7.1)
  • GitHub Check: min-dep-pytorch (2.5.1)
  • GitHub Check: min-dep-py3 (3.12)
  • GitHub Check: min-dep-py3 (3.11)
  • GitHub Check: min-dep-pytorch (2.8.0)
  • GitHub Check: min-dep-py3 (3.9)
  • GitHub Check: min-dep-os (windows-latest)
  • GitHub Check: min-dep-os (ubuntu-latest)
  • GitHub Check: min-dep-py3 (3.10)
  • GitHub Check: lint-py3 (mypy)
  • GitHub Check: quick-py3 (windows-latest)
  • GitHub Check: quick-py3 (ubuntu-latest)
  • GitHub Check: packaging
  • GitHub Check: quick-py3 (macOS-latest)
  • GitHub Check: lint-py3 (pytype)
  • GitHub Check: lint-py3 (codeformat)
🔇 Additional comments (13)
monai/data/box_utils.py (4)

594-596: LGTM!

Simplifying range(0, spatial_dims) to range(spatial_dims) — idiomatic Python, no behavioral change.


734-736: LGTM!

Same stylistic cleanup — range(spatial_dims) is cleaner.


1044-1050: LGTM!

Consistent with other range simplifications in this PR.


1136-1136: LGTM!

Range simplification applied consistently.

monai/apps/detection/transforms/box_ops.py (1)

181-183: LGTM!

Default flip_axes computation simplified. Same behavior.

tests/handlers/test_handler_regression_metrics.py (1)

73-73: LGTM!

Direct keyword argument is cleaner than dict unpacking.

pyproject.toml (2)

42-42: LGTM!

Line length now consistent with black config (line 12).


47-57: Rule selection looks good.

Comprehensive coverage migrating from flake8 plugins. Comments with doc links are helpful.

.github/workflows/weekly-preview.yml (1)

8-8: LGTM!

Job name now accurately reflects it runs general linting, not just flake8.

.github/workflows/pythonapp.yml (1)

25-25: LGTM!

Consistent with weekly-preview.yml rename.

monai/utils/profiling.py (1)

340-340: The # noqa: N805 directive is necessary and should be retained.

N805 is active in ruff configuration (N rules selected, N805 not ignored). The code intentionally uses _self to avoid shadowing the outer self scope, making the noqa suppression valid.

Likely an incorrect or invalid review comment.

runtests.sh (2)

62-62: LGTM: --flake8 option removed from usage.

Consistent with the PR objective. The help text now correctly reflects available linting options with ruff as the replacement.


265-271: LGTM: --codeformat now relies solely on ruff for linting.

The shorthand -f|--codeformat correctly activates black, isort, ruff, and copyright checks. Flake8 reference removed as expected.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pyproject.toml (1)

83-84: max-complexity = 50 is essentially disabled.

Standard threshold is 10-15. The TODO acknowledges this needs lowering. Also, typo: "treshold" → "threshold".

Typo fix
-max-complexity = 50  # todo lower this treshold when yesqa id replaced with Ruff's RUF100
+max-complexity = 50  # todo lower this threshold when yesqa is replaced with Ruff's RUF100
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between dd5f392 and 2f9dd9c.

📒 Files selected for processing (8)
  • monai/apps/auto3dseg/bundle_gen.py
  • monai/metrics/confusion_matrix.py
  • monai/metrics/loss_metric.py
  • monai/transforms/regularization/array.py
  • monai/transforms/regularization/dictionary.py
  • monai/transforms/traits.py
  • monai/utils/deprecate_utils.py
  • pyproject.toml
💤 Files with no reviewable changes (1)
  • monai/transforms/traits.py
✅ Files skipped from review due to trivial changes (1)
  • monai/metrics/confusion_matrix.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.

Files:

  • monai/transforms/regularization/dictionary.py
  • monai/apps/auto3dseg/bundle_gen.py
  • monai/metrics/loss_metric.py
  • monai/transforms/regularization/array.py
  • monai/utils/deprecate_utils.py
🧬 Code graph analysis (2)
monai/transforms/regularization/dictionary.py (1)
monai/transforms/transform.py (2)
  • MapTransform (372-497)
  • RandomizableTransform (328-369)
monai/transforms/regularization/array.py (1)
monai/transforms/transform.py (1)
  • RandomizableTransform (328-369)
🔇 Additional comments (10)
monai/transforms/regularization/array.py (1)

22-22: LGTM!

Absolute import aligns with PR's import normalization pattern. Path correctly references monai.transforms.transform.

monai/transforms/regularization/dictionary.py (1)

24-25: LGTM!

Absolute import for MapTransform and RandomizableTransform is consistent with sibling module array.py.

monai/metrics/loss_metric.py (1)

22-23: LGTM!

Absolute import for TensorOrList follows the PR's normalization pattern.

monai/utils/deprecate_utils.py (2)

24-24: LGTM!

Absolute import for __version__ follows the PR's normalization pattern.


203-207: LGTM!

Using _ to discard the binding result suppresses unused-variable warnings from ruff while preserving the validation logic.

monai/apps/auto3dseg/bundle_gen.py (1)

210-213: LGTM!

Tuple-based endswith is cleaner and idiomatic. Functionally equivalent to separate checks.

pyproject.toml (4)

42-42: Good alignment with black.

line-length = 120 matches the black configuration on line 12. Consistency achieved.


46-58: Rule expansion looks solid.

Adding B, C90, N, PIE, TID covers the flake8 plugins being removed. RUF100 commented out with clear TODO intent.


63-70: Clarify E501 + line-length interaction.

E501 is ignored, but line-length = 120 is set. Ruff uses line-length for the formatter and E501 for the linter. Ignoring E501 means no lint warnings for long lines—only the formatter will wrap. If that's intentional (let formatter handle it), this is fine. Otherwise, remove E501 from ignore.


72-81: Per-file ignores are reasonable.

Tests get flexibility on naming (N999, N801), complexity (C901), and useless expressions (B018). ATSS_matcher.py exception for N999 due to filename.

@Borda
Copy link
Contributor Author

Borda commented Jan 13, 2026

@ericspod as part of this PR, I have renamed the CI jobs stated as flake8 to be lint since they never just flake8 but an aggregation of lint, and typing... that is why the flake8-* are pending...

@hjmjohnson
Copy link
Contributor

@Borda Very nice!

Borda and others added 15 commits January 29, 2026 15:07
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
for more information, see https://pre-commit.ci

Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
for more information, see https://pre-commit.ci

Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <jirka.borovec@seznam.cz>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
…label ordering bug (Project-MONAI#8680)

### Description

Rename `NormalizeLabelsInDatasetd` to `RemapLabelsToSequentiald` to
better describe its actual functionality. The old name was confusing as
it suggests normalization when it actually remaps arbitrary label values
to sequential indices (0, 1, 2, 3, ...).

Fixes Project-MONAI#7800

### Bug Fix

Fixed a bug where the order of labels in the input dictionary affected
the output.
Previously, if background appeared first (e.g., `{background: 0, organ1:
1, organ2: 2}`), the transform would skip index 1 and produce
`{background: 0, organ1: 2, organ2: 3}`.
This was caused by enumerate starting at 1 for all items but skipping
background without adjusting the index. The fix excludes background from
enumeration and handles it separately.

### Changes

- Renamed `NormalizeLabelsInDatasetd` to `RemapLabelsToSequentiald`
- Fixed label ordering bug by excluding background from enumeration
- Kept `NormalizeLabelsInDatasetd` as deprecated alias for backward
compatibility
- Enhanced documentation to clearly explain remapping behavior
- Added alphabetical sorting for deterministic output ordering
- Added tests for deprecated name warning and proper remapping

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] New tests added to cover the changes.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.

---------

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
### Description

This adds the "what's new" page for the minor 1.5.2 release. This commit
should probably just be cherry-picked for the release. Branch rules will
have to be temporarily broken to allow the PR past blossom as well,
since no code is modified here this is safe and it's only the
documentation generation that should be checked.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
for more information, see https://pre-commit.ci

Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
Borda and others added 3 commits January 29, 2026 15:10
Signed-off-by: jirka <6035284+Borda@users.noreply.github.com>
@Borda
Copy link
Contributor Author

Borda commented Jan 29, 2026

@ericspod @KumoLiu aligned with the dev branch, so is there anything else I can do?

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.

4 participants