diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
new file mode 100644
index 000000000..8f02673e4
--- /dev/null
+++ b/.git-blame-ignore-revs
@@ -0,0 +1,2 @@
+# Initial pre-commit reformat
+5578999a90e439fbca06fc0ffc98f4d04e96f7b4
diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml
index ca1845e2c..651f863d8 100644
--- a/.github/workflows/test-python.yml
+++ b/.github/workflows/test-python.yml
@@ -5,6 +5,18 @@ on:
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 }}
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 000000000..39062bbdf
--- /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 40dca00e0..bbc22954a 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
-------------
@@ -67,4 +84,4 @@ The ``-b`` flag adds as a regex pattern to block files you do not wish to
update in PyMongo.
This is primarily helpful if you are implementing a new feature in PyMongo
that has spec tests already implemented, or if you are attempting to
-validate new spec tests in PyMongo.
\ No newline at end of file
+validate new spec tests in PyMongo.
diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES
index 28a340b3f..a307b3043 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/doc/api/pymongo/event_loggers.rst b/doc/api/pymongo/event_loggers.rst
index f79bfb234..9be0779c2 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 8141507df..24353db2a 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 0a64b294c..6100e9d3c 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 28659c133..fc436c0cd 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 22071bd3b..b993e32f4 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 65b38c16a..304a1eaf5 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 6ac86cfcc..24beea2d4 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-----