Skip to content

Commit

Permalink
Merge pull request #164 from DakaraProject/ruff
Browse files Browse the repository at this point in the history
setup ruff as a flake8 replacement
  • Loading branch information
Neraste authored Mar 16, 2024
2 parents 05b6fdf + d4a64c8 commit 7b916ae
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ jobs:
- name: Run style checks
run: python -m black . --check

- name: Run PEP8 style checks
run: python -m flake8
- name: Run ruff linter
run: python -m ruff check .
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ repos:
entry: black . --check
language: system
pass_filenames: false
- id: flake8-check
name: Check PEP8
entry: flake8
- id: ruff-check
name: Run ruff linter
entry: ruff check .
language: system
pass_filenames: false
5 changes: 5 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
line-length = 88

[lint]
select = ["E", "F", "W", "B"]
ignore = []
32 changes: 18 additions & 14 deletions dakara_server/internal/cache_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,8 @@ def _manage_on_delete_fields(self):
cache model. Instead, we execute the on-delete action with the
`pre_delete` signal of the related field.
"""
for field in self.model._meta.concrete_fields:
# only consider foreign key fields with the callable attribute
# "cache_on_delete"
if not isinstance(field, models.ForeignKey):
continue

on_delete = getattr(field, "cache_on_delete", None)

if not callable(on_delete):
raise TypeError("cache_on_delete must be callable")

def handle_decorator(field):
# register the handle to the pre_delete signal
@receiver(
pre_delete,
Expand All @@ -59,10 +50,23 @@ def _manage_on_delete_fields(self):
)
def handle(sender, **kwargs):
instance = kwargs.get("instance")
on_delete(instance, self)
field.cache_on_delete(instance, self)

return handle

for field in self.model._meta.concrete_fields:
# only consider foreign key fields with the callable attribute
# "cache_on_delete"
if not isinstance(field, models.ForeignKey):
continue

on_delete = getattr(field, "cache_on_delete", None)

if not callable(on_delete):
raise TypeError("cache_on_delete must be callable")

# store the handle
self._on_delete_funcs[field.name] = handle
self._on_delete_funcs[field.name] = handle_decorator(field)

@contextmanager
def _access_store(self):
Expand Down Expand Up @@ -233,7 +237,7 @@ def __new__(cls, name, bases, attrs):
# create and connect cache manager
manager = CacheManager()
manager._connect(new_class)
setattr(new_class, "cache", manager)
new_class.cache = manager

return new_class

Expand Down Expand Up @@ -279,7 +283,7 @@ class CacheOnDeleteMixin:
"""

def __init__(self, to, on_delete, *args, **kwargs):
super().__init__(to, on_delete=models.DO_NOTHING, *args, **kwargs)
super().__init__(to, *args, on_delete=models.DO_NOTHING, **kwargs)
self.cache_on_delete = on_delete


Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pytest-cov>=4.0.0,<4.1.0
pytest-django>=4.5.2,<4.6.0
pytest-mock>=3.10.0,<3.11.0
pytest>=7.2.0,<7.3.0
ruff>=0.3.0,<0.4.0
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[flake8]
max-line-length = 88
ignore = E203, W503

[coverage:run]
omit = */tests/*, */conftest.py

Expand Down

0 comments on commit 7b916ae

Please sign in to comment.