From 53ac96b11170627976e3e3656d12933b76eeb274 Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 26 Jan 2018 11:29:31 +0200 Subject: [PATCH 1/6] requirements-style: Add flake8-isort and flake8-print Make sure that imports are correctly sorted and that there is no debugging print statements committed. --- requirements-style.in | 2 ++ requirements-style.txt | 8 +++++++- setup.cfg | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/requirements-style.in b/requirements-style.in index 39304807..f9084250 100644 --- a/requirements-style.in +++ b/requirements-style.in @@ -1 +1,3 @@ flake8 +flake8-isort +flake8-print diff --git a/requirements-style.txt b/requirements-style.txt index da70b1cf..647fbace 100644 --- a/requirements-style.txt +++ b/requirements-style.txt @@ -3,6 +3,12 @@ # prequ update # flake8==3.5.0 +flake8-isort==2.3 +flake8-polyfill==1.0.2 # via flake8-isort +flake8-print==3.0.1 +isort==4.2.15 # via flake8-isort mccabe==0.6.1 # via flake8 -pycodestyle==2.3.1 # via flake8 +pycodestyle==2.3.1 # via flake8, flake8-print pyflakes==1.6.0 # via flake8 +six==1.11.0 # via flake8-print +testfixtures==5.4.0 # via flake8-isort diff --git a/setup.cfg b/setup.cfg index eb04976a..98ac9b58 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,8 +20,8 @@ doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ALLOW_UNICODE atomic=true combine_as_imports=false indent=4 -known_standard_library=token,tokenize,enum,importlib -known_third_party=django,six +default_section=THIRDPARTY +known_first_party=parkkihubi,parkings length_sort=false line_length=120 multi_line_output=5 From 2faf550cc65e848c5d63414da1825e18654d5fed Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 26 Jan 2018 11:47:22 +0200 Subject: [PATCH 2/6] requirements-style: Add pep8-naming Ensure variable names are cased according to PEP-8. --- requirements-style.in | 1 + requirements-style.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements-style.in b/requirements-style.in index f9084250..b19b7d37 100644 --- a/requirements-style.in +++ b/requirements-style.in @@ -1,3 +1,4 @@ flake8 flake8-isort flake8-print +pep8-naming diff --git a/requirements-style.txt b/requirements-style.txt index 647fbace..743bba12 100644 --- a/requirements-style.txt +++ b/requirements-style.txt @@ -4,10 +4,11 @@ # flake8==3.5.0 flake8-isort==2.3 -flake8-polyfill==1.0.2 # via flake8-isort +flake8-polyfill==1.0.2 # via flake8-isort, pep8-naming flake8-print==3.0.1 isort==4.2.15 # via flake8-isort mccabe==0.6.1 # via flake8 +pep8-naming==0.5.0 pycodestyle==2.3.1 # via flake8, flake8-print pyflakes==1.6.0 # via flake8 six==1.11.0 # via flake8-print From 28e0abe511207aa81980d567577d01e235a6b3fb Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 26 Jan 2018 11:55:16 +0200 Subject: [PATCH 3/6] Tune isort configuration * Simplify the isort configuration by removing many unneeded customizations. * Change the line length to 79 so that very long lines can be avoided in the imports. * Use multi_line_output style 4. The imports are sorted (with isort) too. --- parkings/api/public/parking_area.py | 3 ++- parkings/tests/api/enforcement/test_operator.py | 4 +++- parkings/tests/api/enforcement/test_valid_parking.py | 8 ++++---- parkings/tests/api/operator/test_parking.py | 4 +++- .../tests/api/public/test_parking_area_statistics.py | 4 +++- parkings/tests/conftest.py | 5 ++--- setup.cfg | 10 ++-------- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/parkings/api/public/parking_area.py b/parkings/api/public/parking_area.py index e9a93cb5..fe9c5a8f 100644 --- a/parkings/api/public/parking_area.py +++ b/parkings/api/public/parking_area.py @@ -1,6 +1,7 @@ from rest_framework import viewsets from rest_framework_gis.pagination import GeoJsonPagination -from rest_framework_gis.serializers import GeoFeatureModelSerializer, GeometrySerializerMethodField +from rest_framework_gis.serializers import ( + GeoFeatureModelSerializer, GeometrySerializerMethodField) from parkings.models import ParkingArea diff --git a/parkings/tests/api/enforcement/test_operator.py b/parkings/tests/api/enforcement/test_operator.py index 033accf3..7fa11bf9 100644 --- a/parkings/tests/api/enforcement/test_operator.py +++ b/parkings/tests/api/enforcement/test_operator.py @@ -4,7 +4,9 @@ from parkings.models import Operator -from ..utils import ALL_METHODS, check_list_endpoint_base_fields, check_method_status_codes, get +from ..utils import ( + ALL_METHODS, check_list_endpoint_base_fields, check_method_status_codes, + get) list_url = reverse('enforcement:v1:operator-list') diff --git a/parkings/tests/api/enforcement/test_valid_parking.py b/parkings/tests/api/enforcement/test_valid_parking.py index 5cde65a2..28658792 100644 --- a/parkings/tests/api/enforcement/test_valid_parking.py +++ b/parkings/tests/api/enforcement/test_valid_parking.py @@ -3,12 +3,12 @@ import pytest from django.core.urlresolvers import reverse from django.utils.timezone import utc -from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN +from rest_framework.status import ( + HTTP_400_BAD_REQUEST, HTTP_401_UNAUTHORIZED, HTTP_403_FORBIDDEN) from ..utils import ( - ALL_METHODS, check_list_endpoint_base_fields, check_method_status_codes, check_response_objects, get, - get_ids_from_results -) + ALL_METHODS, check_list_endpoint_base_fields, check_method_status_codes, + check_response_objects, get, get_ids_from_results) list_url = reverse('enforcement:v1:valid_parking-list') diff --git a/parkings/tests/api/operator/test_parking.py b/parkings/tests/api/operator/test_parking.py index f130bcff..5e0fbb67 100644 --- a/parkings/tests/api/operator/test_parking.py +++ b/parkings/tests/api/operator/test_parking.py @@ -8,7 +8,9 @@ from parkings.models import Parking -from ..utils import ALL_METHODS, check_method_status_codes, check_required_fields, delete, patch, post, put +from ..utils import ( + ALL_METHODS, check_method_status_codes, check_required_fields, delete, + patch, post, put) list_url = reverse('operator:v1:parking-list') diff --git a/parkings/tests/api/public/test_parking_area_statistics.py b/parkings/tests/api/public/test_parking_area_statistics.py index f653e1bc..ecc19c78 100644 --- a/parkings/tests/api/public/test_parking_area_statistics.py +++ b/parkings/tests/api/public/test_parking_area_statistics.py @@ -5,7 +5,9 @@ from parkings.models import Parking -from ..utils import check_list_endpoint_base_fields, check_method_status_codes, get, get_ids_from_results +from ..utils import ( + check_list_endpoint_base_fields, check_method_status_codes, get, + get_ids_from_results) list_url = reverse('public:v1:parkingareastatistics-list') diff --git a/parkings/tests/conftest.py b/parkings/tests/conftest.py index 2e4b6b2a..c676bc46 100644 --- a/parkings/tests/conftest.py +++ b/parkings/tests/conftest.py @@ -2,9 +2,8 @@ from pytest_factoryboy import register from parkings.factories import ( - AdminUserFactory, HistoryParkingFactory, OperatorFactory, ParkingAreaFactory, ParkingFactory, StaffUserFactory, - UserFactory -) + AdminUserFactory, HistoryParkingFactory, OperatorFactory, + ParkingAreaFactory, ParkingFactory, StaffUserFactory, UserFactory) register(OperatorFactory) register(ParkingFactory, 'parking') diff --git a/setup.cfg b/setup.cfg index 98ac9b58..73a7c0ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,18 +17,12 @@ norecursedirs = bower_components node_modules .git .idea doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL ALLOW_UNICODE [isort] -atomic=true -combine_as_imports=false -indent=4 default_section=THIRDPARTY known_first_party=parkkihubi,parkings -length_sort=false -line_length=120 -multi_line_output=5 +line_length=79 +multi_line_output=4 not_skip=__init__.py -order_by_type=false skip=migrations,.tox -wrap_length=120 [pydocstyle] ignore=D100,D104,D105,D200,D203,D400 From a33e7e6361437eaff7287941be1102fd8afff72e Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 9 Feb 2018 11:19:59 +0200 Subject: [PATCH 4/6] Tox: requirements check: Allow specifying prequ args --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index b4befcb6..5da86c54 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ commands = py.test -ra -vvv --strict --cov {posargs} [testenv:requirements] basepython = python3.4 deps = prequ==1.3.1 -commands = prequ check -v +commands = prequ {posargs:check -v} [testenv:style] basepython = python3.4 From a85547364292f5b163150bf090589630f75cd295 Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 9 Feb 2018 11:23:25 +0200 Subject: [PATCH 5/6] settings: Remove a print statement --- parkkihubi/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/parkkihubi/settings.py b/parkkihubi/settings.py index 365f874a..4703d3e5 100644 --- a/parkkihubi/settings.py +++ b/parkkihubi/settings.py @@ -32,7 +32,6 @@ # Create var root if it doesn't exist if not os.path.isdir(VAR_ROOT): - print('Creating var root %s' % VAR_ROOT) os.makedirs(VAR_ROOT) MEDIA_ROOT = os.path.join(VAR_ROOT, 'media') From d8af32d237e506154c2cb5e028255fe894e63d3c Mon Sep 17 00:00:00 2001 From: Tuomas Suutari Date: Fri, 9 Feb 2018 11:23:41 +0200 Subject: [PATCH 6/6] Tox: style check: Make flake8-print work The flake8-print plugin doesn't seem to do anything without this option. See https://github.com/JBKahn/flake8-print/issues/27 for info. --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 5da86c54..761e52db 100644 --- a/tox.ini +++ b/tox.ini @@ -20,4 +20,4 @@ commands = prequ {posargs:check -v} [testenv:style] basepython = python3.4 deps = -rrequirements-style.txt -commands = flake8 {posargs} +commands = flake8 {posargs:--enable=T}