Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze dev requirements, update dev tooling #103

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 0 additions & 11 deletions dev_requirements.txt

This file was deleted.

29 changes: 22 additions & 7 deletions model_bakery/random_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -289,27 +294,37 @@ 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():
return gen_point()


def gen_geometry_collection():
return "GEOMETRYCOLLECTION ({})".format(gen_point(),)
return "GEOMETRYCOLLECTION ({})".format(
gen_point(),
)


def gen_pg_numbers_range(number_cast=int):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
python:
version: 3.5
version: 3.8
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
django>=1.11.0
django>=1.11.0<3.2
13 changes: 13 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -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
31 changes: 24 additions & 7 deletions tests/generic/baker_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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))

Expand Down
7 changes: 4 additions & 3 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
28 changes: 22 additions & 6 deletions tests/test_baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions tests/test_filling_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading