Skip to content
Open
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
12 changes: 0 additions & 12 deletions .importanizerc

This file was deleted.

64 changes: 45 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
---
repos:

- repo: https://github.com/miki725/importanize
rev: '0.7'
hooks:
- id: importanize
language_version: python3

- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/pyupgrade
rev: v2.1.0
hooks:
- id: pyupgrade
args: [--py3-plus]

- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:
- id: docformatter

- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
exclude: deployment/roles
additional_dependencies:
- flake8-blind-except
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger

- repo: https://github.com/mgedmin/check-manifest
rev: '0.41'
hooks:
- id: check-manifest

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v2.5.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand All @@ -14,22 +54,8 @@ repos:
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: fix-encoding-pragma
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- id: trailing-whitespace

- repo: https://github.com/miki725/importanize
rev: '0.7'
hooks:
- id: importanize
language_version: python3

- repo: https://github.com/python/black
rev: 19.10b0
hooks:
- id: black
args: [--line-length=120, --safe]
language_version: python3
- id: mixed-line-ending
args: [--fix=lf]
- id: pretty-format-json
args: [--autofix]
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cache:

python:
- "3.7"
- "3.8"

install:
- pip install tox-travis
Expand Down
20 changes: 20 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include *.rc
include *.editorconfig
include *.rst
include *.toml
include *.txt
include *.yaml *.yml
include LICENSE
include Makefile
include pytest.ini
include tox.ini
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

recursive-include rest_dataclasses *.py

recursive-include docs *
recursive-exclude docs/_build *

recursive-include tests *
recursive-include test_site *
46 changes: 24 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
PACKAGE=rest_dataclasses
FILES=$(shell find $(PACKAGE) -iname '*.py')
FILES=$(shell find $(PACKAGE) -iname '*.py' ! -iname '__*')
VERSION=$(shell python setup.py --version)
NEXT=$(shell semver -i $(BUMP) $(VERSION))
COVERAGE_FLAGS?=--cov-fail-under=100
DBS=\
test
RESETDBS=$(addsuffix -resetdb,$(DBS))
COVERAGE_FLAGS?=--cov-report term-missing --cov-fail-under=100

.PHONY: help list docs $(FILES)

.PHONY: docs $(FILES)

help:
@for f in $(MAKEFILE_LIST) ; do \
echo "$$f:" ; \
grep -E '^[a-zA-Z_-%]+:.*?## .*$$' $$f | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' ; \
grep -E '^[^[:space:]].*:.*?## .*$$' $$f | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' ; \
done ; \

resetdb: ## reset test db
-psql -c "drop database test;" -h localhost -U postgres
-psql -c "create database test;" -h localhost -U postgres

list: ## list all possible targets
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

clean-build: ## remove build artifacts
find -name '*.sqlite3' -delete
rm -rf build/ dist/ .eggs/
rm -rf '*.egg-info'
rm -rf '*.egg'
rm -rf build dist .eggs .mypy_cache .pytest_cache docs/_build *.egg*

clean-pyc: ## remove Python file artifacts
find -name '*.pyc' -delete
Expand All @@ -32,7 +32,13 @@ clean-pyc: ## remove Python file artifacts
find -name '__pycache__' -delete

clean-test: ## remove test and coverage artifacts
rm -rf .tox/ .coverage htmlcov/
rm -rf .tox .coverage htmlcov

%-resetdb:
-psql postgresql://postgres:postgres@localhost -c "drop database $*;"
-psql postgresql://postgres:postgres@localhost -c "create database $*;"

resetdb: $(RESETDBS)

lint: ## run pre-commit hooks on all files
if python -c "import sys; exit(1) if sys.version_info.major < 3 else exit(0)"; then \
Expand All @@ -41,26 +47,21 @@ lint: ## run pre-commit hooks on all files

coverage: ## check code coverage quickly with the default Python
py.test $(PYTEST_OPTS) \
--cov-report html \
--cov-report term-missing \
--cov=$(PACKAGE) tests \
--cov=$(PACKAGE) \
$(COVERAGE_FLAGS) \
--doctest-modules \
tests $(PACKAGE)
tests

$(FILES): ## helper target to run coverage tests on a module
py.test $(PYTEST_OPTS) \
--cov-report term-missing \
--cov-fail-under 100 \
py.test $(PYTEST_OPTS) $(COVERAGE_FLAGS) \
--cov=$(subst /,.,$(firstword $(subst ., ,$@))) $(subst $(PACKAGE),tests,$(dir $@))test_$(notdir $@)

test: ## run tests
py.test $(PYTEST_OPTS) --doctest-modules tests $(PACKAGE)
py.test $(PYTEST_OPTS) tests $(PACKAGE)

check: ## run all tests
tox

history: ## generate HISTORY.rst
history: docs ## generate HISTORY.rst
gitchangelog > HISTORY.rst

