Skip to content

GitHub Actions: Lint Python code with ruff #6996

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Jul 10, 2025

https://github.com/astral-sh/ruff

Why ruff?

If ruff is a superset of flake8, why doesn't it complain about the rules in this repo's .flake8 file?

ardupilot_wiki/.flake8

Lines 1 to 16 in 703219c

[flake8]
ignore =
# H301: one import per line
H301,
# H306: imports not in alphabetical order (time, os)
H306,
# E226: missing whitespace around arithmetic operator
E226,
# E261 at least two spaces before inline comment
E261,
# W504 line break after binary operator
W504,
# E203 whitespace before ':'
E203,
# E221 multiple spaces before operator
E221

Most of these are whitespace errors that are better handled by a code formatter like ruff format or psf/black, so ruff check ignores them.

https://github.com/astral-sh/ruff

Why ruff?
* mavlink/mavlink#2303 (comment)

If ruff is a superset of flake8, why doesn't it complain about the rules in this repo's `.flake8`?
https://github.com/ArduPilot/ardupilot_wiki/blob/703219ca36a9f8df9741f19810965aa7da2ea8f7/.flake8#L1-L16

Most of these are whitespace errors that are better handled by a code formatter like ruff format or psf/black, so ruff check ignores them.
@Hwurzburg Hwurzburg requested a review from peterbarker July 10, 2025 11:56
@peterbarker
Copy link
Contributor

Query: do we need to use random isolation tools like pipx to do this stuff?

If I'm thinking right this actually increases the changes of the job failing as it installs the tool from the internet as part of running pipx here - in a CI job that's evrey time we run the job. Th jobs on the main repository fail not infrequently because of external dependencies (including failed connections to github.com resources themselves!) so I don't know if this is an appropriate way of running the tool. I'm certainly not growing fonder of restarting CI jobs that have failed with "Connection refused" to some random thing on the internet.

Installing it on the runner image would seem to be a better option.

@khancyr hard to install ruff on the image we use for testing the Wiki?

@cclauss
Copy link
Contributor Author

cclauss commented Jul 11, 2025

GitHub Actions docs: https://docs.github.com/en/actions/how-tos/use-cases-and-examples/building-and-testing/building-and-testing-python#using-ruff-to-lint-andor-format-code

I do not see how pipx is random. It is created by the same team that creates pip. It simplifies the running of CLI tools and scripts that contain PEP 723 inline metadata headers. GitHub Actions pre-installs it because installing into a venv is the recommendation for Python projects, and because isolated venv's avoid dependency conflicts.

It really does not matter for ruff because it contains no Python code, it is a Rust executable that is installed via pip, pipx, or uvx because it is trying to install trivially in a Python world.

I see lots of failing tests on PRs here, but I have not seen any caused by GitHub Actions servers being unable to reach PyPI. Whether pip installing or pipx installing, if the GitHub Actions servers are unable to see PyPI then the job is going to fail.

@Hwurzburg
Copy link
Contributor

@khancyr ping

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.

3 participants