chore/fix: re-enable linting for backend
Description
This PR re-enables linting for the backend (disabled 4 months ago in https://github.com/open-webui/open-webui/pull/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. KeyboardInterrupts, 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 to ruff (they're 99.x% compatible, but ruff 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 what requirements.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 of ruff; technically, Ruff should be a development-time dependency only, but there is no requirements-dev.txt or similar and Black was in the runtime deps, so I didn't change that.
Changelog Entry
Changed
- Python code is now linted and formatted using Ruff.
@cheahjs Please let me know if there's any interest in getting this merged (I see there's adjacent work in https://github.com/open-webui/open-webui/pull/2182) so I know whether or not to keep rebasing this.
Rebased on dev. cc @cheahjs @tjbck
@tjbck Rebased once more on dev.
@tjbck have we reached a decision on this?
Rebased.
Looks like the frontend build CI is broken on dev anyway.