Skip to content

Commit

Permalink
Used isort to sort imports (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
smithdc1 authored Nov 29, 2020
1 parent b0be6e2 commit 79ff8ea
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ messages: init

compilemessages: init
$(PYTHON) translations.py compile

format:
isort model_utils tests setup.py
2 changes: 1 addition & 1 deletion model_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion model_utils/fields.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 2 additions & 4 deletions model_utils/managers.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
11 changes: 4 additions & 7 deletions model_utils/models.py
Original file line number Diff line number Diff line change
@@ -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()


Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ all_files = 1
[tool:pytest]
django_find_project = false
DJANGO_SETTINGS_MODULE = tests.settings

[isort]
profile = black
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from setuptools import setup, find_packages

from setuptools import find_packages, setup


def long_desc(root_path):
Expand Down
2 changes: 1 addition & 1 deletion tests/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from model_utils.managers import SoftDeletableQuerySet, SoftDeletableManager
from model_utils.managers import SoftDeletableManager, SoftDeletableQuerySet


class CustomSoftDeleteQuerySet(SoftDeletableQuerySet):
Expand Down
19 changes: 5 additions & 14 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
22 changes: 18 additions & 4 deletions tests/test_fields/test_field_tracker.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down
5 changes: 2 additions & 3 deletions tests/test_fields/test_monitor_field.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from datetime import datetime

from freezegun import freeze_time

from django.test import TestCase
from freezegun import freeze_time

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):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_fields/test_status_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from model_utils.fields import StatusField
from tests.models import (
Article, StatusFieldDefaultFilled, StatusFieldDefaultNotFilled,
Article,
StatusFieldChoicesName,
StatusFieldDefaultFilled,
StatusFieldDefaultNotFilled,
)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_inheritance_iterable.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 7 additions & 3 deletions tests/test_managers/test_inheritance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
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,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_managers/test_join_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase

from tests.models import JoinItemForeignKey, BoxJoinModel
from tests.models import BoxJoinModel, JoinItemForeignKey


class JoinManagerTest(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_managers/test_status_manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_savesignalhandling_model.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_models/test_status_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from datetime import datetime

from freezegun import freeze_time

from django.test.testcases import TestCase
from freezegun import freeze_time

from tests.models import Status, StatusPlainTuple, StatusCustomManager
from tests.models import Status, StatusCustomManager, StatusPlainTuple


class StatusModelTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_timeframed_model.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models/test_uuid_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase

from tests.models import CustomUUIDModel, CustomNotPrimaryUUIDModel
from tests.models import CustomNotPrimaryUUIDModel, CustomUUIDModel


class UUIDFieldTests(TestCase):
Expand Down
11 changes: 9 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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

0 comments on commit 79ff8ea

Please sign in to comment.