diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 0000000000..46234f41bd
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,2 @@
+# Initial pre-commit reformat
+b1d76c8ef4dd8fd364168c53b5c081b6d053d7b6
diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml
new file mode 100644
index 0000000000..187545944f
--- /dev/null
+++ b/.github/workflows/test-python.yml
@@ -0,0 +1,40 @@
+name: Python Tests
+
+on:
+ push:
+ pull_request:
+
+jobs:
+
+ pre-commit:
+ name: pre-commit
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions/setup-python@v2
+ - uses: pre-commit/action@v2.0.0
+ with:
+ extra_args: --all-files --hook-stage=manual
+
+ build:
+ # supercharge/mongodb-github-action requires containers so we don't test other platforms
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-20.04]
+ python-version: ["3.6", "3.10", "pypy-3.8"]
+ name: CPython ${{ matrix.python-version }}-${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v2
+ - name: Setup Python
+ uses: actions/setup-python@v2
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Start MongoDB
+ uses: supercharge/mongodb-github-action@1.7.0
+ with:
+ mongodb-version: 4.4
+ - name: Run tests
+ run: |
+ python setup.py test
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000000..39062bbdf5
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,31 @@
+
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v3.4.0
+ hooks:
+ - id: check-added-large-files
+ - id: check-case-conflict
+ - id: check-toml
+ - id: check-yaml
+ - id: debug-statements
+ - id: end-of-file-fixer
+ exclude: WHEEL
+ exclude_types: [json]
+ - id: forbid-new-submodules
+ - id: trailing-whitespace
+ exclude: .patch
+ exclude_types: [json]
+
+- repo: https://github.com/psf/black
+ rev: 22.1.0
+ hooks:
+ - id: black
+ files: \.py$
+ args: [--line-length=100]
+
+- repo: https://github.com/PyCQA/isort
+ rev: 5.7.0
+ hooks:
+ - id: isort
+ files: \.py$
+ args: [--profile=black]
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index cf451172a4..443344fbbf 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -38,6 +38,23 @@ General Guidelines
from the cmd line to run the test suite).
- Add yourself to doc/contributors.rst :)
+Running Linters
+---------------
+
+PyMongo uses `pre-commit `_
+for managing linting of the codebase.
+``pre-commit`` performs various checks on all files in PyMongo and uses tools
+that help follow a consistent code style within the codebase.
+
+To set up ``pre-commit`` locally, run::
+
+ pip install pre-commit
+ pre-commit install
+
+To run ``pre-commit`` manually, run::
+
+ pre-commit run --all-files
+
Documentation
-------------
diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES
index 4f2edb8660..4c32fc64a8 100644
--- a/THIRD-PARTY-NOTICES
+++ b/THIRD-PARTY-NOTICES
@@ -94,4 +94,3 @@ supplied in this file in the creation of products supporting the
Unicode Standard, and to make copies of this file in any form
for internal or external distribution as long as this notice
remains attached.
-
diff --git a/bson/binary.py b/bson/binary.py
index 361e59376a..c9415ba069 100644
--- a/bson/binary.py
+++ b/bson/binary.py
@@ -69,7 +69,7 @@ class UuidRepresentation:
code. When decoding a BSON binary field with a UUID subtype, a
:class:`~bson.binary.Binary` instance will be returned instead of a
:class:`uuid.UUID` instance.
-
+
See :ref:`unspecified-representation-details` for details.
.. versionadded:: 3.11
@@ -81,7 +81,7 @@ class UuidRepresentation:
:class:`uuid.UUID` instances will automatically be encoded to
and decoded from BSON binary, using RFC-4122 byte order with
binary subtype :data:`UUID_SUBTYPE`.
-
+
See :ref:`standard-representation-details` for details.
.. versionadded:: 3.11
@@ -93,7 +93,7 @@ class UuidRepresentation:
:class:`uuid.UUID` instances will automatically be encoded to
and decoded from BSON binary, using RFC-4122 byte order with
binary subtype :data:`OLD_UUID_SUBTYPE`.
-
+
See :ref:`python-legacy-representation-details` for details.
.. versionadded:: 3.11
@@ -105,7 +105,7 @@ class UuidRepresentation:
:class:`uuid.UUID` instances will automatically be encoded to
and decoded from BSON binary subtype :data:`OLD_UUID_SUBTYPE`,
using the Java driver's legacy byte order.
-
+
See :ref:`java-legacy-representation-details` for details.
.. versionadded:: 3.11
@@ -117,7 +117,7 @@ class UuidRepresentation:
:class:`uuid.UUID` instances will automatically be encoded to
and decoded from BSON binary subtype :data:`OLD_UUID_SUBTYPE`,
using the C# driver's legacy byte order.
-
+
See :ref:`csharp-legacy-representation-details` for details.
.. versionadded:: 3.11
diff --git a/doc/api/pymongo/event_loggers.rst b/doc/api/pymongo/event_loggers.rst
index f79bfb2345..9be0779c20 100644
--- a/doc/api/pymongo/event_loggers.rst
+++ b/doc/api/pymongo/event_loggers.rst
@@ -4,4 +4,4 @@
.. automodule:: pymongo.event_loggers
:synopsis: A collection of simple listeners for monitoring driver events.
- :members:
\ No newline at end of file
+ :members:
diff --git a/doc/api/pymongo/topology_description.rst b/doc/api/pymongo/topology_description.rst
index 8141507df7..24353db2a9 100644
--- a/doc/api/pymongo/topology_description.rst
+++ b/doc/api/pymongo/topology_description.rst
@@ -7,4 +7,3 @@
.. autoclass:: pymongo.topology_description.TopologyDescription()
:members:
-
diff --git a/doc/atlas.rst b/doc/atlas.rst
index 0a64b294ce..6100e9d3c5 100644
--- a/doc/atlas.rst
+++ b/doc/atlas.rst
@@ -41,4 +41,3 @@ Connections to Atlas require TLS/SSL.
.. _homebrew: https://brew.sh/
.. _macports: https://www.macports.org/
.. _requests: https://pypi.python.org/pypi/requests
-
diff --git a/doc/examples/server_selection.rst b/doc/examples/server_selection.rst
index 28659c133e..fc436c0cd7 100644
--- a/doc/examples/server_selection.rst
+++ b/doc/examples/server_selection.rst
@@ -105,4 +105,4 @@ list of known hosts. As an example, for a 3-member replica set with a
all available secondaries.
-.. _server selection algorithm: https://docs.mongodb.com/manual/core/read-preference-mechanics/
\ No newline at end of file
+.. _server selection algorithm: https://docs.mongodb.com/manual/core/read-preference-mechanics/
diff --git a/doc/migrate-to-pymongo4.rst b/doc/migrate-to-pymongo4.rst
index 22071bd3bb..b993e32f4e 100644
--- a/doc/migrate-to-pymongo4.rst
+++ b/doc/migrate-to-pymongo4.rst
@@ -950,4 +950,4 @@ Additional BSON classes implement ``__slots__``
:class:`~bson.max_key.MaxKey`, :class:`~bson.timestamp.Timestamp`,
:class:`~bson.regex.Regex`, and :class:`~bson.dbref.DBRef` now implement
``__slots__`` to reduce memory usage. This means that their attributes are fixed, and new
-attributes cannot be added to the object at runtime.
\ No newline at end of file
+attributes cannot be added to the object at runtime.
diff --git a/doc/tools.rst b/doc/tools.rst
index 65b38c16a8..304a1eaf5c 100644
--- a/doc/tools.rst
+++ b/doc/tools.rst
@@ -47,14 +47,14 @@ Humongolus
possible. The code is available for download
`at GitHub `_. Tutorials and usage
examples are also available at GitHub.
-
+
MincePy
- `MincePy `_ is an
- object-document mapper (ODM) designed to make any Python object storable
- and queryable in a MongoDB database. It is designed with machine learning
- and big-data computational and experimental science applications in mind
- but is entirely general and can be useful to anyone looking to organise,
- share, or process large amounts data with as little change to their current
+ `MincePy `_ is an
+ object-document mapper (ODM) designed to make any Python object storable
+ and queryable in a MongoDB database. It is designed with machine learning
+ and big-data computational and experimental science applications in mind
+ but is entirely general and can be useful to anyone looking to organise,
+ share, or process large amounts data with as little change to their current
workflow as possible.
Ming
@@ -80,7 +80,7 @@ MotorEngine
It implements the same modeling APIs to be data-portable, meaning that a
model defined in MongoEngine can be read in MotorEngine. The source is
`available on GitHub `_.
-
+
uMongo
`uMongo `_ is a Python MongoDB ODM.
Its inception comes from two needs: the lack of async ODM and the
diff --git a/test/certificates/ca.pem b/test/certificates/ca.pem
index 6ac86cfcc1..24beea2d48 100644
--- a/test/certificates/ca.pem
+++ b/test/certificates/ca.pem
@@ -18,4 +18,4 @@ gT564CmvkUat8uXPz6olOCdwkMpJ9Sj62i0mpgXJdBfxKQ6TZ9yGz6m3jannjZpN
LchB7xSAEWtqUgvNusq0dApJsf4n7jZ+oBZVaQw2+tzaMfaLqHgMwcu1FzA8UKCD
sxCgIsZUs8DdxaD418Ot6nPfheOTqe24n+TTa+Z6O0W0QtnofJBx7tmAo1aEc57i
77s89pfwIJetpIlhzNSMKurCAocFCJMJLAASJFuu6dyDvPo=
------END CERTIFICATE-----
\ No newline at end of file
+-----END CERTIFICATE-----