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

introduce Ruff as linter #345

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install poetry
poetry install
- name: Run yapf, isort, and flake8
- name: Run yapf, ruff, and mypy
run: |
poetry run tox -e yapf,isort,flake8,mypy
poetry run tox -e yapf,ruff,mypy
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies and build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
362 changes: 162 additions & 200 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,32 @@ redis = "*"
matplotlib = "*"

[tool.poetry.group.dev.dependencies]
pyproject-flake8 = "^6.1.0"
ruff = "*"
tox = "*"
moto = "*"
testfixtures = "*"
coverage = "*"
isort = "^5.7"
yapf = ">=0.32"
toml = "*"
lupa = "*"
fakeredis = "*"
mypy = "*"
types-redis = "*"

[tool.flake8]
[tool.ruff]
select = [
"E4", "E7", "E9", "F", # ruff's default. see https://docs.astral.sh/ruff/settings/#select
"B", # bugbear
"I" # isort
]

# B006: Do not use mutable data structures for argument defaults. They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.
# B008 Do not perform function calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time function call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.
# W503 line break before binary operator. We use W504(line break after binary operator) rather than W503
ignore = "B006,B008,W503"
max-line-length = 160
exclude = "venv/*,tox/*"
ignore = ["B006", "B008"]
Copy link
Collaborator Author

@hirosassa hirosassa Jan 21, 2024

Choose a reason for hiding this comment

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

W503 is not currently supported in ruff and it will not be implemented.
ref: astral-sh/ruff#4125

Is anyone who want to ignore this error?


line-length = 160
indent-width = 4
exclude = ["venv/*", "tox/*"]

[tool.yapf]
based_on_style = "pep8"
Expand All @@ -64,9 +70,6 @@ ignore_patterns = [
"examples/*"
]

[tool.isort]
line_length = 160

[tool.mypy]
ignore_missing_imports = true

Expand Down
2 changes: 1 addition & 1 deletion test/test_redis_lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import random
import random # noqa: I001
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This noqa is needed for line 8.
If I remove this noqa the line will fixed as following format by ruff

from gokart.redis_lock import (
    RedisClient,
    RedisParams,
    make_redis_key,
    make_redis_params,
    wrap_with_dump_lock,
    wrap_with_load_lock,
    wrap_with_remove_lock,
    wrap_with_run_lock,
)

To minimize diff in this PR I added it but it needs to discuss with this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

[imo] +1 to ruff's one, and +10 to accept default behaviors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

applied! e834ad0

import time
import unittest
from unittest.mock import MagicMock, patch
Expand Down
11 changes: 3 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ allowlist_externals = yapf
skip_install = true
commands = yapf -dr . {posargs}

[testenv:isort]
allowlist_externals = isort
[testenv:ruff]
allowlist_externals = ruff
skip_install = true
commands = isort -c gokart test {posargs}

[testenv:flake8]
allowlist_externals = pflake8
skip_install = true
commands = pflake8 gokart test {posargs}
commands = ruff check gokart test {posargs}

[testenv:mypy]
allowlist_externals = mypy
Expand Down