chore/fix: re-enable linting for backend #2041
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR re-enables linting for the backend (disabled 4 months ago in #368 because "too many issues") using Ruff, and fixes the issues it finds. Each commit should be fine to review in isolation, if this PR otherwise feels too large. Most of the cumulative diff is reordering imports.
I deliberately disabled some rules for the time being, though, with TODO notes that they really ought to be fixed; bare
try:except:
s for one are a bad habit, since they catch e.g.KeyboardInterrupt
s, so chances are the backend will ignore attempts of stopping it if the signal lands in a suitable place 😅Conversely, more rules could be added later.
It also switches formatting from
black
toruff
(they're 99.x% compatible, butruff
is a lot faster and formats some things in a neater way). The formatting actually found a couple of stray commas that inadvertently turned some logging statements into no-op 1-tuple constructions... 😄For CI, I made sure that the pinned versions from
requirements.txt
are used for Ruff – before this, CI could install a different version of Black than whatrequirements.txt
said.Testing
Since there is no test suite, all I really could do is test the app runs fine with these changes.
I ran under
coverage
(coverage run -m uvicorn main:app ...
), which gave me a coverage of about 49%.Dependencies
black
was dropped in favor ofruff
; technically, Ruff should be a development-time dependency only, but there is norequirements-dev.txt
or similar and Black was in the runtime deps, so I didn't change that.Changelog Entry
Changed