diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e050699..a80ebfe5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,35 @@ repos: -- repo: git@github.com:pre-commit/pre-commit-hooks - rev: v3.1.0 + - repo: git@github.com:pre-commit/pre-commit-hooks + rev: v3.2.0 hooks: - - id: check-added-large-files - - id: debug-statements - - id: end-of-file-fixer - - id: requirements-txt-fixer - - id: trailing-whitespace -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.3 + - id: check-added-large-files + - id: debug-statements + - id: end-of-file-fixer + - id: requirements-txt-fixer + - id: trailing-whitespace + - repo: local hooks: - - id: flake8 -- repo: https://github.com/timothycrosley/isort - rev: 4.3.21 - hooks: - - id: isort -- repo: https://github.com/PyCQA/pydocstyle - rev: 5.0.2 - hooks: - - id: pydocstyle -- repo: https://github.com/psf/black - rev: 19.10b0 - hooks: - - id: black + - id: flake8 + name: flake8 + entry: flake8 + language: system + types: + - python + - id: isort + name: isort + entry: isort + language: system + types: + - python + - id: pydocstyle + name: pydocstyle + entry: pydocstyle + language: system + types: + - python + - id: black + name: black + entry: black + language: system + types: + - python diff --git a/CHANGELOG.md b/CHANGELOG.md index bab5c3d1..76ccc5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support to django 3.1 `JSONField` [PR #85](https://github.com/model-bakers/model_bakery/pull/85) ### Changed +- [dev] Freeze dev requirements +- [dev] Add Django 3.1 to test matrix +- [dev] pre-commit to use local packages (so versions will match) +- [dev] consistent use of pydocstyle ### Removed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 57e0b5f8..2b6128e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ git clone git@github.com:YOUR_USER/model_bakery.git 2. Install the dev dependencies: ``` -pip install -r dev_requirements.txt +pip install -r requirements_dev.txt ``` 3. Change the code and run your tests with: @@ -26,4 +26,4 @@ make test make lint ``` -If you don't follow the step 4, your PR may fail due to `black`, `isort` or flake8` warnings. +If you don't follow the step 4, your PR may fail due to `black`, `isort`, `flake8` or `pydocstyle` warnings. diff --git a/MANIFEST.in b/MANIFEST.in index 5524434c..f3446a8c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,7 @@ include model_bakery/mock_img.jpeg include LICENSE include README.md include CHANGELOG.md -include requirements.txt dev_requirements.txt +include requirements.txt requirements_dev.txt include .travis.yml include tox.ini recursive-include tests *.py diff --git a/Makefile b/Makefile index e1ee8c90..cda3c436 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,9 @@ release: @twine upload dist/* lint: - @isort model_bakery - @black model_bakery - @flake8 model_bakery + @flake8 . + @isort . + @pydocstyle . + @black . .PHONY: test release diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index 4716a6ae..00000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ --r requirements.txt -black -flake8 -isort -pillow -pre-commit -psycopg2-binary -pytest -pytest-django -sphinx -tox diff --git a/model_bakery/random_gen.py b/model_bakery/random_gen.py index 87569999..b062042e 100644 --- a/model_bakery/random_gen.py +++ b/model_bakery/random_gen.py @@ -272,11 +272,16 @@ def gen_coords(): def gen_point(): - return "POINT ({})".format(gen_coords(),) + return "POINT ({})".format( + gen_coords(), + ) def _gen_line_string_without_prefix(): - return "({}, {})".format(gen_coords(), gen_coords(),) + return "({}, {})".format( + gen_coords(), + gen_coords(), + ) def gen_line_string(): @@ -289,19 +294,27 @@ def _gen_polygon_without_prefix(): def gen_polygon(): - return "POLYGON {}".format(_gen_polygon_without_prefix(),) + return "POLYGON {}".format( + _gen_polygon_without_prefix(), + ) def gen_multi_point(): - return "MULTIPOINT (({}))".format(gen_coords(),) + return "MULTIPOINT (({}))".format( + gen_coords(), + ) def gen_multi_line_string(): - return "MULTILINESTRING ({})".format(_gen_line_string_without_prefix(),) + return "MULTILINESTRING ({})".format( + _gen_line_string_without_prefix(), + ) def gen_multi_polygon(): - return "MULTIPOLYGON ({})".format(_gen_polygon_without_prefix(),) + return "MULTIPOLYGON ({})".format( + _gen_polygon_without_prefix(), + ) def gen_geometry(): @@ -309,7 +322,9 @@ def gen_geometry(): def gen_geometry_collection(): - return "GEOMETRYCOLLECTION ({})".format(gen_point(),) + return "GEOMETRYCOLLECTION ({})".format( + gen_point(), + ) def gen_pg_numbers_range(number_cast=int): diff --git a/readthedocs.yml b/readthedocs.yml index 20a9e2df..41dd48b3 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -1,2 +1,2 @@ python: - version: 3.5 + version: 3.8 diff --git a/requirements.txt b/requirements.txt index 6c11d7ab..f9105b95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -django>=1.11.0 +django>=1.11.0<3.2 diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 00000000..a87b0be1 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,13 @@ +-r requirements.txt + +black==20.8b1 +flake8==3.8.3 +isort==5.5.0 +pillow==7.2.0 +pip-tools==5.3.1 +pre-commit==2.7.1 +psycopg2-binary==2.8.5 +pycodestyle==2.6.0 +pydocstyle==5.1.1 +pytest==6.0.1 +pytest-django==3.9.0 diff --git a/tests/generic/baker_recipes.py b/tests/generic/baker_recipes.py index 31b35023..85d7a4b3 100644 --- a/tests/generic/baker_recipes.py +++ b/tests/generic/baker_recipes.py @@ -25,7 +25,10 @@ birth_time=now(), ) -serial_person = Recipe(Person, name=seq("joe"),) +serial_person = Recipe( + Person, + name=seq("joe"), +) serial_numbers = Recipe( DummyDefaultFieldsModel, @@ -50,15 +53,24 @@ dog = Recipe(Dog, breed="Pug", owner=foreign_key(person)) -homeless_dog = Recipe(Dog, breed="Pug",) +homeless_dog = Recipe( + Dog, + breed="Pug", +) other_dog = Recipe(Dog, breed="Basset", owner=foreign_key("person")) -dog_with_friends = dog.extend(friends_with=related(dog, dog),) +dog_with_friends = dog.extend( + friends_with=related(dog, dog), +) -dog_with_more_friends = dog.extend(friends_with=related(dog_with_friends),) +dog_with_more_friends = dog.extend( + friends_with=related(dog_with_friends), +) -extended_dog = dog.extend(breed="Super basset",) +extended_dog = dog.extend( + breed="Super basset", +) class SmallDogRecipe(Recipe): @@ -68,11 +80,16 @@ class SmallDogRecipe(Recipe): small_dog = SmallDogRecipe(Dog) -pug = small_dog.extend(breed="Pug",) +pug = small_dog.extend( + breed="Pug", +) other_dog_unicode = Recipe(Dog, breed="Basset", owner=foreign_key("person")) -dummy_unique_field = Recipe(DummyUniqueIntegerFieldModel, value=seq(10),) +dummy_unique_field = Recipe( + DummyUniqueIntegerFieldModel, + value=seq(10), +) dog_lady = Recipe(Person, dog_set=related("dog", other_dog)) diff --git a/tests/generic/models.py b/tests/generic/models.py index b72adf28..74d676ca 100755 --- a/tests/generic/models.py +++ b/tests/generic/models.py @@ -6,10 +6,11 @@ from decimal import Decimal from tempfile import gettempdir +from django.conf import settings from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation from django.contrib.contenttypes.models import ContentType from django.core.files.storage import FileSystemStorage -from django.conf import settings + from model_bakery.gis import BAKER_GIS from model_bakery.timezone import smart_datetime as datetime @@ -105,11 +106,11 @@ class Person(models.Model): CITextField, ) from django.contrib.postgres.fields.ranges import ( - IntegerRangeField, BigIntegerRangeField, - FloatRangeField, DateRangeField, DateTimeRangeField, + FloatRangeField, + IntegerRangeField, ) if settings.USING_POSTGRES: diff --git a/tests/test_baker.py b/tests/test_baker.py index 28137e26..f38ed43d 100644 --- a/tests/test_baker.py +++ b/tests/test_baker.py @@ -6,6 +6,7 @@ import pytest from django.db.models import Manager from django.db.models.signals import m2m_changed + from model_bakery import baker, random_gen from model_bakery.exceptions import ( AmbiguousModelName, @@ -268,10 +269,18 @@ def test_access_related_name_of_m2m(self): def test_save_object_instances_when_handling_one_to_many_relations(self): owner = baker.make(models.Person) - dogs_set = baker.prepare(models.Dog, owner=owner, _quantity=2,) + dogs_set = baker.prepare( + models.Dog, + owner=owner, + _quantity=2, + ) assert 0 == models.Dog.objects.count() # ensure there're no dogs in our db - home = baker.make(models.Home, owner=owner, dogs=dogs_set,) + home = baker.make( + models.Home, + owner=owner, + dogs=dogs_set, + ) assert home.dogs.count() == 2 assert 2 == models.Dog.objects.count() # dogs in dogs_set were created @@ -407,7 +416,9 @@ def test_allow_create_fkey_related_model(self): def test_field_lookup_for_related_field(self): person = baker.make( - models.Person, one_related__name="Foo", fk_related__name="Bar", + models.Person, + one_related__name="Foo", + fk_related__name="Bar", ) assert person.pk @@ -418,7 +429,9 @@ def test_field_lookup_for_related_field(self): def test_field_lookup_for_related_field_does_not_work_with_prepare(self): person = baker.prepare( - models.Person, one_related__name="Foo", fk_related__name="Bar", + models.Person, + one_related__name="Foo", + fk_related__name="Bar", ) assert not person.pk @@ -565,7 +578,8 @@ def test_skip_fields_with_default(self): class TestBakerHandlesModelWithNext: def test_creates_instance_for_model_with_next(self): instance = baker.make( - models.BaseModelForNext, fk=baker.make(models.ModelWithNext), + models.BaseModelForNext, + fk=baker.make(models.ModelWithNext), ) assert instance.id @@ -649,6 +663,8 @@ def test_annotation_within_manager_get_queryset_are_run_on_make(self): assert movie.name movie = baker.make( - models.MovieWithAnnotation, title="Old Boy", _from_manager="objects", + models.MovieWithAnnotation, + title="Old Boy", + _from_manager="objects", ) assert movie.title == movie.name diff --git a/tests/test_filling_fields.py b/tests/test_filling_fields.py index ddb49f3b..8e3b4dd7 100644 --- a/tests/test_filling_fields.py +++ b/tests/test_filling_fields.py @@ -14,6 +14,7 @@ ) from django.db import connection from django.db.models import FileField, ImageField, fields + from model_bakery import baker from model_bakery.gis import BAKER_GIS from model_bakery.random_gen import gen_related @@ -31,14 +32,14 @@ CIEmailField, CITextField, HStoreField, - JSONField as PostgresJSONField, ) + from django.contrib.postgres.fields import JSONField as PostgresJSONField from django.contrib.postgres.fields.ranges import ( - IntegerRangeField, BigIntegerRangeField, - FloatRangeField, DateRangeField, DateTimeRangeField, + FloatRangeField, + IntegerRangeField, ) except ImportError: ArrayField = None diff --git a/tests/test_recipes.py b/tests/test_recipes.py index c30b2549..08059931 100644 --- a/tests/test_recipes.py +++ b/tests/test_recipes.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest + from model_bakery import baker from model_bakery.exceptions import InvalidQuantityException, RecipeIteratorEmpty from model_bakery.recipe import Recipe, RecipeForeignKey, foreign_key @@ -255,7 +256,10 @@ def test_make_recipe_raises_correct_exception_if_invalid_quantity(self): def test_prepare_recipe_with_foreign_key(self): person_recipe = Recipe(Person, name="John Doe") - dog_recipe = Recipe(Dog, owner=foreign_key(person_recipe),) + dog_recipe = Recipe( + Dog, + owner=foreign_key(person_recipe), + ) dog = dog_recipe.prepare() assert dog.id is None diff --git a/tox.ini b/tox.ini index 3b367c6f..fc4b3135 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,15 @@ envlist = py{36,37,38}-django{111,20,21,22,30}-{postgresql,sqlite} flake8 isort + pydocstyle black [gh-actions] python = 3.5: py35 - 3.6: py36,flake8,isort,black + 3.6: py36 3.7: py37 - 3.8: py38 + 3.8: py38,flake8,isort,pydocstyle,black [testenv] setenv = @@ -28,6 +29,7 @@ deps = django21: Django==2.1 django22: Django==2.2 django30: Django>=3.0a1,<3.1 + django31: Django>=3.1,<3.2 postgresql: psycopg2-binary commands = pytest