Skip to content

MNT: upgrade ruff pre-commit hook, move its configuration out of pre-commit-config.yaml and fix lints#371

Merged
glesur merged 4 commits into
idefix-code:developfrom
neutrinoceros:lint/ruff-conf
Jul 15, 2026
Merged

MNT: upgrade ruff pre-commit hook, move its configuration out of pre-commit-config.yaml and fix lints#371
glesur merged 4 commits into
idefix-code:developfrom
neutrinoceros:lint/ruff-conf

Conversation

@neutrinoceros

Copy link
Copy Markdown
Collaborator

Moving ruff's config to ruff.toml allows running ruff's LSP in an IDE and see lints before git commit is invoked.
I also upgraded the tool to a much more recent version and applied newly discovered lints.

@neutrinoceros

neutrinoceros commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator Author

Seeing a couple failures with

TypeError: zip() takes no keyword arguments

which indicate that the python interpreter used in CI is older than 3.10.
While I strongly recommend upgrading it at least to 3.111, I could also adjust settings to preserve compatibility with an older Python version, though in this case, please let me know how far back you'd like me to go.

Footnotes

  1. for motivation Python 3.9 is EOL already and 3.10 will be too in about 6 month

@neutrinoceros
neutrinoceros changed the base branch from master to develop April 4, 2026 08:43
@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

updated base branch to develop

@glesur

glesur commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

python updated to 3.14 from sources on the self-hosted runner. Should work fine.

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

thanks. Pre-commit still failed on CI but it looks like some unrelated networking error.

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

linting passed, but now the env under which tests are run looks broken.

@glesur

glesur commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

tests are failing because somehow #367 is not included upstream. Can you rebase ?

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

I don't think that's it. I did check that commits from #367 are in my branch's history. In any case rebasing locally turned into a no-op

Comment thread test/MHD/LinearWaveTest/testme.py Outdated
@glesur

glesur commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

I put this PR on hold: forcing python3.14 on the host running the tests has too many side effects, including breaking the package manager and breaking the pydefix test for all the other branches (including master)

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

sure. Python 3.11 or 3.12 would probably be safer bets, but there's no rush.
What package manager is it, out of curiosity ?

@glesur

glesur commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

apt, running on debian 11

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

I think you mean
image

@glesur

glesur commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@neutrinoceros can you add a dummy commit to trigger the CI? python and cuda have been updated on the testing infrastructure, this PR should now succeed.

@neutrinoceros

Copy link
Copy Markdown
Collaborator Author

not as is. Recent changes have also added to the pile of smells that ruff flags. I'll fix them too and rebase

@neutrinoceros
neutrinoceros force-pushed the lint/ruff-conf branch 2 times, most recently from c20427b to 3564149 Compare July 10, 2026 09:14
- add missing stacklevel in a Python warning
- use conventional naming for unused loop variables in Python
- Fix violations to rules, B011, B006 and B904

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the Python linting setup by upgrading the Ruff pre-commit hook and moving Ruff configuration into a dedicated ruff.toml, then applies the resulting lint-driven cleanups across test scripts and pytools.

Changes:

  • Upgraded Ruff’s pre-commit hook and migrated its rule selection/ignores into a new ruff.toml.
  • Performed widespread import ordering / blank-line normalization across many test helper scripts to satisfy Ruff/isort.
  • Applied small Python correctness/quality tweaks in pytools (e.g., safer default-arg patterns, better exception chaining, improved warnings attribution).

Reviewed changes

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

