open-webui icon indicating copy to clipboard operation
open-webui copied to clipboard

chore/fix: re-enable linting for backend

Open akx opened this issue 1 year ago • 5 comments

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.

akx avatar May 07 '24 09:05 akx

@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.

akx avatar May 13 '24 07:05 akx

Rebased on dev. cc @cheahjs @tjbck

akx avatar May 14 '24 07:05 akx

@tjbck Rebased once more on dev.

akx avatar May 27 '24 14:05 akx

@tjbck have we reached a decision on this?

justinh-rahb avatar Jun 03 '24 15:06 justinh-rahb

Rebased.

Looks like the frontend build CI is broken on dev anyway.

akx avatar Jun 17 '24 12:06 akx