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

Replaced flake8 and isort with ruff #692

Merged
merged 16 commits into from
Nov 1, 2023
Merged
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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ jobs:
matrix:
tool:
- 'black'
- 'flake8'
- 'isort'
- 'ruff'
- 'mypy'

steps:
Expand Down
19 changes: 6 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,15 @@ repos:
- id: check-symlinks
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
# from readme - ruff with autofix must run before
# other formatters, such as black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: pyupgrade
- id: ruff
args: [ --fix, --exit-non-zero-on-fix , --show-fixes]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
139 changes: 139 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# https://beta.ruff.rs/docs/rules/
select = [
# rules from pyflakes
"F",

# rules from pycodestyle
"E", "W",

# rules from mccabe
"C90",

# rules from isort
"I",

# rules from pyupgrade
"UP",

# rules from flake8-2020
"YTT",

# rules from flake8-annotations
# "ANN",

# rules from flake8-bandit
"S",

# rules from flake8-blind-except
"BLE",

# rules from flake8-boolean-trap
# TODO: "FBT",

# rules from flake8-bugbear
"B",

# rules from flake8-builtins
"A",

# rules from flake8-commas
"COM",

# rules from flake8-comprehensions
"C4",

# rules from flake8-datetimez
# TODO: "DTZ",

# rules from flake8-debugger
"T10",

# rules from flake8-django
"DJ",

# rules from flake8-errmsg
"EM",

# rules from flake8-executable
"EXE",

# rules from flake8-implicit-str-concat
"ISC",

# rules from flake8-import-conventions
"ICN",

# rules from flake8-logging-format
"G",

# rules from flake8-no-pep420
"INP",

# rules from flake8-pie
# TODO: "PIE",

# rules from flake8-print
"T20",

# rules from flake8-pyi
"PYI",

# rules from flake8-pytest-style
# TODO: "PT",

# rules from flake8-raise
"RSE",

# rules from flake8-return
"RET",

# rules from flake8-self
# TODO: "SLF",

# rules from flake8-simplify
"SIM",

# rules from flake8-tidy-imports
"TID",

# rules from flake8-type-checking
"TCH",

# rules from flake8-gettext
"INT",

# rules from flake8-unused-arguments
# TODO: "ARG",

# rules from flake8-use-pathlib
"PTH",

# removes unused noqa comments
"RUF100",
]

ignore = [
"COM812", # missing trailing comma, covered by black
"ANN101", # ignore missing type annotation in self parameter
"S311", # ignore Standard pseudo-random generators because they are not used for cryptographic purposes
]

fix = true

# TODO: enable this when python3.6 will stop being supported,
# from april 2024 https://docs.djangoproject.com/en/4.2/releases/3.2/
#target-version = "py36"

[flake8-tidy-imports]
## Disallow all relative imports.
ban-relative-imports = "all"

[per-file-ignores]
# ignore assert statements in tests
"tests/*.py" = ["S101"]

# ignore SECRET_KEY in settings files in tests
"tests/settings/*.py" = ["S105"]

# pickle is used on purpose and its use is discouraged
"django_redis/serializers/pickle.py" = ["S301"]
1 change: 1 addition & 0 deletions changelog.d/692.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace isort and flake8 with ruff
5 changes: 3 additions & 2 deletions django_redis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

cache = caches[alias]

error_message = "This backend does not support this feature"

Check warning on line 14 in django_redis/__init__.py

View check run for this annotation

Codecov / codecov/patch

django_redis/__init__.py#L14

Added line #L14 was not covered by tests
if not hasattr(cache, "client"):
raise NotImplementedError("This backend does not support this feature")
raise NotImplementedError(error_message)

Check warning on line 16 in django_redis/__init__.py

View check run for this annotation

Codecov / codecov/patch

django_redis/__init__.py#L16

Added line #L16 was not covered by tests

if not hasattr(cache.client, "get_client"):
raise NotImplementedError("This backend does not support this feature")
raise NotImplementedError(error_message)

Check warning on line 19 in django_redis/__init__.py

View check run for this annotation

Codecov / codecov/patch

django_redis/__init__.py#L19

Added line #L19 was not covered by tests

return cache.client.get_client(write)
6 changes: 3 additions & 3 deletions django_redis/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.core.cache.backends.base import BaseCache
from django.utils.module_loading import import_string

from .exceptions import ConnectionInterrupted
from django_redis.exceptions import ConnectionInterrupted

CONNECTION_INTERRUPTED = object()

Expand All @@ -33,7 +33,7 @@ def _decorator(self, *args, **kwargs):
self.logger.exception("Exception ignored")

return return_value
raise e.__cause__
raise e.__cause__ # noqa: B904

return _decorator

Expand Down Expand Up @@ -77,7 +77,7 @@ def client(self):
return self._client

@omit_exception
def set(self, *args, **kwargs):
def set(self, *args, **kwargs): # noqa: A003
return self.client.set(*args, **kwargs)

@omit_exception
Expand Down
8 changes: 4 additions & 4 deletions django_redis/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .default import DefaultClient
from .herd import HerdClient
from .sentinel import SentinelClient
from .sharded import ShardClient
from django_redis.client.default import DefaultClient
from django_redis.client.herd import HerdClient
from django_redis.client.sentinel import SentinelClient
from django_redis.client.sharded import ShardClient

__all__ = ["DefaultClient", "HerdClient", "SentinelClient", "ShardClient"]
Loading
Loading