Show a summary per file
File Description
test/utils/lookupTable/testme.py Import/blank-line formatting for Ruff
test/utils/dumpImage/testme.py Import/blank-line formatting for Ruff
test/utils/columnDensity/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/UniformCollapse/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/UniformCollapse/python/testidefix.py Import ordering/grouping cleanup
test/SelfGravity/RandomSphereCartesian/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/RandomSphereCartesian/python/testidefix.py Import ordering/grouping cleanup
test/SelfGravity/RandomSphere/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/RandomSphere/python/testidefix.py Import ordering/grouping cleanup
test/SelfGravity/JeansInstability/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/JeansInstability/python/testidefix.py Import ordering/grouping cleanup
test/SelfGravity/DustyCollapse/testme.py Import/blank-line formatting for Ruff
test/SelfGravity/DustyCollapse/python/testidefix.py Import ordering/grouping cleanup
test/Pluto/HD/sod/python/testidefix.py Import ordering/grouping cleanup
test/Pluto/HD/sod/python/sod.py Adds zip(..., strict=True) for safer mapping construction
test/Pluto/HD/sod/python/idefixTools.py Blank-line normalization
test/Planet/PlanetTorque3D/testme.py Import/blank-line formatting for Ruff
test/Planet/PlanetTorque3D/python/testidefix.py Import/blank-line formatting for Ruff
test/Planet/PlanetSpiral2D/testme.py Import/blank-line formatting for Ruff
test/Planet/PlanetSpiral2D/python/testidefix.py Import ordering/grouping cleanup
test/Planet/PlanetsIsActiveRK52D/testme.py Import/blank-line formatting for Ruff
test/Planet/PlanetsIsActiveRK52D/python/testidefix.py Import/blank-line formatting for Ruff
test/Planet/PlanetPlanetRK42D/testme.py Import/blank-line formatting for Ruff
test/Planet/PlanetPlanetRK42D/python/testidefix.py Import ordering/grouping cleanup
test/Planet/PlanetMigration2D/testme.py Import/blank-line formatting for Ruff
test/Planet/PlanetMigration2D/python/testidefix.py Import/blank-line formatting for Ruff
test/Planet/Planet3Body/testme.py Import/blank-line formatting for Ruff
test/Planet/Planet3Body/python/testidefix.py Import/blank-line formatting for Ruff
test/MHD/sphBragViscosity/testme.py Import/blank-line formatting for Ruff
test/MHD/sphBragViscosity/python/testidefix.py Import ordering/grouping cleanup
test/MHD/sphBragTDiffusion/testme.py Import/blank-line formatting for Ruff
test/MHD/sphBragTDiffusion/python/testidefix.py Import ordering/grouping cleanup
test/MHD/sod/testme.py Import/blank-line formatting for Ruff
test/MHD/sod-iso/testme.py Import/blank-line formatting for Ruff
test/MHD/ShearingBox/testme.py Import/blank-line formatting for Ruff
test/MHD/ShearingBox/python/testidefix.py Import ordering/grouping cleanup
test/MHD/ResistiveAlfvenWave/testme.py Import/blank-line formatting for Ruff
test/MHD/ResistiveAlfvenWave/python/testidefix.py Import ordering/grouping cleanup
test/MHD/OrszagTang3D/testme.py Import/blank-line formatting for Ruff
test/MHD/OrszagTang/testme.py Import/blank-line formatting for Ruff
test/MHD/MTI/testme.py Import/blank-line formatting for Ruff
test/MHD/MTI/python/testidefix.py Import ordering/grouping cleanup
test/MHD/LinearWaveTest/testme.py Import/blank-line formatting for Ruff
test/MHD/LinearWaveTest/python/testidefix.py Import ordering/grouping cleanup
test/MHD/HallWhistler/testme.py Import/blank-line formatting for Ruff
test/MHD/HallWhistler/python/testidefix.py Import ordering/grouping cleanup
test/MHD/FargoMHDSpherical/testme.py Import/blank-line formatting for Ruff
test/MHD/Coarsening/testme.py Import/blank-line formatting for Ruff
test/MHD/Coarsening/python/testidefix.py Import ordering/grouping cleanup
test/MHD/clessTDiffusion/testme.py Import/blank-line formatting for Ruff
test/MHD/clessTDiffusion/python/testidefix.py Import ordering/grouping cleanup
test/MHD/AxisFluxTube/testme.py Import/blank-line formatting for Ruff
test/MHD/AxisFluxTube/python/checkAxisBounds.py Import ordering/grouping cleanup
test/MHD/AmbipolarShearingBox/python/testidefix.py Import ordering/grouping cleanup
test/MHD/AmbipolarCshock3D/testme.py Import/blank-line formatting for Ruff
test/MHD/AmbipolarCshock3D/python/testidefix.py Import ordering/grouping cleanup
test/MHD/AmbipolarCshock/testme.py Import/blank-line formatting for Ruff
test/MHD/AmbipolarCshock/python/testidefix.py Import ordering/grouping cleanup
test/IO/xdmf/testme.py Fixes control flow so the XDMF existence check is reliably executed
test/IO/pydefix/testme.py Import/blank-line formatting for Ruff
test/IO/pydefix/pydefix_example.py Import ordering/grouping cleanup
test/IO/dump/testme.py Import/blank-line formatting for Ruff
test/HD/ViscousFlowPastCylinder/testme.py Import/blank-line formatting for Ruff
test/HD/ViscousDisk/testme.py Import/blank-line formatting for Ruff
test/HD/ViscousDisk/python/testidefix.py Import ordering/grouping cleanup
test/HD/thermalDiffusion/testme.py Import/blank-line formatting for Ruff
test/HD/thermalDiffusion/python/testidefix.py Import ordering/grouping cleanup
test/HD/sod/testme.py Import/blank-line formatting for Ruff
test/HD/sod/python/testidefix.py Import ordering/grouping cleanup
test/HD/sod/pydefix_example.py Import ordering/grouping cleanup
test/HD/sod-iso/testme.py Import/blank-line formatting for Ruff
test/HD/sod-iso/python/testidefix.py Import ordering/grouping cleanup
test/HD/ShearingBox/testme.py Import/blank-line formatting for Ruff
test/HD/ShearingBox/python/testidefix.py Import ordering/grouping cleanup
test/HD/SedovBlastWave/testme.py Import/blank-line formatting for Ruff
test/HD/SedovBlastWave/python/testidefix.py Import ordering/grouping cleanup
test/HD/MachReflection/testme.py Import/blank-line formatting for Ruff
test/HD/FargoPlanet/testme.py Import/blank-line formatting for Ruff
test/Dust/DustyWave/testme.py Import/blank-line formatting for Ruff
test/Dust/DustyWave/python/testidefix.py Import ordering/grouping cleanup
test/Dust/DustyShock/testme.py Import/blank-line formatting for Ruff
test/Dust/DustyShock/python/testidefix.py Import ordering/grouping cleanup
test/Dust/DustEnergy/testme.py Import/blank-line formatting for Ruff
test/Dust/DustEnergy/python/testidefix.py Import ordering/grouping cleanup
test.py Import/blank-line formatting for Ruff
ruff.toml New Ruff configuration (target version + lint selection/ignores)
pytools/vtk_io.py Import ordering + warnings.warn(..., stacklevel=...) improvement
pytools/tests/test_idfx_test_run.py Import ordering/grouping cleanup
pytools/tests/test_idfx_test_gen.py Import ordering/grouping cleanup
pytools/sod.py Adds zip(..., strict=True) for safer mapping construction
pytools/idfx_test.py Import ordering + safer defaults for optional dict args
pytools/idfx_test_run.py Import ordering + exception chaining + NotImplementedError
pytools/idfx_test_gen.py Avoids mutable default args by using None + initialization
pytools/idfx_io.py Minor loop variable cleanup (_)
pytools/dump_io.py Minor loop variable cleanup (_)
doc/source/plot_idefix_bench.py Import ordering/blank-line normalization
.pre-commit-config.yaml Upgrades Ruff pre-commit revision and switches to ruff-check hook

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

Comment thread pytools/idfx_test.py Outdated
Comment thread pytools/idfx_test.py
Comment on lines +260 to +261
if override is None:
override = {}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Indentation inconsistencies can trivially be resolved in the long run by also enabling the formatter hook from ruff. Happy to open a follow up PR to achieve this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

#392 👀

Comment thread ruff.toml
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@glesur
glesur merged commit 4f0ff74 into idefix-code:develop Jul 15, 2026
41 checks passed
@neutrinoceros
neutrinoceros deleted the lint/ruff-conf branch July 15, 2026 07:47
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.

3 participants