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

enable pre-commit #223

Merged
merged 10 commits into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.21.2
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: mixed-line-ending

- repo: https://github.com/pycqa/isort
rev: 5.9.2
hooks:
- id: isort
1 change: 0 additions & 1 deletion django_celery_results/__init__.py
Expand Up @@ -4,7 +4,6 @@
# :license: BSD (3 Clause), see LICENSE for more details.

import re

from collections import namedtuple

import django
Expand Down
11 changes: 5 additions & 6 deletions django_celery_results/admin.py
@@ -1,8 +1,7 @@
"""Result Task Admin interface."""

from django.contrib import admin

from django.conf import settings
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

try:
Expand All @@ -11,7 +10,7 @@
ALLOW_EDITS = False
pass

from .models import TaskResult, GroupResult
from .models import GroupResult, TaskResult


class TaskResultAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -59,9 +58,9 @@ def get_readonly_fields(self, request, obj=None):
if ALLOW_EDITS:
return self.readonly_fields
else:
return list(set(
[field.name for field in self.opts.local_fields]
))
return list({
field.name for field in self.opts.local_fields
})


admin.site.register(TaskResult, TaskResultAdmin)
Expand Down
4 changes: 2 additions & 2 deletions django_celery_results/backends/cache.py
@@ -1,8 +1,8 @@
"""Celery cache backend using the Django Cache Framework."""

from django.core.cache import cache as default_cache, caches

from celery.backends.base import KeyValueStoreBackend
from django.core.cache import cache as default_cache
from django.core.cache import caches


class CacheBackend(KeyValueStoreBackend):
Expand Down
15 changes: 8 additions & 7 deletions django_celery_results/backends/database.py
Expand Up @@ -4,14 +4,15 @@
from celery import maybe_signature
from celery.backends.base import BaseDictBackend
from celery.exceptions import ChordError
from celery.result import allow_join_result, result_from_tuple, GroupResult
from celery.utils.serialization import b64encode, b64decode
from celery.result import GroupResult, allow_join_result, result_from_tuple
from celery.utils.log import get_logger
from kombu.exceptions import DecodeError
from celery.utils.serialization import b64decode, b64encode
from django.db import transaction
from kombu.exceptions import DecodeError

from ..models import TaskResult, ChordCounter, GroupResult as GroupResultModel

from ..models import ChordCounter
from ..models import GroupResult as GroupResultModel
from ..models import TaskResult

logger = get_logger(__name__)

Expand Down Expand Up @@ -224,7 +225,7 @@ def trigger_callback(app, callback, group_result):
except Exception as exc: # pylint: disable=broad-except
try:
culprit = next(group_result._failed_join_report())
reason = "Dependency {0.id} raised {1!r}".format(culprit, exc)
reason = f"Dependency {culprit.id} raised {exc!r}"
except StopIteration:
reason = repr(exc)
logger.exception("Chord %r raised: %r", group_result.id, exc)
Expand All @@ -235,5 +236,5 @@ def trigger_callback(app, callback, group_result):
except Exception as exc: # pylint: disable=broad-except
logger.exception("Chord %r raised: %r", group_result.id, exc)
app.backend.chord_error_from_stack(
callback, exc=ChordError("Callback error: {0!r}".format(exc))
callback, exc=ChordError(f"Callback error: {exc!r}")
)
5 changes: 1 addition & 4 deletions django_celery_results/managers.py
@@ -1,15 +1,12 @@
"""Model managers."""

import warnings

from functools import wraps
from itertools import count

from celery.utils.time import maybe_timedelta

from django.db import connections, router, transaction
from django.db import models
from django.conf import settings
from django.db import connections, models, router, transaction

from .utils import now

Expand Down
3 changes: 0 additions & 3 deletions django_celery_results/migrations/0001_initial.py
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

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

Expand Down
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2017-10-26 16:06
from __future__ import absolute_import, unicode_literals

from django.db import migrations, models

Expand Down
2 changes: 0 additions & 2 deletions django_celery_results/migrations/0003_auto_20181106_1101.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 2.1 on 2018-11-06 11:01
from __future__ import absolute_import, unicode_literals

from django.db import migrations

Expand Down
2 changes: 0 additions & 2 deletions django_celery_results/migrations/0004_auto_20190516_0412.py
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-16 04:12

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

from __future__ import absolute_import, unicode_literals

from django.conf import settings
from django.db import migrations, models
Expand Down
2 changes: 0 additions & 2 deletions django_celery_results/migrations/0005_taskresult_worker.py
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.22 on 2019-07-24 15:38

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

from __future__ import absolute_import, unicode_literals

from django.db import migrations, models

Expand Down
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
# Generated by Django 2.2.4 on 2019-08-21 19:53

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

from __future__ import absolute_import, unicode_literals

from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


def copy_date_done_to_date_created(apps, schema_editor):
Expand Down
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Generated by Django 2.2.6 on 2019-10-27 11:29

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

from __future__ import absolute_import, unicode_literals

from django.db import migrations

