Skip to content

Commit 9680259

Browse files
authored
Merge pull request #2497 from bagerard/switch_to_isort
Switch to isort + add few pre-commit hooks
2 parents f0fad6d + 49a4d23 commit 9680259

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+136
-87
lines changed

.github/workflows/github-actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ jobs:
140140
- name: publish pypi
141141
uses: pypa/gh-action-pypi-publish@master
142142
with:
143-
password: ${{ secrets.pypi_token }}
143+
password: ${{ secrets.pypi_token }}

.pre-commit-config.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
fail_fast: false
22
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v3.4.0
5+
hooks:
6+
- id: check-merge-conflict
7+
- id: debug-statements
8+
- id: trailing-whitespace
9+
- id: end-of-file-fixer
310
- repo: https://github.com/ambv/black
411
rev: 20.8b1
512
hooks:
613
- id: black
714
- repo: https://gitlab.com/pycqa/flake8
8-
rev: 3.8.4
15+
rev: 3.9.0
916
hooks:
1017
- id: flake8
11-
additional_dependencies:
12-
- flake8-import-order
1318
- repo: https://github.com/asottile/pyupgrade
14-
rev: v2.7.4
19+
rev: v2.11.0
1520
hooks:
1621
- id: pyupgrade
1722
args: [--py36-plus]
23+
- repo: https://github.com/pycqa/isort
24+
rev: 5.8.0
25+
hooks:
26+
- id: isort

CONTRIBUTING.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Travis runs the tests against the main Python 3.x versions.
3535
Style Guide
3636
-----------
3737

38-
MongoEngine's codebase is formatted with `black <https://github.com/python/black>`_, other tools like
39-
flake8 are also used. Those tools will run as part of the CI and will fail in case the code is not formatted properly.
38+
MongoEngine's codebase is auto-formatted with `black <https://github.com/python/black>`_, imports are ordered with `isort <https://pycqa.github.io/isort/>`_
39+
and other tools like flake8 are also used. Those tools will run as part of the CI and will fail in case the code is not formatted properly.
4040

4141
To install all development tools, simply run the following commands:
4242

@@ -58,6 +58,10 @@ To enable ``pre-commit`` simply run:
5858
See the ``.pre-commit-config.yaml`` configuration file for more information
5959
on how it works.
6060

61+
pre-commit will now run upon every commit and will reject anything that doesn't comply.
62+
63+
You can also run all the checks with ``pre-commit run -a``, this is what is used in the CI.
64+
6165
Testing
6266
-------
6367

docs/guide/validation.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,3 @@ the validation and cleaning of a document when you call :meth:`~mongoengine.docu
120120
Person(age=1000).save(validate=False)
121121
person = Person.objects.first()
122122
assert person.age == 1000
123-

mongoengine/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Import submodules so that we can expose their __all__
2-
from mongoengine import connection
3-
from mongoengine import document
4-
from mongoengine import errors
5-
from mongoengine import fields
6-
from mongoengine import queryset
7-
from mongoengine import signals
2+
from mongoengine import (
3+
connection,
4+
document,
5+
errors,
6+
fields,
7+
queryset,
8+
signals,
9+
)
810

911
# Import everything from each submodule so that it can be accessed via
1012
# mongoengine, e.g. instead of `from mongoengine.connection import connect`,
@@ -17,7 +19,6 @@
1719
from mongoengine.queryset import * # noqa: F401
1820
from mongoengine.signals import * # noqa: F401
1921

20-
2122
__all__ = (
2223
list(document.__all__)
2324
+ list(fields.__all__)

mongoengine/base/document.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import copy
2-
32
import numbers
43
from functools import partial
54

6-
from bson import DBRef, ObjectId, SON, json_util
75
import pymongo
6+
from bson import SON, DBRef, ObjectId, json_util
87

98
from mongoengine import signals
109
from mongoengine.base.common import get_document

mongoengine/base/fields.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import operator
22
import weakref
33

4-
from bson import DBRef, ObjectId, SON
54
import pymongo
5+
from bson import SON, DBRef, ObjectId
66

77
from mongoengine.base.common import UPDATE_OPERATORS
8-
from mongoengine.base.datastructures import BaseDict, BaseList, EmbeddedDocumentList
8+
from mongoengine.base.datastructures import (
9+
BaseDict,
10+
BaseList,
11+
EmbeddedDocumentList,
12+
)
913
from mongoengine.common import _import_class
1014
from mongoengine.errors import DeprecatedError, ValidationError
1115

mongoengine/base/metaclasses.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import warnings
33

44
from mongoengine.base.common import _document_registry
5-
from mongoengine.base.fields import BaseField, ComplexBaseField, ObjectIdField
5+
from mongoengine.base.fields import (
6+
BaseField,
7+
ComplexBaseField,
8+
ObjectIdField,
9+
)
610
from mongoengine.common import _import_class
711
from mongoengine.errors import InvalidDocumentError
812
from mongoengine.queryset import (
@@ -12,7 +16,6 @@
1216
QuerySetManager,
1317
)
1418

15-
1619
__all__ = ("DocumentMetaclass", "TopLevelDocumentMetaclass")
1720

1821

mongoengine/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def register_connection(
217217

218218
def disconnect(alias=DEFAULT_CONNECTION_NAME):
219219
"""Close the connection with a given alias."""
220-
from mongoengine.base.common import _get_documents_by_db
221220
from mongoengine import Document
221+
from mongoengine.base.common import _get_documents_by_db
222222

223223
if alias in _connections:
224224
get_connection(alias=alias).close()

mongoengine/dereference.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from bson import DBRef, SON
1+
from bson import SON, DBRef
22

33
from mongoengine.base import (
44
BaseDict,
@@ -10,7 +10,12 @@
1010
from mongoengine.base.datastructures import LazyReference
1111
from mongoengine.connection import get_db
1212
from mongoengine.document import Document, EmbeddedDocument
13-
from mongoengine.fields import DictField, ListField, MapField, ReferenceField
13+
from mongoengine.fields import (
14+
DictField,
15+
ListField,
16+
MapField,
17+
ReferenceField,
18+
)
1419
from mongoengine.queryset import QuerySet
1520

1621

0 commit comments

Comments
 (0)