Skip to content

Commit b6b5878

Browse files
graingertauvipypre-commit-ci[bot]
authored
enable pre-commit (celery#223)
* enable pre-commit * manual flake8 fixes * configure black isort profile * apply isort * apply pyupgrade * apply isort * Update t/conftest.py Co-authored-by: Thomas Grainger <[email protected]> * Update t/conftest.py Co-authored-by: Thomas Grainger <[email protected]> * Update t/conftest.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Asif Saif Uddin <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 67b8158 commit b6b5878

29 files changed

+107
-102
lines changed

.pre-commit-config.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v2.21.2
4+
hooks:
5+
- id: pyupgrade
6+
args: ["--py36-plus"]
7+
8+
- repo: https://gitlab.com/pycqa/flake8
9+
rev: 3.9.2
10+
hooks:
11+
- id: flake8
12+
13+
- repo: https://github.com/asottile/yesqa
14+
rev: v1.2.3
15+
hooks:
16+
- id: yesqa
17+
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v4.0.1
20+
hooks:
21+
- id: check-merge-conflict
22+
- id: check-toml
23+
- id: check-yaml
24+
- id: mixed-line-ending
25+
26+
- repo: https://github.com/pycqa/isort
27+
rev: 5.9.2
28+
hooks:
29+
- id: isort

django_celery_results/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# :license: BSD (3 Clause), see LICENSE for more details.
55

66
import re
7-
87
from collections import namedtuple
98

109
import django

django_celery_results/admin.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Result Task Admin interface."""
22

3-
from django.contrib import admin
4-
53
from django.conf import settings
4+
from django.contrib import admin
65
from django.utils.translation import gettext_lazy as _
76

87
try:
@@ -11,7 +10,7 @@
1110
ALLOW_EDITS = False
1211
pass
1312

14-
from .models import TaskResult, GroupResult
13+
from .models import GroupResult, TaskResult
1514

1615

1716
class TaskResultAdmin(admin.ModelAdmin):
@@ -59,9 +58,9 @@ def get_readonly_fields(self, request, obj=None):
5958
if ALLOW_EDITS:
6059
return self.readonly_fields
6160
else:
62-
return list(set(
63-
[field.name for field in self.opts.local_fields]
64-
))
61+
return list({
62+
field.name for field in self.opts.local_fields
63+
})
6564

6665

6766
admin.site.register(TaskResult, TaskResultAdmin)

django_celery_results/backends/cache.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Celery cache backend using the Django Cache Framework."""
22

3-
from django.core.cache import cache as default_cache, caches
4-
53
from celery.backends.base import KeyValueStoreBackend
4+
from django.core.cache import cache as default_cache
5+
from django.core.cache import caches
66

77

88
class CacheBackend(KeyValueStoreBackend):

django_celery_results/backends/database.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from celery import maybe_signature
55
from celery.backends.base import BaseDictBackend
66
from celery.exceptions import ChordError
7-
from celery.result import allow_join_result, result_from_tuple, GroupResult
8-
from celery.utils.serialization import b64encode, b64decode
7+
from celery.result import GroupResult, allow_join_result, result_from_tuple
98
from celery.utils.log import get_logger
10-
from kombu.exceptions import DecodeError
9+
from celery.utils.serialization import b64decode, b64encode
1110
from django.db import transaction
11+
from kombu.exceptions import DecodeError
1212

13-
from ..models import TaskResult, ChordCounter, GroupResult as GroupResultModel
14-
13+
from ..models import ChordCounter
14+
from ..models import GroupResult as GroupResultModel
15+
from ..models import TaskResult
1516

1617
logger = get_logger(__name__)
1718

@@ -224,7 +225,7 @@ def trigger_callback(app, callback, group_result):
224225
except Exception as exc: # pylint: disable=broad-except
225226
try:
226227
culprit = next(group_result._failed_join_report())
227-
reason = "Dependency {0.id} raised {1!r}".format(culprit, exc)
228+
reason = f"Dependency {culprit.id} raised {exc!r}"
228229
except StopIteration:
229230
reason = repr(exc)
230231
logger.exception("Chord %r raised: %r", group_result.id, exc)
@@ -235,5 +236,5 @@ def trigger_callback(app, callback, group_result):
235236
except Exception as exc: # pylint: disable=broad-except
236237
logger.exception("Chord %r raised: %r", group_result.id, exc)
237238
app.backend.chord_error_from_stack(
238-
callback, exc=ChordError("Callback error: {0!r}".format(exc))
239+
callback, exc=ChordError(f"Callback error: {exc!r}")
239240
)

django_celery_results/managers.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
"""Model managers."""
22

33
import warnings
4-
54
from functools import wraps
65
from itertools import count
76

87
from celery.utils.time import maybe_timedelta
9-
10-
from django.db import connections, router, transaction
11-
from django.db import models
128
from django.conf import settings
9+
from django.db import connections, models, router, transaction
1310

1411
from .utils import now
1512

django_celery_results/migrations/0001_initial.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, unicode_literals
3-
41
from django.conf import settings
52
from django.db import migrations, models
63

django_celery_results/migrations/0002_add_task_name_args_kwargs.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.9.1 on 2017-10-26 16:06
3-
from __future__ import absolute_import, unicode_literals
42

53
from django.db import migrations, models
64

django_celery_results/migrations/0003_auto_20181106_1101.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 2.1 on 2018-11-06 11:01
3-
from __future__ import absolute_import, unicode_literals
42

53
from django.db import migrations
64

django_celery_results/migrations/0004_auto_20190516_0412.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.11.20 on 2019-05-16 04:12
32

43
# this file is auto-generated so don't do flake8 on it
54
# flake8: noqa
65

7-
from __future__ import absolute_import, unicode_literals
86

97
from django.conf import settings
108
from django.db import migrations, models

django_celery_results/migrations/0005_taskresult_worker.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.11.22 on 2019-07-24 15:38
32

43
# this file is auto-generated so don't do flake8 on it
54
# flake8: noqa
65

7-
from __future__ import absolute_import, unicode_literals
86

97
from django.db import migrations, models
108

django_celery_results/migrations/0006_taskresult_date_created.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 2.2.4 on 2019-08-21 19:53
32

43
# this file is auto-generated so don't do flake8 on it
54
# flake8: noqa
65

7-
from __future__ import absolute_import, unicode_literals
86

9-
from django.db import migrations, models
107
import django.utils.timezone
8+
from django.db import migrations, models
119

1210

1311
def copy_date_done_to_date_created(apps, schema_editor):

django_celery_results/migrations/0007_remove_taskresult_hidden.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 2.2.6 on 2019-10-27 11:29
32

43
# this file is auto-generated so don't do flake8 on it
54
# flake8: noqa
65

7-
from __future__ import absolute_import, unicode_literals
86

97
from django.db import migrations
108

django_celery_results/migrations/0008_chordcounter.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Generated by Django 3.0.6 on 2020-05-12 12:05
2-
from __future__ import unicode_literals, absolute_import
32

43
from django.conf import settings
54
from django.db import migrations, models

django_celery_results/migrations/0010_remove_duplicate_indices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
to not add the duplicates for new installs
88
"""
99

10-
from django.db import migrations, DatabaseError
10+
from django.db import DatabaseError, migrations
1111

1212

1313
class TryRemoveIndex(migrations.RemoveIndex):

django_celery_results/models.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import json
44

5+
from celery import states
6+
from celery.result import GroupResult as CeleryGroupResult
7+
from celery.result import result_from_tuple
58
from django.conf import settings
69
from django.db import models
710
from django.utils.translation import gettext_lazy as _
811

9-
from celery import states
10-
from celery.result import result_from_tuple
11-
from celery.result import GroupResult as CeleryGroupResult
12-
1312
from . import managers
1413

1514
ALL_STATES = sorted(states.ALL_STATES)
@@ -206,7 +205,7 @@ def as_dict(self):
206205
}
207206

208207
def __str__(self):
209-
return '<Group: {0.group_id}>'.format(self)
208+
return f'<Group: {self.group_id}>'
210209

211210
objects = managers.GroupResultManager()
212211

django_celery_results/views.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Views."""
2-
from django.http import JsonResponse
3-
42
from celery import states
53
from celery.result import AsyncResult, GroupResult
64
from celery.utils import get_full_cls_name
5+
from django.http import JsonResponse
76
from kombu.utils.encoding import safe_repr
87

98

docs/conf.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import absolute_import, unicode_literals
3-
41
import os
52

63
from sphinx_celery import conf

manage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
from __future__ import absolute_import, unicode_literals
2+
33
import os
44
import sys
55

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ match-dir = [^migrations]
1717

1818
[wheel]
1919
universal = 1
20+
21+
[isort]
22+
profile=black

setup.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

3+
import codecs
44
import os
55
import re
66
import sys
7-
import codecs
87

98
import setuptools
109
import setuptools.command.test
@@ -18,7 +17,7 @@ def _pyimp():
1817

1918
NAME = 'django_celery_results'
2019

21-
E_UNSUPPORTED_PYTHON = '%s 1.0 requires %%s %%s or later!' % (NAME,)
20+
E_UNSUPPORTED_PYTHON = f'{NAME} 1.0 requires %s %s or later!'
2221

2322
PYIMP = _pyimp()
2423
PY36_OR_LESS = sys.version_info < (3, 6)
@@ -65,6 +64,7 @@ def add_default(m):
6564
def add_doc(m):
6665
return (('doc', m.groups()[0]),)
6766

67+
6868
pats = {re_meta: add_default,
6969
re_doc: add_doc}
7070
here = os.path.abspath(os.path.dirname(__file__))
@@ -81,8 +81,8 @@ def add_doc(m):
8181
# -*- Installation Requires -*-
8282

8383

84-
def strip_comments(l):
85-
return l.split('#', 1)[0].strip()
84+
def strip_comments(line):
85+
return line.split('#', 1)[0].strip()
8686

8787

8888
def _pip_requirement(req):
@@ -93,22 +93,24 @@ def _pip_requirement(req):
9393

9494

9595
def _reqs(*f):
96-
return [
97-
_pip_requirement(r) for r in (
98-
strip_comments(l) for l in open(
99-
os.path.join(os.getcwd(), 'requirements', *f)).readlines()
100-
) if r]
96+
with open(os.path.join(os.getcwd(), 'requirements', *f)) as fp:
97+
return [
98+
_pip_requirement(r)
99+
for r in (strip_comments(line) for line in fp)
100+
if r
101+
]
101102

102103

103104
def reqs(*f):
104105
return [req for subreq in _reqs(*f) for req in subreq]
105106

106107
# -*- Long Description -*-
107108

109+
108110
if os.path.exists('README.rst'):
109111
long_description = codecs.open('README.rst', 'r', 'utf-8').read()
110112
else:
111-
long_description = 'See http://pypi.python.org/pypi/%s' % (NAME,)
113+
long_description = f'See http://pypi.python.org/pypi/{NAME}'
112114

113115
# -*- %%% -*-
114116

@@ -124,6 +126,7 @@ def run_tests(self):
124126
import pytest
125127
sys.exit(pytest.main(self.pytest_args))
126128

129+
127130
setuptools.setup(
128131
name=NAME,
129132
packages=setuptools.find_packages(exclude=['ez_setup', 't', 't.*']),

t/conftest.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
# we have to import the pytest plugin fixtures here,
44
# in case user did not do the `python setup.py develop` yet,
55
# that installs the pytest plugin into the setuptools registry.
6-
from celery.contrib.pytest import (celery_app, celery_enable_logging,
7-
celery_parameters, depends_on_current_app,
8-
celery_config, use_celery_app_trap)
6+
from celery.contrib.pytest import (
7+
celery_app,
8+
celery_config,
9+
celery_enable_logging,
10+
celery_parameters,
11+
depends_on_current_app,
12+
use_celery_app_trap,
13+
)
914
from celery.contrib.testing.app import TestApp, Trap
1015

1116
# Tricks flake8 into silencing redefining fixtures warnings.

t/integration/benchmark_models.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import pytest
2-
3-
from datetime import timedelta
41
import time
2+
from datetime import timedelta
53

6-
from django.test import TransactionTestCase
7-
4+
import pytest
85
from celery import uuid
6+
from django.test import TransactionTestCase
97

108
from django_celery_results.models import TaskResult
119
from django_celery_results.utils import now

t/proj/settings.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import os
1414
import sys
1515

16-
1716
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1817
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1918
sys.path.insert(0, os.path.abspath(os.path.join(BASE_DIR, os.pardir)))

0 commit comments

Comments
 (0)