Expand Down
1 change: 0 additions & 1 deletion django_celery_results/migrations/0008_chordcounter.py
@@ -1,5 +1,4 @@
# Generated by Django 3.0.6 on 2020-05-12 12:05
from __future__ import unicode_literals, absolute_import

from django.conf import settings
from django.db import migrations, models
Expand Down
Expand Up @@ -7,7 +7,7 @@
to not add the duplicates for new installs
"""

from django.db import migrations, DatabaseError
from django.db import DatabaseError, migrations


class TryRemoveIndex(migrations.RemoveIndex):
Expand Down
9 changes: 4 additions & 5 deletions django_celery_results/models.py
Expand Up @@ -2,14 +2,13 @@

import json

from celery import states
from celery.result import GroupResult as CeleryGroupResult
from celery.result import result_from_tuple
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _

from celery import states
from celery.result import result_from_tuple
from celery.result import GroupResult as CeleryGroupResult

from . import managers

ALL_STATES = sorted(states.ALL_STATES)
Expand Down Expand Up @@ -206,7 +205,7 @@ def as_dict(self):
}

def __str__(self):
return '<Group: {0.group_id}>'.format(self)
return f'<Group: {self.group_id}>'

objects = managers.GroupResultManager()

Expand Down
3 changes: 1 addition & 2 deletions django_celery_results/views.py
@@ -1,9 +1,8 @@
"""Views."""
from django.http import JsonResponse

from celery import states
from celery.result import AsyncResult, GroupResult
from celery.utils import get_full_cls_name
from django.http import JsonResponse
from kombu.utils.encoding import safe_repr


Expand Down
3 changes: 0 additions & 3 deletions docs/conf.py
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import os

from sphinx_celery import conf
Expand Down
2 changes: 1 addition & 1 deletion manage.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from __future__ import absolute_import, unicode_literals

import os
import sys

Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -17,3 +17,6 @@ match-dir = [^migrations]

[wheel]
universal = 1

[isort]
profile=black
25 changes: 14 additions & 11 deletions setup.py
@@ -1,10 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs
import os
import re
import sys
import codecs

import setuptools
import setuptools.command.test
Expand All @@ -18,7 +17,7 @@ def _pyimp():

NAME = 'django_celery_results'

E_UNSUPPORTED_PYTHON = '%s 1.0 requires %%s %%s or later!' % (NAME,)
E_UNSUPPORTED_PYTHON = f'{NAME} 1.0 requires %s %s or later!'

PYIMP = _pyimp()
PY36_OR_LESS = sys.version_info < (3, 6)
Expand Down Expand Up @@ -65,6 +64,7 @@ def add_default(m):
def add_doc(m):
return (('doc', m.groups()[0]),)


pats = {re_meta: add_default,
re_doc: add_doc}
here = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -81,8 +81,8 @@ def add_doc(m):
# -*- Installation Requires -*-


def strip_comments(l):
return l.split('#', 1)[0].strip()
def strip_comments(line):
return line.split('#', 1)[0].strip()


def _pip_requirement(req):
Expand All @@ -93,22 +93,24 @@ def _pip_requirement(req):


def _reqs(*f):
return [
_pip_requirement(r) for r in (
strip_comments(l) for l in open(
os.path.join(os.getcwd(), 'requirements', *f)).readlines()
) if r]
with open(os.path.join(os.getcwd(), 'requirements', *f)) as fp:
return [
_pip_requirement(r)
for r in (strip_comments(line) for line in fp)
if r
]


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

# -*- Long Description -*-


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

# -*- %%% -*-

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


setuptools.setup(
name=NAME,
packages=setuptools.find_packages(exclude=['ez_setup', 't', 't.*']),
Expand Down
11 changes: 8 additions & 3 deletions t/conftest.py
Expand Up @@ -3,9 +3,14 @@
# we have to import the pytest plugin fixtures here,
# in case user did not do the `python setup.py develop` yet,
# that installs the pytest plugin into the setuptools registry.
auvipy marked this conversation as resolved.
Show resolved Hide resolved
from celery.contrib.pytest import (celery_app, celery_enable_logging,
celery_parameters, depends_on_current_app,
celery_config, use_celery_app_trap)
from celery.contrib.pytest import (
celery_app,
celery_config,
celery_enable_logging,
celery_parameters,
depends_on_current_app,
use_celery_app_trap,
)
auvipy marked this conversation as resolved.
Show resolved Hide resolved
from celery.contrib.testing.app import TestApp, Trap

# Tricks flake8 into silencing redefining fixtures warnings.
Expand Down
8 changes: 3 additions & 5 deletions t/integration/benchmark_models.py
@@ -1,11 +1,9 @@
import pytest

from datetime import timedelta
import time
from datetime import timedelta

from django.test import TransactionTestCase

import pytest
from celery import uuid
from django.test import TransactionTestCase

from django_celery_results.models import TaskResult
from django_celery_results.utils import now
Expand Down
1 change: 0 additions & 1 deletion t/proj/settings.py
Expand Up @@ -13,7 +13,6 @@
import os
import sys


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.abspath(os.path.join(BASE_DIR, os.pardir)))
Expand Down