Skip to content

Add pre-commit + format all Python code with Ruff#778

Merged
ddabble merged 5 commits intomainfrom
cleanup/ruff-format
Dec 8, 2025
Merged

Add pre-commit + format all Python code with Ruff#778
ddabble merged 5 commits intomainfrom
cleanup/ruff-format

Conversation

@ddabble
Copy link
Member

@ddabble ddabble commented Oct 23, 2025

Proposed changes

  • Added pre-commit with the following hooks:
  • Formatted all Python code with Ruff (b57c22a)

Also:

  • Refactored the CI setup code into a composite action (e370e44)
  • Ensured all committed text files have \n newlines (b7fef60)

Review guidance

Highly recommend reviewing one commit at a time! (Also notice the commit message of the Ruff commit, which mentions that pretty much all the changes to the .py files were made automatically by Ruff.)

Also try running make lint locally and provide feedback here on how it works for you 🙂

Checklist

(If any of the points are not relevant, mark them as checked, so that it's easy to see which points you've handled or not)

  • I've run makemigrations, makemessages and compilemessages
  • I've written tests that fail without these changes (if relevant/possible)
  • I've manually tested the website UI with different device layouts
    • Most common is to test with typical screen sizes for mobile (320-425 px), tablet (768 px) and desktop (1024+ px), which can easily be done with your browser's dev tools
  • I've manually tested with different users locally
    • This can be e.g. anonymous users (i.e. not being logged in), "normal" non-member users, members of different committees, and superusers
  • I've made sure that my code conforms to the code style guides
    • It's not intended that you read through this whole document, but that you get yourself an overview over its contents, and that you use it as a reference guide / checklist while taking a second look at your code before opening a pull request
  • I've attempted to minimize the number of common code smells
    • See the comment for the previous checkbox
  • I've added documentation
    • E.g. comments, docstrings, or in the README
  • I've added my changes to the "Unreleased" section of the changelog, together with a link to this PR
    • Mainly the changes that are of particular interest to users and/or developers, if any
  • I've added a "Deployment notes" section above and labelled the PR with has-deployment-notes
    • ...if anything out of the ordinary should be done when deploying these changes to the server (e.g. adding/removing an environment variable, manually creating/changing some objects, running a management command, etc.)
  • I've structured my commits reasonably

@make-bot make-bot bot added this to web Oct 23, 2025
@make-bot make-bot bot moved this to Ready for Review in web Oct 23, 2025
@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 85.31157% with 99 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.01%. Comparing base (6d6d7b3) to head (b7fef60).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/checkin/views.py 21.87% 25 Missing ⚠️
src/checkin/api/views.py 0.00% 14 Missing ⚠️
src/docs/forms.py 46.15% 7 Missing ⚠️
src/internal/forms.py 71.42% 6 Missing ⚠️
src/internal/views.py 90.90% 5 Missing ⚠️
src/make_queue/forms/course.py 70.58% 5 Missing ⚠️
src/card/views.py 0.00% 4 Missing ⚠️
src/checkin/local_scanner.py 0.00% 4 Missing ⚠️
src/dataporten/social.py 55.55% 4 Missing ⚠️
src/dataporten/views.py 42.85% 4 Missing ⚠️
... and 10 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #778      +/-   ##
==========================================
- Coverage   88.04%   88.01%   -0.04%     
==========================================
  Files         153      153              
  Lines        6225     6224       -1     
==========================================
- Hits         5481     5478       -3     
- Misses        744      746       +2     
Files with missing lines Coverage Δ
src/announcements/admin.py 100.00% <100.00%> (ø)
src/announcements/apps.py 100.00% <100.00%> (ø)
src/announcements/forms.py 100.00% <100.00%> (ø)
src/announcements/models.py 93.93% <100.00%> (ø)
src/announcements/urls.py 100.00% <100.00%> (ø)
src/announcements/views.py 100.00% <100.00%> (ø)
src/card/apps.py 100.00% <100.00%> (ø)
src/card/formfields.py 93.33% <100.00%> (ø)
src/card/modelfields.py 100.00% <100.00%> (ø)
src/card/utils.py 46.15% <ø> (ø)
... and 84 more

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@TheStrgamer TheStrgamer left a comment

Choose a reason for hiding this comment

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

Works as intended when i run it.

Also added a CI linting job to check that all our pre-commit hooks have
been run.

Also removed the "Global" -> "Empty/blank lines" section in
`CONTRIBUTING.md`, as the first, most important part is now enforced by
the `end-of-file-fixer` pre-commit hook, and the second part doesn't
really bring that much value.
Pretty much all changes in the `.py` files were made by Ruff, but a few
of them were made manually by me to made some wrapped lines more
readable.

Also removed a few now-redundant entries in `CONTRIBUTING.md`.
@ddabble ddabble force-pushed the cleanup/ruff-format branch from 7ff0306 to b7fef60 Compare December 8, 2025 08:02
@ddabble ddabble merged commit 6b38ee7 into main Dec 8, 2025
11 checks passed
@ddabble ddabble deleted the cleanup/ruff-format branch December 8, 2025 08:23
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in web Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants