Enable more ruff rules - #7470
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7470 +/- ##
==========================================
+ Coverage 80.68% 80.68% +0.01%
==========================================
Files 581 581
Lines 47068 47068
==========================================
+ Hits 37971 37974 +3
+ Misses 9097 9094 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: QUIET Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR narrows Ruff ignores, adds targeted ChangesLint cleanup and warning compliance
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/schedulers/test_slurm.py`:
- Around line 59-61: Update the ValueError match pattern in the SlurmJobResource
test to use a single escaped asterisk in the raw regex, so it matches the
literal “*” in the error message rather than backslashes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5be77c4f-4616-4935-a97b-bd1e076c56ad
📒 Files selected for processing (35)
.molecule/default/files/polish/lib/expression.pypyproject.tomlsrc/aiida/engine/processes/calcjobs/calcjob.pysrc/aiida/engine/processes/workchains/restart.pysrc/aiida/orm/nodes/data/array/bands.pysrc/aiida/orm/utils/node.pysrc/aiida/restapi/resources.pysrc/aiida/storage/sqlite_zip/orm.pysrc/aiida/tools/dbimporters/plugins/icsd.pysrc/aiida/transports/plugins/async_backend.pytests/cmdline/params/types/test_calculation.pytests/cmdline/params/types/test_code.pytests/cmdline/params/types/test_group.pytests/cmdline/utils/test_common.pytests/conftest.pytests/engine/daemon/test_client.pytests/engine/processes/test_control.pytests/engine/test_run.pytests/engine/test_runners.pytests/engine/test_work_chain.pytests/manage/configuration/test_config.pytests/orm/data/code/test_abstract.pytests/orm/data/code/test_containerized.pytests/orm/data/code/test_installed.pytests/orm/data/code/test_portable.pytests/orm/models/test_models.pytests/orm/nodes/data/test_array.pytests/orm/nodes/data/test_data.pytests/orm/nodes/data/test_jsonable.pytests/orm/nodes/data/test_remote.pytests/orm/nodes/data/test_trajectory.pytests/schedulers/test_slurm.pytests/test_conftest.pytests/tools/archive/migration/test_v06_to_v07.pytests/transports/test_all_plugins.py
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/engine/daemon/test_client.py (2)
94-94: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winInclude the trailing periods in the exception-message assertions.
DaemonNotRunningExceptionandDaemonTimeoutExceptionraise messages that end with periods, so the assertions attests/engine/daemon/test_client.py:94and:106should matchr'The daemon is not running\.'andr'Connection to the daemon timed out\.'.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/engine/daemon/test_client.py` at line 94, Update the exception message patterns in the relevant pytest.raises assertions to match the trailing periods emitted by DaemonNotRunningException and DaemonTimeoutException, escaping the periods in the regex while preserving the existing message text.
166-166: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winRemove the hard-coded temporary path from the fixture.
Ruff reports
S108for/tmp/aiida-coreon Line 166. The value is test metadata, not a file operation, but it still violates the lint check in this lint-cleanup PR. Use a non-temporary sentinel or derive the value withpathlib.Path.Proposed fix
- 'aiida-core': {'version': '2.6.0', 'editable_path': '/tmp/aiida-core'}, + 'aiida-core': { + 'version': '2.6.0', + 'editable_path': str(pathlib.Path('aiida-core').resolve()), + },Ruff 0.16.1 reports this
S108finding.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/engine/daemon/test_client.py` at line 166, Replace the hard-coded `/tmp/aiida-core` value in the fixture metadata with a non-temporary sentinel or a value derived through pathlib.Path, while preserving the fixture’s expected editable_path metadata.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/engine/daemon/test_client.py`:
- Line 94: Update the exception message patterns in the relevant pytest.raises
assertions to match the trailing periods emitted by DaemonNotRunningException
and DaemonTimeoutException, escaping the periods in the regex while preserving
the existing message text.
- Line 166: Replace the hard-coded `/tmp/aiida-core` value in the fixture
metadata with a non-temporary sentinel or a value derived through pathlib.Path,
while preserving the fixture’s expected editable_path metadata.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7bda5155-3b71-4c23-8070-0b3af5a71194
📒 Files selected for processing (8)
pyproject.tomlsrc/aiida/engine/processes/calcjobs/calcjob.pysrc/aiida/transports/plugins/async_backend.pytests/conftest.pytests/engine/daemon/test_client.pytests/engine/test_work_chain.pytests/orm/models/test_models.pytests/orm/nodes/data/test_array.py
🚧 Files skipped from review as they are similar to previous changes (7)
- tests/conftest.py
- src/aiida/engine/processes/calcjobs/calcjob.py
- pyproject.toml
- tests/orm/models/test_models.py
- tests/orm/nodes/data/test_array.py
- tests/engine/test_work_chain.py
- src/aiida/transports/plugins/async_backend.py
GeigerJ2
left a comment
There was a problem hiding this comment.
Thanks, @danielhollas. Always LGTM for enabling more ruff rules! Red CI is just because of the merge of main, that re-introduced two hits. Should be easy to resolve by re-running pre-commit on all files. Then, good to merge and I will approve.
The many times we return tuples, just to unpack them and immediately throw away half of its members, hints that we should be using more proper datastructures. Underscore prefix is the right, well-scoped fix for this PR, though.
|
I've added PLR0911 back to the ignore list, since this rule is not included in the new expanded set of default rules in ruff 0.16, which I think we should migrate into, see more info in https://astral.sh/blog/ruff-v0.16.0#better-default-rule-set Otherwise this should be ready @GeigerJ2 |
GeigerJ2
left a comment
There was a problem hiding this comment.
Thanks, @danielhollas, already approve. One minor nit:
tests/cmdline/utils/test_common.py:107,112, tests/orm/nodes/data/test_remote.py:160
with pytest.raises(TypeError, match=r'.*passed for validation.'):
with pytest.raises(FileExistsError, match=r'.*use `--overwrite` to overwrite.'):
with pytest.raises(ValueError, match=r'.*is not an valid input. Please choose either.*.'):The trailing . is a real period in each message, but now reads as a wildcard. Escape it if you want to keep asserting the period (match=r'passed for validation\\.'), or drop it. test_all_plugins.py:1362 is the inverse: match=r'Error while creating the tar archive' has no metacharacter left, so the r is inert; its twin at :1520 has none.
Thanks, I dropped the trailing periods. Also, the Will merge after tests pass unless somebody stops me. :-) |
This is a follow-up to the recent ruff upgrades, where I purposefully disabled some rules that had a lot of hits to ease review.
Here I enable three more rules and fix (or add noqas) all the hits
RUFF043
RUF059 (unused-unpacked-variable)
### PLR0911 (too-many-return-statements)