docs: ## generate docs
Expand All @@ -78,6 +79,7 @@ next: # print next version
bump: history
@sed -i 's/$(VERSION)/$(NEXT)/g' $(PACKAGE)/__version__.py
@sed -i 's/Next version (unreleased yet)/$(NEXT) ($(shell date +"%Y-%m-%d"))/g' HISTORY.rst
@git add .
@git commit -am "Bump version: $(VERSION) → $(NEXT)"

tag: ## tags branch
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 120
target-version = ['py34', 'py35', 'py36', 'py37']
target-version = ['py36', 'py37']
include = '\.pyi?$'
exclude = '''
/(
Expand Down
16 changes: 13 additions & 3 deletions rest_dataclasses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from .__version__ import (
__author__,
__author_email__,
__description__,
__version__,
)

from .__version__ import __author__, __author_email__, __description__, __version__ # noqa

__all__ = [
"__author__",
"__author_email__",
"__description__",
"__version__",
]
6 changes: 0 additions & 6 deletions rest_dataclasses/__version__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals


# -*- coding: utf-8 -*-

__author__ = "Serkan Hosca"
__author_email__ = "[email protected]"
__version__ = "0.0.3"
Expand Down
6 changes: 1 addition & 5 deletions rest_dataclasses/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import copy
import dataclasses as da
import enum
Expand All @@ -9,12 +7,10 @@
from decimal import Decimal

from django.core.exceptions import ValidationError as DjangoValidationError

from rest_enumfield import EnumField
from rest_framework import fields, serializers
from rest_framework.exceptions import ValidationError

from rest_enumfield import EnumField

from .utils import django_to_drf_validation_error


Expand Down
9 changes: 4 additions & 5 deletions rest_dataclasses/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from django.core.exceptions import NON_FIELD_ERRORS, ValidationError as DjangoValidationError

from django.core.exceptions import (
NON_FIELD_ERRORS,
ValidationError as DjangoValidationError,
)
from rest_framework.serializers import ValidationError
from rest_framework.settings import api_settings

Expand Down
15 changes: 15 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ addopts=
-r sfxX

[flake8]
show-source = true
enable-extensions = B,G
max-line-length = 120
exclude = .eggs,.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules
select = C,E,F,W,B,B950
ignore = E501,W503

[importanize]
allow_plugins=True
plugins=
unused_imports
length=120
groups=
stdlib
sitepackages
remainder
packages:django
packages:tests
local
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import os
import shutil
import sys
Expand All @@ -27,7 +25,7 @@ def read(fname):
os.system("python setup.py sdist bdist_wheel")
os.system("twine upload dist/*")
print("You probably want to also tag the version now:")
print(" git tag -a %s -m %s" % (about["__version__"], about["__version__"]))
print(" git tag -a {} -m {}".format(about["__version__"], about["__version__"]))
print(" git push --tags")
os.system("make clean")
sys.exit()
Expand Down
3 changes: 0 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

import django
import django.test.utils
from django.conf import settings
Expand Down
15 changes: 8 additions & 7 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import dataclasses as da
import enum
from typing import Dict, List

from django.core.exceptions import ValidationError as DjangoValidationError
from django.test import SimpleTestCase

from rest_dataclasses.serializers import DataclassSerializer
from rest_framework import fields
from rest_framework.exceptions import ValidationError

from rest_dataclasses.serializers import DataclassSerializer


class Color(enum.Enum):
RED = "red"
Expand Down Expand Up @@ -82,7 +78,9 @@ class Meta:
fields = "id,name"

serializer = Serializer(data={"id": 1, "name": "shosca", "email": "[email protected]"})
with self.assertRaisesMessage(TypeError, 'The `fields` option must be a list or tuple or "__all__". Got str.'):
with self.assertRaisesMessage(
TypeError, 'The `fields` option must be a list or tuple or "__all__". Got str.',
):
serializer.is_valid(raise_exception=True)

def test_bad_exclude(self):
Expand Down Expand Up @@ -256,7 +254,10 @@ class Serializer(DataclassSerializer):
class Meta:
model = Line
fields = "__all__"
extra_kwargs = {"a": {"allow_null": False, "allow_create": False}, "b": {"allow_null": False}}
extra_kwargs = {
"a": {"allow_null": False, "allow_create": False},
"b": {"allow_null": False},
}

instance = Line()

Expand Down
3 changes: 0 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import unittest

from django.core.exceptions import ValidationError

from rest_dataclasses.utils import _django_to_drf


Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ skipsdist = true
envlist =
py37-{dj20,dj21,dj22}-{drf38,drf39,drf310}
py37-{dj30}-{drf310}
py38-{dj30}-{drf310}

[testenv]
passenv =
Expand All @@ -15,7 +16,7 @@ passenv =
CPPFLAGS
basepython =
py37: python3.7
pypy3: pypy3
py38: python3.8
deps =
dj11: django<2
dj20: django<2.1
Expand Down