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

Add GitHub Actions for ruff for Python linting #5082

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Python linter (Ruff)

on: [pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@491342200cdd1cf4d5132a30ddc546b3b5bc531b
with:
args: 'check --preview'
changed-files: true
1 change: 1 addition & 0 deletions dependencies/pip/dev_requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pytest
pytest-cov
pytest-django
pytest-env
ruff


# Kobocat
Expand Down
2 changes: 2 additions & 0 deletions dependencies/pip/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ rpds-py==0.18.0
# referencing
rsa==4.9
# via google-auth
ruff==0.6.2
# via -r dependencies/pip/dev_requirements.in
s3transfer==0.10.1
# via boto3
sentinels==1.0.0
Expand Down
27 changes: 24 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,42 @@
# verbose = true
line-length = 80
skip-string-normalization = true

[tool.isort]
profile = "black"
known_first_party = "kobo"
no_lines_before = ["LOCALFOLDER"]

[tool.ruff]
line-length = 80
line-length = 88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making the line-length longer for ruff than for black?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we use an extra buffer of ~10 characters. If your line is 85 characters and you don't want to break it for 5 characters, we don't want the linter to complain about it. Moreover, that's the default configuration (see https://docs.astral.sh/ruff/configuration/)

 # Same as Black.
line-length = 88
indent-width = 4

I would leave black as-is to format with 80 characters. Does not mean the dev cannot bring a line up to 88 characters after Black formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PyCharm, I added two visual limits. One at 80 (kinda soft-limit) and the other one at 90 (kind hard-limit).

Screenshot 2024-08-28 at 09 36 09

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still a little confused. Why do we have black at 80 characters then?

[tool.ruff.format]
quote-style = "single" # Preserve is coming soon to ruff
[tool.ruff.lint]
# Enable ruff isort
extend-select = ["I"]
extend-select = [
"I", # Enable ruff isort
"Q", # Flake quotes
"E", # pycodestyle, some needs `--preview` to be enable
"N", # PEP-8 naming convention
"UP026", # deprecated mock
"UP034", # extraneous-parentheses
"UP039", # Unnecessary parentheses after class definition
"W1", # Indentation warning
"W292", # no newline at end of file
"T20", # (p)print found
]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "single" # To prefer single quotes over double quote
multiline-quotes = "double"
docstring-quotes = "double"
[tool.ruff.lint.isort]
known-first-party = ["kobo"]

[tool.flake8]
inline-quotes = "single"
multiline-quotes = "double"
docstring-quotes = "double"
max-line-length = 88

[tool.pytest.ini_options]
testpaths = [
'kobo',
Expand Down
Loading