From 646b2dcf802c6e1420c4b5071002045a1f0b0ef1 Mon Sep 17 00:00:00 2001 From: sax Date: Sun, 9 Sep 2018 23:42:58 +0200 Subject: [PATCH] list and pre-commit support --- .pre-commit-config.yaml | 43 +++++++++++++++++++++++++++++++ .tx/config | 1 - AUTHORS | 2 +- MANIFEST.in | 2 ++ Pipfile | 1 + docs/_ext/version.py | 4 +-- docs/api.rst | 1 - docs/changes.rst | 2 -- docs/conf.py | 10 ++++--- docs/faq.rst | 2 -- docs/fields.rst | 2 -- docs/globals.txt | 1 - docs/install.rst | 1 - docs/middleware.rst | 1 - manage.py | 4 ++- setup.cfg | 1 - setup.py | 1 + src/concurrency/admin.py | 1 - src/concurrency/compat.py | 7 +++-- src/concurrency/config.py | 6 +++-- tests/conftest.py | 1 + tests/demoapp/demo/util.py | 2 +- tests/test_admin_actions.py | 1 - tests/test_admin_edit.py | 2 +- tests/test_admin_list_editable.py | 2 +- tests/test_api.py | 2 +- tests/test_base.py | 2 +- tests/test_checks.py | 2 +- tests/test_command.py | 5 ++-- tests/test_conditional.py | 2 +- tests/test_config.py | 3 ++- tests/test_core.py | 3 +-- tests/test_enable_disable.py | 2 +- tests/test_forms.py | 2 +- tests/test_issues.py | 8 +++--- tests/test_loaddata_dumpdata.py | 4 +-- tests/test_manager.py | 1 - tests/test_middleware.py | 2 +- tests/test_reversion.py | 5 ++-- tests/test_templatetags.py | 1 - tests/test_threads.py | 2 +- tests/test_triggers.py | 2 +- tests/test_triggerversionfield.py | 2 +- tests/test_utils.py | 4 +-- tox.ini | 2 -- 45 files changed, 98 insertions(+), 59 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..303344b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +exclude: '^$' +fail_fast: false +repos: +- repo: local + hooks: + - id: isort + args: + - -rc + - src/ + - tests/ + name: isort + entry: isort + language: system + types: [python] + - id: check-manifest + name: check-manifest + entry: check-manifest + language: system + types: [python] + files: '^$' + always_run: true + +- repo: git://github.com/pre-commit/pre-commit-hooks + rev: v1.4.0 + hooks: + - id: debug-statements + exclude: manage.py + - id: end-of-file-fixer + - id: flake8 + exclude: docs/ + args: + - src/ + - tests/ + - id: check-merge-conflict + - id: check-case-conflict +# - id: name-tests-test +# - id: trailing-whitespace +# - id: requirements-txt-fixer +# files: requirements-dev.txt +#- repo: git://github.com/asottile/reorder_python_imports +# rev: v1.0.1 +# hooks: +# - id: reorder-python-imports diff --git a/.tx/config b/.tx/config index 76b6432..f4edfd7 100644 --- a/.tx/config +++ b/.tx/config @@ -6,4 +6,3 @@ source_lang = en [main] host = https://www.transifex.com type = PO - diff --git a/AUTHORS b/AUTHORS index 03ffd93..e98088a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1 @@ -Stefano Apostolico \ No newline at end of file +Stefano Apostolico diff --git a/MANIFEST.in b/MANIFEST.in index 59287a1..e8fbbfa 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -8,9 +8,11 @@ include tox.ini include *.py exclude Makefile +exclude Pipfile exclude .editorconfig exclude .tx exclude .pyc +exclude .pre-commit-config.yaml recursive-exclude .tx * recursive-exclude __pycache__ * diff --git a/Pipfile b/Pipfile index 9365404..cce0829 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ name = "pypi" [packages] django = "==2.1" +pre-commit = "*" [dev-packages] django-reversion = "*" diff --git a/docs/_ext/version.py b/docs/_ext/version.py index 70e6b8e..5f12f2e 100644 --- a/docs/_ext/version.py +++ b/docs/_ext/version.py @@ -1,8 +1,8 @@ import re + +from docutils.parsers.rst import Directive, directives from sphinx import addnodes, roles from sphinx.util.console import bold -from docutils.parsers.rst import Directive, directives - # RE for option descriptions without a '--' prefix from sphinx.writers.html import HTMLTranslator diff --git a/docs/api.rst b/docs/api.rst index 8585938..eae43dd 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -291,4 +291,3 @@ extends :class:`django.core.signing.Signer`. If you want change your Signer you :file:`settings.py` :: CONCURRENCY_FIELD_SIGNER = "myapp.mysigner.DummySigner" - diff --git a/docs/changes.rst b/docs/changes.rst index ad1c258..3aee716 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -13,5 +13,3 @@ This section lists the biggest changes done on each release. :local: .. include:: ../CHANGES - - diff --git a/docs/conf.py b/docs/conf.py index 7f2ecaf..c16454c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,13 +1,17 @@ # -*- coding: utf-8 -*- -import sys, os +import os +import sys + +from django.conf import settings + +import concurrency + src = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'src')) sys.path.insert(0, src) -from django.conf import settings settings.configure() -import concurrency # os.environ['DJANGO_SETTINGS_MODULE']= 'django.conf.global_settings' diff --git a/docs/faq.rst b/docs/faq.rst index 258d680..97c8a31 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -68,5 +68,3 @@ anyway this will NOT raise any error .. note:: `TriggerVersionField` will be always updated - - diff --git a/docs/fields.rst b/docs/fields.rst index 13a2784..aaa3d2a 100644 --- a/docs/fields.rst +++ b/docs/fields.rst @@ -103,5 +103,3 @@ the scope of the concurrency checks. class ConcurrencyMeta: check_fields = ('username',) - - diff --git a/docs/globals.txt b/docs/globals.txt index 313f9d1..9c2836b 100644 --- a/docs/globals.txt +++ b/docs/globals.txt @@ -10,4 +10,3 @@ .. |concurrency| replace:: **django-concurrency** .. |pkg| replace:: dja .. |version| replace:: 0.1 - diff --git a/docs/install.rst b/docs/install.rst index aabf7d3..7aa7856 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -41,4 +41,3 @@ How to run the tests $ pip install tox $ tox - diff --git a/docs/middleware.rst b/docs/middleware.rst index a15f969..fc97e99 100644 --- a/docs/middleware.rst +++ b/docs/middleware.rst @@ -120,4 +120,3 @@ use :class:`concurrency.forms.ConcurrentForm` class MyModelAdmin(ConcurrentModelAdmin): form = forms.ModelForm # overrides default ConcurrentForm - diff --git a/manage.py b/manage.py index 7029d14..256f83d 100755 --- a/manage.py +++ b/manage.py @@ -1,5 +1,7 @@ #!/usr/bin/env python -import os, sys +import os +import sys + here = os.path.abspath(os.path.join(os.path.dirname(__file__))) rel = lambda *args: os.path.join(here, *args) diff --git a/setup.cfg b/setup.cfg index 6d5e59a..1725c71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,4 +27,3 @@ universal=1 [devpi:upload] formats = bdist_wheel,sdist.tgz - diff --git a/setup.py b/setup.py index 446af7f..37a9468 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import ast import os import re + from setuptools import find_packages, setup from setuptools.command.test import test as TestCommand diff --git a/src/concurrency/admin.py b/src/concurrency/admin.py index 0aafefc..4288304 100644 --- a/src/concurrency/admin.py +++ b/src/concurrency/admin.py @@ -5,7 +5,6 @@ import re from functools import reduce -import django from django.contrib import admin, messages from django.contrib.admin import helpers from django.core.checks import Error diff --git a/src/concurrency/compat.py b/src/concurrency/compat.py index 590d35e..3c3e4ae 100644 --- a/src/concurrency/compat.py +++ b/src/concurrency/compat.py @@ -1,13 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals -import django +# import django # if django.VERSION <(1,9): # from django.template.base import TemplateDoesNotExist # else: -from django.template.exceptions import TemplateDoesNotExist # noqa - django 1.9 - +from django.template.exceptions import TemplateDoesNotExist # noqa # if django.VERSION <(1,9): # from django.core.urlresolvers import get_callable # noqa # else: -from django.urls.utils import get_callable +from django.urls.utils import get_callable # noqa diff --git a/src/concurrency/config.py b/src/concurrency/config.py index 47d0b06..ff1b45a 100644 --- a/src/concurrency/config.py +++ b/src/concurrency/config.py @@ -51,14 +51,16 @@ def _set_attr(self, prefix_name, value): name = prefix_name[len(self.prefix) + 1:] if name == 'IGNORE_DEFAULT': raise ImproperlyConfigured('IGNORE_DEFAULT has been removed in django-concurrency 1.5. ' - 'Use VERSION_FIELD_REQUIRED instead') + 'Use VERSION_FIELD_REQUIRED instead') elif name == 'CALLBACK': if isinstance(value, six.string_types): func = get_callable(value) elif callable(value): func = value else: - raise ImproperlyConfigured("{} is not a valid value for `CALLBACK`. It must be a callable or a fullpath to callable. ".format(value)) + raise ImproperlyConfigured( + "{} is not a valid value for `CALLBACK`. It must be a callable or a fullpath to callable. ".format( + value)) self._callback = func setattr(self, name, value) diff --git a/tests/conftest.py b/tests/conftest.py index 7e420dd..e1abfc5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import sys import django + import pytest py_impl = getattr(platform, 'python_implementation', lambda: None) diff --git a/tests/demoapp/demo/util.py b/tests/demoapp/demo/util.py index 3842cd9..2d704f9 100644 --- a/tests/demoapp/demo/util.py +++ b/tests/demoapp/demo/util.py @@ -3,9 +3,9 @@ from functools import partial, update_wrapper from itertools import count -import pytest from django import db +import pytest from demo.models import ( AutoIncConcurrentModel, ConcreteModel, CustomSaveModel, InheritedModel, ProxyModel, SimpleConcurrentModel, TriggerConcurrentModel diff --git a/tests/test_admin_actions.py b/tests/test_admin_actions.py index 30f61ae..8459017 100644 --- a/tests/test_admin_actions.py +++ b/tests/test_admin_actions.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import pytest - from demo.base import SENTINEL, AdminTestCase from demo.models import SimpleConcurrentModel from demo.util import unique_id diff --git a/tests/test_admin_edit.py b/tests/test_admin_edit.py index 3eaf81d..f9261bf 100644 --- a/tests/test_admin_edit.py +++ b/tests/test_admin_edit.py @@ -1,6 +1,6 @@ -import pytest from django.utils.translation import ugettext as _ +import pytest from demo.base import SENTINEL, AdminTestCase from demo.models import SimpleConcurrentModel from demo.util import nextname diff --git a/tests/test_admin_list_editable.py b/tests/test_admin_list_editable.py index 8b72f94..2d0d123 100644 --- a/tests/test_admin_list_editable.py +++ b/tests/test_admin_list_editable.py @@ -1,13 +1,13 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals -import pytest from django.contrib.admin.models import LogEntry from django.contrib.admin.sites import site from django.contrib.contenttypes.models import ContentType from django.db import transaction from django.utils.encoding import force_text +import pytest from demo.base import SENTINEL, AdminTestCase from demo.models import ListEditableConcurrentModel from demo.util import attributes, unique_id diff --git a/tests/test_api.py b/tests/test_api.py index 2829598..b10b028 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,6 +1,6 @@ -import pytest from django.contrib.auth.models import Group +import pytest from demo.models import SimpleConcurrentModel from demo.util import nextgroup, nextname diff --git a/tests/test_base.py b/tests/test_base.py index 7c4fe4f..8b39ff7 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,6 +1,6 @@ -import pytest from django.test import override_settings +import pytest from demo.util import concurrent_model, unique_id, with_all_models, with_std_models from concurrency.core import _set_version diff --git a/tests/test_checks.py b/tests/test_checks.py index 66a6af1..9cc4541 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -4,8 +4,8 @@ import logging import django -import pytest +import pytest from demo.models import TriggerConcurrentModel logger = logging.getLogger(__name__) diff --git a/tests/test_command.py b/tests/test_command.py index 8c53fb8..45237bd 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- import logging - -import pytest import six + from django.core.management import call_command + +import pytest from mock import Mock import concurrency.management.commands.triggers as command diff --git a/tests/test_conditional.py b/tests/test_conditional.py index a8bee9f..aa832c8 100644 --- a/tests/test_conditional.py +++ b/tests/test_conditional.py @@ -3,9 +3,9 @@ import logging -import pytest from django.contrib.auth.models import User +import pytest from demo.models import ( ConditionalVersionModel, ConditionalVersionModelSelfRelation, ConditionalVersionModelWithoutMeta, ThroughRelation diff --git a/tests/test_config.py b/tests/test_config.py index 2788e5e..1b0b1c0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,7 @@ -import pytest from django.core.exceptions import ImproperlyConfigured +import pytest + from concurrency.config import AppSettings from concurrency.utils import fqn diff --git a/tests/test_core.py b/tests/test_core.py index 59dcd27..730c535 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2,11 +2,11 @@ from __future__ import absolute_import, unicode_literals import pytest +from demo.models import SimpleConcurrentModel from concurrency.core import _select_lock from concurrency.exceptions import RecordModifiedError from concurrency.utils import refetch -from demo.models import SimpleConcurrentModel @pytest.mark.django_db @@ -20,4 +20,3 @@ def test_select_lock(settings): settings.CONCURRENCY_ENABLED = False _select_lock(s1) - diff --git a/tests/test_enable_disable.py b/tests/test_enable_disable.py index 4d5d03c..9856737 100644 --- a/tests/test_enable_disable.py +++ b/tests/test_enable_disable.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -import pytest from django.contrib.auth.models import User from django.test.utils import override_settings +import pytest from demo.models import AutoIncConcurrentModel, SimpleConcurrentModel from demo.util import nextname diff --git a/tests/test_forms.py b/tests/test_forms.py index bbc6783..6650b1b 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,4 +1,3 @@ -import pytest from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation from django.forms.models import modelform_factory from django.forms.widgets import HiddenInput, TextInput @@ -7,6 +6,7 @@ from django.utils.encoding import smart_str from django.utils.translation import ugettext as _ +import pytest from demo.models import Issue3TestModel, SimpleConcurrentModel from concurrency.exceptions import VersionError diff --git a/tests/test_issues.py b/tests/test_issues.py index b345ec2..9f6feca 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -2,7 +2,6 @@ import re import django -import pytest from django.contrib.admin.sites import site from django.contrib.auth.models import User from django.core.management import call_command @@ -13,15 +12,18 @@ from django.test.testcases import SimpleTestCase from django.utils.encoding import force_text -from concurrency.exceptions import RecordModifiedError +import pytest from conftest import skipIfDjangoVersion from demo.admin import ActionsModelAdmin, admin_register from demo.base import AdminTestCase -from demo.models import ListEditableConcurrentModel, ReversionConcurrentModel, SimpleConcurrentModel +from demo.models import ( + ListEditableConcurrentModel, ReversionConcurrentModel, SimpleConcurrentModel +) from demo.util import attributes, unique_id from concurrency.admin import ConcurrentModelAdmin from concurrency.config import CONCURRENCY_LIST_EDITABLE_POLICY_SILENT +from concurrency.exceptions import RecordModifiedError from concurrency.forms import ConcurrentForm from concurrency.templatetags.concurrency import identity from concurrency.utils import refetch diff --git a/tests/test_loaddata_dumpdata.py b/tests/test_loaddata_dumpdata.py index 093391c..f5c24f4 100644 --- a/tests/test_loaddata_dumpdata.py +++ b/tests/test_loaddata_dumpdata.py @@ -4,11 +4,11 @@ import json import logging import os +from six import StringIO -import pytest from django.core.management import call_command -from six import StringIO +import pytest from demo.models import SimpleConcurrentModel logger = logging.getLogger(__name__) diff --git a/tests/test_manager.py b/tests/test_manager.py index f450971..35b196c 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1,5 +1,4 @@ import pytest - from demo.models import ( AutoIncConcurrentModel, ConcreteModel, CustomSaveModel, InheritedModel, ProxyModel, SimpleConcurrentModel diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 4179925..74701a7 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -import mock from django.conf import settings from django.contrib.admin.sites import site from django.http import HttpRequest from django.test.utils import override_settings +import mock from demo.base import AdminTestCase from demo.models import SimpleConcurrentModel from demo.util import DELETE_ATTRIBUTE, attributes, unique_id diff --git a/tests/test_reversion.py b/tests/test_reversion.py index b6825e1..2526311 100644 --- a/tests/test_reversion.py +++ b/tests/test_reversion.py @@ -2,10 +2,9 @@ from __future__ import absolute_import, unicode_literals import pytest -from reversion.models import Version - from demo.models import ReversionConcurrentModel -from reversion import revisions, add_to_revision, set_comment +from reversion import add_to_revision, revisions, set_comment +from reversion.models import Version try: from django.core.urlresolvers import reverse diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 1297345..f88ecbf 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -4,7 +4,6 @@ import logging import pytest - from demo.models import SimpleConcurrentModel from concurrency.templatetags.concurrency import identity, is_version, version diff --git a/tests/test_threads.py b/tests/test_threads.py index 4e51161..96b7f74 100644 --- a/tests/test_threads.py +++ b/tests/test_threads.py @@ -1,7 +1,7 @@ -import pytest from django import db from django.db import transaction +import pytest from conftest import skippypy from demo.models import TriggerConcurrentModel from demo.util import concurrently diff --git a/tests/test_triggers.py b/tests/test_triggers.py index 71cadb3..979c233 100644 --- a/tests/test_triggers.py +++ b/tests/test_triggers.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- import logging -import pytest from django.db import connections +import pytest from demo.models import DropTriggerConcurrentModel, TriggerConcurrentModel # noqa from concurrency.triggers import drop_triggers, factory, get_triggers diff --git a/tests/test_triggerversionfield.py b/tests/test_triggerversionfield.py index dfbf410..285d0b8 100644 --- a/tests/test_triggerversionfield.py +++ b/tests/test_triggerversionfield.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from django.core.signals import request_started -from django.db import IntegrityError, connections, connection +from django.db import IntegrityError, connection, connections import mock import pytest diff --git a/tests/test_utils.py b/tests/test_utils.py index 77b3ae1..efc6b99 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,13 +3,13 @@ import logging -import pytest from django.test import TestCase +import pytest from demo.models import SimpleConcurrentModel import concurrency.fields -from concurrency.utils import ConcurrencyTestMixin, fqn, deprecated +from concurrency.utils import ConcurrencyTestMixin, deprecated, fqn logger = logging.getLogger(__name__) diff --git a/tox.ini b/tox.ini index 0c6078c..6dc61b6 100644 --- a/tox.ini +++ b/tox.ini @@ -87,5 +87,3 @@ commands = commands = mkdir -p {toxinidir}/~build/docs pipenv run sphinx-build -aE docs/ {toxinidir}/~build/docs - -