From 17151f67c2cdd98e97f3f4f539af167b84927ee2 Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 00:53:39 +0100 Subject: [PATCH 1/7] Reformat repo with pre-commit hooks --- docs/django.rst | 4 ++-- docs/faq.rst | 1 - docs/guide/connecting.rst | 2 +- docs/guide/mongomock.rst | 4 ++-- docs/guide/signals.rst | 4 ++-- docs/guide/text-indexes.rst | 6 +++--- docs/index.rst | 1 - mongoengine/queryset/base.py | 4 +++- python-mongoengine.spec | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/django.rst b/docs/django.rst index b8a52165..d43a205e 100644 --- a/docs/django.rst +++ b/docs/django.rst @@ -13,7 +13,7 @@ Help Wanted! The MongoEngine team is looking for help contributing and maintaining a new Django extension for MongoEngine! If you have Django experience and would like -to help contribute to the project, please get in touch on the -`mailing list `_ or by +to help contribute to the project, please get in touch on the +`mailing list `_ or by simply contributing on `GitHub `_. diff --git a/docs/faq.rst b/docs/faq.rst index 27cd6937..49c73023 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -10,4 +10,3 @@ If this is a requirement for your project, check the alternative: `uMongo`_ and .. _uMongo: https://umongo.readthedocs.io/ .. _MotorEngine: https://motorengine.readthedocs.io/ - diff --git a/docs/guide/connecting.rst b/docs/guide/connecting.rst index aac13902..ac2146a6 100644 --- a/docs/guide/connecting.rst +++ b/docs/guide/connecting.rst @@ -86,7 +86,7 @@ using 3 different databases to store data:: connect(alias='user-db-alias', db='user-db') connect(alias='book-db-alias', db='book-db') connect(alias='users-books-db-alias', db='users-books-db') - + class User(Document): name = StringField() diff --git a/docs/guide/mongomock.rst b/docs/guide/mongomock.rst index d70ee6a6..9f199ce5 100644 --- a/docs/guide/mongomock.rst +++ b/docs/guide/mongomock.rst @@ -2,10 +2,10 @@ Use mongomock for testing ============================== -`mongomock `_ is a package to do just +`mongomock `_ is a package to do just what the name implies, mocking a mongo database. -To use with mongoengine, simply specify mongomock when connecting with +To use with mongoengine, simply specify mongomock when connecting with mongoengine: .. code-block:: python diff --git a/docs/guide/signals.rst b/docs/guide/signals.rst index 06bccb3b..e5214610 100644 --- a/docs/guide/signals.rst +++ b/docs/guide/signals.rst @@ -44,8 +44,8 @@ Available signals include: `post_save` Called within :meth:`~mongoengine.Document.save` after most actions - (validation, insert/update, and cascades, but not clearing dirty flags) have - completed successfully. Passed the additional boolean keyword argument + (validation, insert/update, and cascades, but not clearing dirty flags) have + completed successfully. Passed the additional boolean keyword argument `created` to indicate if the save was an insert or an update. `pre_delete` diff --git a/docs/guide/text-indexes.rst b/docs/guide/text-indexes.rst index 92a4471a..a5eaf7d8 100644 --- a/docs/guide/text-indexes.rst +++ b/docs/guide/text-indexes.rst @@ -8,7 +8,7 @@ After MongoDB 2.4 version, supports search documents by text indexes. Defining a Document with text index =================================== Use the *$* prefix to set a text index, Look the declaration:: - + class News(Document): title = StringField() content = StringField() @@ -35,10 +35,10 @@ Saving a document:: content="Various improvements").save() Next, start a text search using :attr:`QuerySet.search_text` method:: - + document = News.objects.search_text('testing').first() document.title # may be: "Using mongodb text search" - + document = News.objects.search_text('released').first() document.title # may be: "MongoEngine 0.9 released" diff --git a/docs/index.rst b/docs/index.rst index 662968d4..15f3c590 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -91,4 +91,3 @@ Indices and tables * :ref:`genindex` * :ref:`modindex` * :ref:`search` - diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index a648391e..a09cbf99 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -1193,7 +1193,9 @@ class BaseQuerySet(object): validate_read_preference("read_preference", read_preference) queryset = self.clone() queryset._read_preference = read_preference - queryset._cursor_obj = None # we need to re-create the cursor object whenever we apply read_preference + queryset._cursor_obj = ( + None + ) # we need to re-create the cursor object whenever we apply read_preference return queryset def scalar(self, *fields): diff --git a/python-mongoengine.spec b/python-mongoengine.spec index eddb488d..635c779f 100644 --- a/python-mongoengine.spec +++ b/python-mongoengine.spec @@ -51,4 +51,4 @@ rm -rf $RPM_BUILD_ROOT # %{python_sitearch}/* %changelog -* See: http://docs.mongoengine.org/en/latest/changelog.html \ No newline at end of file +* See: http://docs.mongoengine.org/en/latest/changelog.html From 5b9f2bac87cafab072e224f9f5c0caa123d26c8f Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 00:54:20 +0100 Subject: [PATCH 2/7] Add pre-commit --- .pre-commit-config.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..cac25e41 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: + - repo: https://github.com/ambv/black + rev: 19.3b0 + hooks: + - id: black + language_version: python3 + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.2.3 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: flake8 From 648b28876d152be2a6e1f28b79ddb4f82e05e78b Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 00:55:16 +0100 Subject: [PATCH 3/7] Rename requirements-lint.txt to requirements-dev.txt --- requirements-lint.txt => requirements-dev.txt | 4 ++++ 1 file changed, 4 insertions(+) rename requirements-lint.txt => requirements-dev.txt (51%) diff --git a/requirements-lint.txt b/requirements-dev.txt similarity index 51% rename from requirements-lint.txt rename to requirements-dev.txt index 9dc6123b..e57131c5 100644 --- a/requirements-lint.txt +++ b/requirements-dev.txt @@ -1,3 +1,7 @@ black flake8 flake8-import-order +pre-commit +pytest +ipdb +ipython From abc159b7b95380d0da6f9bc7cef427a31f3139e6 Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 01:10:54 +0100 Subject: [PATCH 4/7] Update Contributing, changelog --- CONTRIBUTING.rst | 24 ++++++++++++++++++++++-- docs/changelog.rst | 2 ++ requirements-dev.txt | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 56bae31f..b571acf1 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -31,8 +31,28 @@ build. You should ensure that your code is properly converted by Style Guide ----------- -MongoEngine uses `black `_ for code -formatting. +MongoEngine uses various tools to maintain a common coding style. + +To install all development tools, simply run the following commands: + +.. code-block:: console + + $ python -m pip install -r requirements-dev.txt + + +You can install `pre-commit `_ into your git hooks, +to automatically check and fix any formatting issue before creating a +git commit. + +Simply run the following command: + +.. code-block:: console + + $ pre-commit install + +See the ``.pre-commit-config.yaml`` configuration file for more information +on how it works. + Testing ------- diff --git a/docs/changelog.rst b/docs/changelog.rst index 99081957..933d0231 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,6 +25,8 @@ Development - In bulk write insert, the detailed error message would raise in exception. - Added ability to compare Q and Q operations #2204 - Added ability to use a db alias on query_counter #2194 +- Added pre-commit +- Renamed requirements-lint.txt to requirements-dev.txt Changes in 0.18.2 ================= diff --git a/requirements-dev.txt b/requirements-dev.txt index e57131c5..ee788e7a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,3 +5,4 @@ pre-commit pytest ipdb ipython +tox From 37ffeafeff79e615ca0aa3140b5db638a1cd252b Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 01:13:05 +0100 Subject: [PATCH 5/7] Replace 'pip' with 'python -m pip install' in docs --- README.rst | 6 +++--- docs/guide/installing.rst | 2 +- docs/index.rst | 2 +- docs/tutorial.rst | 2 +- docs/upgrade.rst | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 853d8fbe..bae7c52c 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,7 @@ with MongoDB version > 3.6. Installation ============ We recommend the use of `virtualenv `_ and of -`pip `_. You can then use ``pip install -U mongoengine``. +`pip `_. You can then use ``python -m pip install -U mongoengine``. You may also have `setuptools `_ and thus you can use ``easy_install -U mongoengine``. Another option is `pipenv `_. You can then use ``pipenv install mongoengine`` @@ -44,7 +44,7 @@ run ``python setup.py install``. Dependencies ============ -All of the dependencies can easily be installed via `pip `_. +All of the dependencies can easily be installed via `python -m pip `_. At the very least, you'll need these two packages to use MongoEngine: - pymongo>=3.4 @@ -126,7 +126,7 @@ installed in your environment and then: .. code-block:: shell # Install tox - $ pip install tox + $ python -m pip install tox # Run the test suites $ tox diff --git a/docs/guide/installing.rst b/docs/guide/installing.rst index b89d48f0..2c962ad9 100644 --- a/docs/guide/installing.rst +++ b/docs/guide/installing.rst @@ -12,7 +12,7 @@ MongoEngine is available on PyPI, so you can use :program:`pip`: .. code-block:: console - $ pip install mongoengine + $ python -m pip install mongoengine Alternatively, if you don't have setuptools installed, `download it from PyPi `_ and run diff --git a/docs/index.rst b/docs/index.rst index 15f3c590..a42ff857 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,7 +7,7 @@ MongoDB. To install it, simply run .. code-block:: console - $ pip install -U mongoengine + $ python -m pip install -U mongoengine :doc:`tutorial` A quick tutorial building a tumblelog to get you up and running with diff --git a/docs/tutorial.rst b/docs/tutorial.rst index bcd0d17f..b7885c34 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -18,7 +18,7 @@ location --- running it locally will be easier, but if that is not an option then it may be run on a remote server. If you haven't installed MongoEngine, simply use pip to install it like so:: - $ pip install mongoengine + $ python -m pip install mongoengine Before we can start using MongoEngine, we need to tell it how to connect to our instance of :program:`mongod`. For this we use the :func:`~mongoengine.connect` diff --git a/docs/upgrade.rst b/docs/upgrade.rst index 082dbadc..285bf24c 100644 --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -85,10 +85,10 @@ by default from now on. The 0.8.7 package on pypi was corrupted. If upgrading from 0.8.7 to 0.9.0 please follow: :: - pip uninstall pymongo - pip uninstall mongoengine - pip install pymongo==2.8 - pip install mongoengine + python -m pip uninstall pymongo + python -m pip uninstall mongoengine + python -m pip install pymongo==2.8 + python -m pip install mongoengine 0.8.7 ***** From d3d7f0e670b09fdd571fa6f2cf18ee36b793b6c7 Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 01:18:29 +0100 Subject: [PATCH 6/7] Changelog --- CONTRIBUTING.rst | 2 +- docs/changelog.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b571acf1..27759f8f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -44,7 +44,7 @@ You can install `pre-commit `_ into your git hooks, to automatically check and fix any formatting issue before creating a git commit. -Simply run the following command: +To enable ``pre-commit`` simply run: .. code-block:: console diff --git a/docs/changelog.rst b/docs/changelog.rst index 933d0231..38f1a85e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,8 +25,8 @@ Development - In bulk write insert, the detailed error message would raise in exception. - Added ability to compare Q and Q operations #2204 - Added ability to use a db alias on query_counter #2194 -- Added pre-commit -- Renamed requirements-lint.txt to requirements-dev.txt +- Added pre-commit #2212 +- Renamed requirements-lint.txt to requirements-dev.txt #2212 Changes in 0.18.2 ================= From 90fecc56ddf53872f72774b75d27090acd6315ff Mon Sep 17 00:00:00 2001 From: Filip Kucharczyk Date: Thu, 5 Dec 2019 01:33:35 +0100 Subject: [PATCH 7/7] Reformat with black --- mongoengine/queryset/base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mongoengine/queryset/base.py b/mongoengine/queryset/base.py index a09cbf99..a648391e 100644 --- a/mongoengine/queryset/base.py +++ b/mongoengine/queryset/base.py @@ -1193,9 +1193,7 @@ class BaseQuerySet(object): validate_read_preference("read_preference", read_preference) queryset = self.clone() queryset._read_preference = read_preference - queryset._cursor_obj = ( - None - ) # we need to re-create the cursor object whenever we apply read_preference + queryset._cursor_obj = None # we need to re-create the cursor object whenever we apply read_preference return queryset def scalar(self, *fields):