neuroinformatics-unit / movement

Python tools for analysing body movements across space and time
http://movement.neuroinformatics.dev
BSD 3-Clause "New" or "Revised" License
77 stars 7 forks source link

Overhaul linting and formatting #156

Closed niksirbi closed 2 months ago

niksirbi commented 3 months ago

Description

What is this PR

Why is this PR needed?

We use ruff for linting and black for auto-formatting. With the introduction of ruff.format (a drop-in replacement for black, but faster) there is no longer need to be using black. This prompted me to overhaul our entire lint/format setup.

What does this PR do?

I went through the scientific python development guide for style and static checks and applied the recommendations that make sense for movement.

In summary these are:

What does this PR NOT do? I also considered adding the "D" ruff rule (pydocstyle) to enforce consistent formatting for our docstrings (according to PEP8 recommendations). I think this is super useful, but currently requires some manual work to update lots of our non-compliant docstrings (135 non auto-fixable violations!). I will open an issue to do this later.

References

If we end up being happy with the new setup, we may consider porting it over to the python-cookiecutter.

Does this PR require an update to the documentation?

The contributed guidelines have been updated accordingly.

Checklist:

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.63%. Comparing base (5123a41) to head (f3b433c).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #156 +/- ## ========================================== + Coverage 99.28% 99.63% +0.35% ========================================== Files 9 9 Lines 557 554 -3 ========================================== - Hits 553 552 -1 + Misses 4 2 -2 ```

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

niksirbi commented 3 months ago

Tagging @neuroinformatics-unit/behaviour and @b-peri, because these changes will affect workflows for all.

lochhh commented 2 months ago

Thanks again @niksirbi ! Happy to merge once the following two things are addressed:

adamltyson commented 2 months ago

Assuming these changes aren't too specific to movement, could they be added to the cookiecutter, and gradually rolled out to other packages? I'm very keen that our tools don't start to diverge in terms of tooling.

niksirbi commented 2 months ago

Assuming these changes aren't too specific to movement, could they be added to the cookiecutter, and gradually rolled out to other packages? I'm very keen that our tools don't start to diverge in terms of tooling.

Yes, the plan was to roll them out in movement first, for testing, and after a few weeks (assuming all is well) roll them out to the cookiecutter + other packages.

niksirbi commented 2 months ago
  • The mixed-line-ending check fails with 52 files when running pre-commit run --all-files locally on Windows. Could you try this on a Mac?

@lochhh I can't reproduce this on Mac. Running pre-commit run --all-files on my M2 Mac finds no issues. Could you check whether your IDE is configured to automatically use CRLF for line endings (i.e. \r\n, that's the Windows way)? On Unix systems it's LF (\n) and that's what the pre-commit hook enforces (and in theory, auto-fixes).

lochhh commented 2 months ago
  • The mixed-line-ending check fails with 52 files when running pre-commit run --all-files locally on Windows. Could you try this on a Mac?

@lochhh I can't reproduce this on Mac. Running pre-commit run --all-files on my M2 Mac finds no issues. Could you check whether your IDE is configured to automatically use CRLF for line endings (i.e. \r\n, that's the Windows way)? On Unix systems it's LF (\n) and that's what the pre-commit hook enforces (and in theory, auto-fixes).

Thanks for looking into this. Can confirm it is indeed my IDE that's automatically converting the line endings.

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

niksirbi commented 2 months ago

Thanks for verifying @lochhh. I'll merge this now.