Skip to content

Commit

Permalink
Added changelog, added ruff to pre-commit and enabled some ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
WisdomPill committed Nov 1, 2023
1 parent ac98af3 commit 485268d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 41 deletions.
17 changes: 4 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@ repos:
- id: check-symlinks
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade

- 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
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: isort
- id: ruff
args: [ --fix, --exit-non-zero-on-fix , --show-fixes]
25 changes: 18 additions & 7 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# https://beta.ruff.rs/docs/rules/
select = [
# rules from pyflakes
# "F",
"F",

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

# rules from mccabe
# "C90",

# rules from isort
# "I",
"I",

# rules from pyupgrade
# "UP",
"UP",

# rules from flake8-2020
# "YTT",
"YTT",

# rules from flake8-annotations
# "ANN",

# rules from flake8-bandit
# "S",
"S",

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

# rules from flake8-boolean-trap
# TODO: "FBT",
Expand Down Expand Up @@ -116,6 +116,7 @@ select = [
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
Expand All @@ -127,3 +128,13 @@ fix = true
#[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"]

# picle 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
6 changes: 1 addition & 5 deletions django_redis/compressors/lz4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from lz4.frame import compress as _compress
from lz4.frame import decompress as _decompress

from ..exceptions import CompressorError
from .base import BaseCompressor


Expand All @@ -14,7 +13,4 @@ def compress(self, value: bytes) -> bytes:
return value

def decompress(self, value: bytes) -> bytes:
try:
return _decompress(value)
except Exception as e:
raise CompressorError(e)
return _decompress(value)

Check warning on line 16 in django_redis/compressors/lz4.py

View check run for this annotation

Codecov / codecov/patch

django_redis/compressors/lz4.py#L16

Added line #L16 was not covered by tests
12 changes: 8 additions & 4 deletions django_redis/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ def make_connection_params(self, url):

socket_timeout = self.options.get("SOCKET_TIMEOUT", None)
if socket_timeout:
assert isinstance(
if not isinstance(

Check warning on line 51 in django_redis/pool.py

View check run for this annotation

Codecov / codecov/patch

django_redis/pool.py#L51

Added line #L51 was not covered by tests
socket_timeout, (int, float)
), "Socket timeout should be float or integer"
):
raise ImproperlyConfigured("Socket timeout should be float or integer")

Check warning on line 54 in django_redis/pool.py

View check run for this annotation

Codecov / codecov/patch

django_redis/pool.py#L54

Added line #L54 was not covered by tests
kwargs["socket_timeout"] = socket_timeout

socket_connect_timeout = self.options.get("SOCKET_CONNECT_TIMEOUT", None)
if socket_connect_timeout:
assert isinstance(
if not isinstance(

Check warning on line 59 in django_redis/pool.py

View check run for this annotation

Codecov / codecov/patch

django_redis/pool.py#L59

Added line #L59 was not covered by tests
socket_connect_timeout, (int, float)
), "Socket connect timeout should be float or integer"
):
raise ImproperlyConfigured(
"Socket connect timeout should be float or integer"

Check warning on line 63 in django_redis/pool.py

View check run for this annotation

Codecov / codecov/patch

django_redis/pool.py#L62-L63

Added lines #L62 - L63 were not covered by tests
)
kwargs["socket_connect_timeout"] = socket_connect_timeout

return kwargs
Expand Down
13 changes: 1 addition & 12 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ omit =
precision = 1
skip_covered = true

[flake8]
ignore =
W503
W601
E203
max-line-length = 88

[isort]
profile = black
multi_line_output = 3

[tox:tox]
minversion = 3.15.0
envlist =
Expand All @@ -81,7 +70,7 @@ envlist =
python =
3.6: py36
3.7: py37
3.8: py38, black, flake8, isort, mypy
3.8: py38, black, ruff, mypy
3.9: py39
3.10: py310
3.11: py311
Expand Down

0 comments on commit 485268d

Please sign in to comment.