Skip to content

Commit

Permalink
introduce Ruff as linter (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirosassa authored Jan 23, 2024
1 parent 2b33286 commit e1430ee
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 230 deletions.
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.

22 changes: 12 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,31 @@ 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]
# All the rules are listed on https://docs.astral.sh/ruff/rules/
extend-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"]

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

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

[tool.isort]
line_length = 160

[tool.mypy]
ignore_missing_imports = true

Expand Down
12 changes: 10 additions & 2 deletions test/test_redis_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

import fakeredis

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)
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,
)


class TestRedisClient(unittest.TestCase):
Expand Down
13 changes: 4 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{39,310,311,312},yapf,isort,flake8,mypy
envlist = py{39,310,311,312},yapf,ruff,mypy
isolated_build = true

[testenv]
Expand All @@ -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

0 comments on commit e1430ee

Please sign in to comment.