Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA: Use ruff instead of black + flake8 for formatting and linting #75

Merged
merged 6 commits into from
May 8, 2024

Conversation

hnez
Copy link
Member

@hnez hnez commented Apr 25, 2024

The main benefit of using ruff for us is that its rules are automatically consistent between the formatter and linter, while black and flake8 are often caught fighting about the correct formatting and need fine tuned configurations to prevent that.

This aligns with changes we have previously made to usbmuxctl and lxa-iobus.

TODO before merging:

@hnez hnez requested a review from SmithChart April 25, 2024 13:58
@hnez hnez force-pushed the ruff branch 3 times, most recently from e08d5c4 to bcf9ec0 Compare April 29, 2024 10:40
SmithChart
SmithChart previously approved these changes May 6, 2024
@hnez hnez dismissed SmithChart’s stale review May 6, 2024 06:07

The merge-base changed after approval.

hnez added 4 commits May 6, 2024 08:20
The main benefit of using ruff for us is that its rules are automatically
consistent between the formatter and linter, while black and flake8 are
often caught fighting about the correct formatting and need fine tuned
configurations to prevent that.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
Ruff and black are mostly compatible when it comes to their formatting
decisions, but there are still subtle differences.

Adapt the formatting to ruffs likings.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
The setup.py and fastentrypoints.py fixes are somewhat superfluous,
because they will go away with the switch to pyproject.toml,
but fix them anyways.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
@hnez
Copy link
Member Author

hnez commented May 6, 2024

Looks like ruff has learned a new lint in the meantime, making the CI job fail. I'll look into it.

@hnez hnez assigned hnez and unassigned SmithChart May 6, 2024
hnez added 2 commits May 8, 2024 09:38
Without this commit `ruff` complains about `i2c_gpio.py`:

  $ ruff
  usbsdmux/i2c_gpio.py:26:7: B024 `I2cGpio` is an abstract base class,
  but it has no abstract methods
  Found 1 error.

The python docs say the following about abstract base classes [1]:

  Abstract base classes complement duck-typing by providing a way to define
  interfaces when other techniques like hasattr() would be clumsy or subtly
  wrong (for example with magic methods). ABCs introduce virtual subclasses,
  which are classes that don’t inherit from a class but are still recognized
  by isinstance() and issubclass(); see the abc module documentation.

Which is not quite what `I2cGpio` is (a class that should never be used
by itself, but should always be subclassed to form a more specifig i²c
gpio expander class).

`ruff` is thus correct in complaining about the use of ABC here.
Fix the linter error by not inheriting from ABC.

[1]: https://docs.python.org/3/glossary.html#term-abstract-base-class

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
The SIM rule implements the rules provided by "flake8-simplify",
which describes itself as:

  A flake8 plugin that helps you simplify your code

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
@hnez
Copy link
Member Author

hnez commented May 8, 2024

Had a look and added bb17e2e, that removes the abc.ABC inheritance from I2cGpio.

@hnez hnez assigned SmithChart and unassigned hnez May 8, 2024
@SmithChart SmithChart merged commit b0c2903 into linux-automation:master May 8, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants