devito icon indicating copy to clipboard operation
devito copied to clipboard

misc: Ruff

Open JDBetteridge opened this issue 2 months ago • 2 comments

I'm trying to automate detection a lot of the "nitpick" code review comments and providing a route to automatically fixing the issues apriori.

What I have added to CI is equivalent to locally running:

isort --check-only --sort-reexports --multi-line VERTICAL_GRID_GROUPED --line-length 90 --force-alphabetical-sort-within-sections --project devito,examples .
ruff check --preview  --select E,W,F,B,UP,SIM,I,RUF022 --ignore F403,E226,E731,E275,F405,E722,E741,W605 --line-length=90 --output-format concise

Most command line arguments are included in the pyproject.toml and checking out this branch you can just run

isort --check-only .
ruff check --output-format concise

Fixing most linting issues is as simple as

isort .
ruff check --fix

if you trust the auto-formatter!

This PR also extends linting to Dockerfiles and Github actions too.

An excerpt from CONTRIBUTING.md:

Coding guidelines

Some coding rules are "enforced" (and automatically checked by our Continuous Integration systems), some are "strongly recommended", others are "optional" but welcome.

  • We enforce PEP8, with a few exceptions, listed here
  • We enforce a maximum line length of 90 characters.
  • We enforce indentation via 4 spaces.
  • We suggest to use flake8 to check the above points locally, before filing a Pull Request.
  • We strongly recommend to document any new module, class, routine, ... with NumPy-like docstrings ("numpydoc").
  • We strongly recommend imports to be at the top of a module, logically grouped and, within each group, to be alphabetically ordered. As an example, condider our init.py: the first group is imports from the standard library; then imports from third-party dependencies; finally, imports from devito modules.
  • We strongly recommend to follow standard Python coding guidelines:
    • Use camel caps for class names, e.g. class FooBar.
    • Method names must start with a small letter; use underscores to separate words, e.g. def _my_meth_....
    • Private class attributes and methods must start with an underscore.
    • Variable names should be explicative (Devito prefers "long and clear" over "short but unclear").
    • Comment your code, and do not be afraid of being verbose. The first letter must be capitalized. Do not use punctuation (unless the comment consists of multiple sentences).
  • We like that blank lines are used to logically split blocks of code implementing different (possibly sequential) tasks.

JDBetteridge avatar Oct 16 '25 23:10 JDBetteridge

Codecov Report

:x: Patch coverage is 82.08517% with 244 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 83.19%. Comparing base (59c357b) to head (c8bb54c).

Files with missing lines Patch % Lines
devito/mpi/routines.py 18.60% 35 Missing :warning:
tests/test_data.py 56.75% 16 Missing :warning:
devito/mpi/distributed.py 37.50% 15 Missing :warning:
devito/arch/compiler.py 50.00% 12 Missing and 2 partials :warning:
tests/test_ir.py 48.14% 14 Missing :warning:
tests/test_operator.py 41.66% 14 Missing :warning:
benchmarks/user/benchmark.py 54.16% 11 Missing :warning:
devito/data/data.py 38.46% 8 Missing :warning:
devito/tools/data_structures.py 50.00% 8 Missing :warning:
devito/data/utils.py 53.84% 5 Missing and 1 partial :warning:
... and 58 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2771      +/-   ##
==========================================
+ Coverage   83.02%   83.19%   +0.16%     
==========================================
  Files         248      248              
  Lines       50804    50589     -215     
  Branches     4479     4392      -87     
==========================================
- Hits        42180    42087      -93     
+ Misses       7857     7753     -104     
+ Partials      767      749      -18     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.79% <71.39%> (+0.25%) :arrow_up:
pytest-gpu-nvc-nvidiaX 69.31% <71.41%> (+0.26%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 16 '25 23:10 codecov[bot]

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB