diff --git a/CHANGES.rst b/CHANGES.rst index d1f0525..184a644 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,10 @@ CHANGES ======= +Next release (tbc) +------------------ +- Applied `isort` to codebase (Refs GH-#402) + 4.1.0 (2020-11-29) ------------------ - Update InheritanceQuerySetMixin to avoid querying too much tables diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 17c28b3..433912f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -76,3 +76,13 @@ To run tox and generate a coverage report (in ``htmlcov`` directory):: **Please note**: Before a pull request can be merged, all tests must pass and code/branch coverage in tests must be 100%. + +Code Formatting +--------------- +We make use of `isort`_ to sort imports. + +.. _isort: https://pycqa.github.io/isort/ + +Once it is installed you can make sure the code is properly formatted by running:: + + make format diff --git a/Makefile b/Makefile index 798188c..79a693a 100644 --- a/Makefile +++ b/Makefile @@ -30,3 +30,6 @@ messages: init compilemessages: init $(PYTHON) translations.py compile + +format: + isort model_utils tests setup.py diff --git a/model_utils/__init__.py b/model_utils/__init__.py index 766f756..691cf5c 100644 --- a/model_utils/__init__.py +++ b/model_utils/__init__.py @@ -1,4 +1,4 @@ -from pkg_resources import get_distribution, DistributionNotFound +from pkg_resources import DistributionNotFound, get_distribution from .choices import Choices # noqa:F401 from .tracker import FieldTracker, ModelTracker # noqa:F401 diff --git a/model_utils/fields.py b/model_utils/fields.py index a82c64c..c390cce 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -1,7 +1,8 @@ import uuid -from django.db import models + from django.conf import settings from django.core.exceptions import ValidationError +from django.db import models from django.utils.timezone import now DEFAULT_CHOICES_NAME = 'STATUS' diff --git a/model_utils/managers.py b/model_utils/managers.py index a835845..8204480 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -1,12 +1,10 @@ import warnings from django.core.exceptions import ObjectDoesNotExist -from django.db import connection -from django.db import models +from django.db import connection, models from django.db.models.constants import LOOKUP_SEP from django.db.models.fields.related import OneToOneField, OneToOneRel -from django.db.models.query import ModelIterable -from django.db.models.query import QuerySet +from django.db.models.query import ModelIterable, QuerySet from django.db.models.sql.datastructures import Join diff --git a/model_utils/models.py b/model_utils/models.py index da7e879..95320b0 100644 --- a/model_utils/models.py +++ b/model_utils/models.py @@ -1,21 +1,18 @@ from django.core.exceptions import ImproperlyConfigured -from django.db import models, transaction, router +from django.db import models, router, transaction +from django.db.models.functions import Now from django.db.models.signals import post_save, pre_save from django.utils.translation import gettext_lazy as _ from model_utils.fields import ( AutoCreatedField, AutoLastModifiedField, - StatusField, MonitorField, + StatusField, UUIDField, ) -from model_utils.managers import ( - QueryManager, - SoftDeletableManager, -) +from model_utils.managers import QueryManager, SoftDeletableManager -from django.db.models.functions import Now now = Now() diff --git a/setup.cfg b/setup.cfg index ca117cd..89ca82e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,6 @@ all_files = 1 [tool:pytest] django_find_project = false DJANGO_SETTINGS_MODULE = tests.settings + +[isort] +profile = black diff --git a/setup.py b/setup.py index f15f968..48aef8f 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import os -from setuptools import setup, find_packages + +from setuptools import find_packages, setup def long_desc(root_path): diff --git a/tests/managers.py b/tests/managers.py index 43b9860..03ea473 100644 --- a/tests/managers.py +++ b/tests/managers.py @@ -1,4 +1,4 @@ -from model_utils.managers import SoftDeletableQuerySet, SoftDeletableManager +from model_utils.managers import SoftDeletableManager, SoftDeletableQuerySet class CustomSoftDeleteQuerySet(SoftDeletableQuerySet): diff --git a/tests/models.py b/tests/models.py index e5a2970..4323c4d 100644 --- a/tests/models.py +++ b/tests/models.py @@ -1,32 +1,23 @@ import django from django.db import models -from django.db.models.query_utils import DeferredAttribute from django.db.models import Manager +from django.db.models.query_utils import DeferredAttribute from django.utils.translation import gettext_lazy as _ from model_utils import Choices -from model_utils.fields import ( - SplitField, - MonitorField, - StatusField, - UUIDField, -) -from model_utils.managers import ( - QueryManager, - InheritanceManager, - JoinManagerMixin -) +from model_utils.fields import MonitorField, SplitField, StatusField, UUIDField +from model_utils.managers import InheritanceManager, JoinManagerMixin, QueryManager from model_utils.models import ( + SaveSignalHandlingModel, SoftDeletableModel, StatusModel, TimeFramedModel, TimeStampedModel, UUIDModel, - SaveSignalHandlingModel, ) +from model_utils.tracker import FieldTracker, ModelTracker from tests.fields import MutableField from tests.managers import CustomSoftDeleteManager -from model_utils.tracker import FieldTracker, ModelTracker class InheritanceManagerTestRelated(models.Model): diff --git a/tests/test_fields/test_field_tracker.py b/tests/test_fields/test_field_tracker.py index 44449ba..164b9b7 100644 --- a/tests/test_fields/test_field_tracker.py +++ b/tests/test_fields/test_field_tracker.py @@ -1,13 +1,27 @@ from unittest import skip + +from django.core.cache import cache from django.core.exceptions import FieldError from django.test import TestCase -from django.core.cache import cache + from model_utils import FieldTracker from model_utils.tracker import DescriptorWrapper from tests.models import ( - Tracked, TrackedFK, InheritedTrackedFK, TrackedNotDefault, TrackedNonFieldAttr, TrackedMultiple, - InheritedTracked, TrackedFileField, TrackedAbstract, TrackerTimeStamped, - ModelTracked, ModelTrackedFK, ModelTrackedNotDefault, ModelTrackedMultiple, InheritedModelTracked, + InheritedModelTracked, + InheritedTracked, + InheritedTrackedFK, + ModelTracked, + ModelTrackedFK, + ModelTrackedMultiple, + ModelTrackedNotDefault, + Tracked, + TrackedAbstract, + TrackedFileField, + TrackedFK, + TrackedMultiple, + TrackedNonFieldAttr, + TrackedNotDefault, + TrackerTimeStamped, ) diff --git a/tests/test_fields/test_monitor_field.py b/tests/test_fields/test_monitor_field.py index b3f3522..cca6762 100644 --- a/tests/test_fields/test_monitor_field.py +++ b/tests/test_fields/test_monitor_field.py @@ -1,11 +1,10 @@ from datetime import datetime +from django.test import TestCase from freezegun import freeze_time -from django.test import TestCase - from model_utils.fields import MonitorField -from tests.models import Monitored, MonitorWhen, MonitorWhenEmpty, DoubleMonitored +from tests.models import DoubleMonitored, Monitored, MonitorWhen, MonitorWhenEmpty class MonitorFieldTests(TestCase): diff --git a/tests/test_fields/test_status_field.py b/tests/test_fields/test_status_field.py index a09e2b9..ab250c6 100644 --- a/tests/test_fields/test_status_field.py +++ b/tests/test_fields/test_status_field.py @@ -2,8 +2,10 @@ from django.test import TestCase from model_utils.fields import StatusField from tests.models import ( - Article, StatusFieldDefaultFilled, StatusFieldDefaultNotFilled, + Article, StatusFieldChoicesName, + StatusFieldDefaultFilled, + StatusFieldDefaultNotFilled, ) diff --git a/tests/test_inheritance_iterable.py b/tests/test_inheritance_iterable.py index b9e8a0f..f4202e5 100644 --- a/tests/test_inheritance_iterable.py +++ b/tests/test_inheritance_iterable.py @@ -1,7 +1,7 @@ -from django.test import TestCase from django.db.models import Prefetch +from django.test import TestCase -from tests.models import InheritanceManagerTestParent, InheritanceManagerTestChild1 +from tests.models import InheritanceManagerTestChild1, InheritanceManagerTestParent class InheritanceIterableTest(TestCase): diff --git a/tests/test_managers/test_inheritance_manager.py b/tests/test_managers/test_inheritance_manager.py index f9b5250..102c6dd 100644 --- a/tests/test_managers/test_inheritance_manager.py +++ b/tests/test_managers/test_inheritance_manager.py @@ -2,11 +2,15 @@ from django.db import models from django.test import TestCase from tests.models import ( - InheritanceManagerTestRelated, InheritanceManagerTestGrandChild1, - InheritanceManagerTestGrandChild1_2, InheritanceManagerTestParent, InheritanceManagerTestChild1, - InheritanceManagerTestChild2, TimeFrame, InheritanceManagerTestChild3, + InheritanceManagerTestChild2, + InheritanceManagerTestChild3, InheritanceManagerTestChild4, + InheritanceManagerTestGrandChild1, + InheritanceManagerTestGrandChild1_2, + InheritanceManagerTestParent, + InheritanceManagerTestRelated, + TimeFrame, ) diff --git a/tests/test_managers/test_join_manager.py b/tests/test_managers/test_join_manager.py index 1437f6f..3b8a4c2 100644 --- a/tests/test_managers/test_join_manager.py +++ b/tests/test_managers/test_join_manager.py @@ -1,6 +1,6 @@ from django.test import TestCase -from tests.models import JoinItemForeignKey, BoxJoinModel +from tests.models import BoxJoinModel, JoinItemForeignKey class JoinManagerTest(TestCase): diff --git a/tests/test_managers/test_status_manager.py b/tests/test_managers/test_status_manager.py index e7fe144..106881a 100644 --- a/tests/test_managers/test_status_manager.py +++ b/tests/test_managers/test_status_manager.py @@ -1,5 +1,5 @@ -from django.db import models from django.core.exceptions import ImproperlyConfigured +from django.db import models from django.test import TestCase from model_utils.managers import QueryManager diff --git a/tests/test_models/test_savesignalhandling_model.py b/tests/test_models/test_savesignalhandling_model.py index fbe9d81..946da36 100644 --- a/tests/test_models/test_savesignalhandling_model.py +++ b/tests/test_models/test_savesignalhandling_model.py @@ -1,8 +1,8 @@ +from django.db.models.signals import post_save, pre_save from django.test import TestCase from tests.models import SaveSignalHandlingTestModel -from tests.signals import pre_save_test, post_save_test -from django.db.models.signals import pre_save, post_save +from tests.signals import post_save_test, pre_save_test class SaveSignalHandlingModelTests(TestCase): diff --git a/tests/test_models/test_status_model.py b/tests/test_models/test_status_model.py index 818d6cf..2e31143 100644 --- a/tests/test_models/test_status_model.py +++ b/tests/test_models/test_status_model.py @@ -1,10 +1,9 @@ from datetime import datetime +from django.test.testcases import TestCase from freezegun import freeze_time -from django.test.testcases import TestCase - -from tests.models import Status, StatusPlainTuple, StatusCustomManager +from tests.models import Status, StatusCustomManager, StatusPlainTuple class StatusModelTests(TestCase): diff --git a/tests/test_models/test_timeframed_model.py b/tests/test_models/test_timeframed_model.py index c51b9e5..3038828 100644 --- a/tests/test_models/test_timeframed_model.py +++ b/tests/test_models/test_timeframed_model.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta -from django.db import models from django.core.exceptions import ImproperlyConfigured +from django.db import models from django.test import TestCase from model_utils.managers import QueryManager diff --git a/tests/test_models/test_uuid_model.py b/tests/test_models/test_uuid_model.py index 3ce9f91..3c7663d 100644 --- a/tests/test_models/test_uuid_model.py +++ b/tests/test_models/test_uuid_model.py @@ -1,6 +1,6 @@ from django.test import TestCase -from tests.models import CustomUUIDModel, CustomNotPrimaryUUIDModel +from tests.models import CustomNotPrimaryUUIDModel, CustomUUIDModel class UUIDFieldTests(TestCase): diff --git a/tox.ini b/tox.ini index cee8e64..db33619 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,13 @@ [tox] envlist = py{36,37,38,39}-dj{22,30,31,master} - flake8 + flake8, isort [gh-actions] python = 3.6: py36 3.7: py37 - 3.8: py38, flake8 + 3.8: py38, flake8, isort 3.9: py39 [testenv] @@ -46,3 +46,10 @@ ignore = W503 ; line break before binary operator E402 ; module level import not at top of file E501 ; line too long + +[testenv:isort] +basepython = python3.8 +deps = isort +commands = + isort model_utils tests setup.py --check-only --diff +skip_install = True