From c7e8b83a1e8a91b51f954840ed57883bf3ddeae0 Mon Sep 17 00:00:00 2001 From: Justin Slay Date: Wed, 13 Apr 2022 12:51:03 -0600 Subject: [PATCH] Added editorconfig, black, flake8, isort, pre-commit --- .editorconfig | 20 ++++++++++++++++++++ .flake8 | 23 +++++++++++++++++++++++ .gitignore | 3 +++ .pre-commit-config.yaml | 18 ++++++++++++++++++ pyproject.toml | 15 +++++++++++++++ wagtailflags/tests/test_conditions.py | 3 +-- wagtailflags/tests/test_signals.py | 3 +-- wagtailflags/tests/test_views.py | 3 +-- wagtailflags/tests/urls.py | 3 ++- wagtailflags/wagtail_hooks.py | 3 ++- 10 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 .editorconfig create mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1d63a40 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +# Matches multiple files with brace expansion notation +# Set default charset +# Set max line length +# 4 space indentation +[*.py] +charset = utf-8 +max_line_length = 79 +indent_style = space +indent_size = 4 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0be5005 --- /dev/null +++ b/.flake8 @@ -0,0 +1,23 @@ +[flake8] +max-line-length = 79 +select = C,E,F,W,B,B950 +ignore = + # black https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length + E203, E501 + # There's nothing wrong with assigning lambdas + E731, + # PEP8 weakly recommends Knuth-style line breaks before binary + # operators + W503, W504 +exclude = + # These are directories that it's a waste of time to traverse + .git, + .tox, + .venv, + docs, + venv, + + # Generated migration files will throw errors. We need to find a way + # to exclude django-generated migrations while including + # manually-written migrations. + */migrations/*.py, diff --git a/.gitignore b/.gitignore index a8ba298..ca2b58b 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,6 @@ bower_components/ .grunt/ src/vendor/ dist/ + +# IDEs +.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b7efd01 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: +- repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: ["wagtailflags", "setup.py", "--line-length=79"] + exclude: migrations +- repo: https://gitlab.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + additional_dependencies: [flake8-bugbear==22.1.11] +- repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort (python) + args: ["wagtailflags"] diff --git a/pyproject.toml b/pyproject.toml index 70364bd..9900a26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,5 +20,20 @@ exclude = ''' ) ''' +[tool.isort] +profile = "black" +line_length = 79 +lines_after_imports = 2 +skip = [".tox", "migrations", ".venv", "venv"] +known_django = ["django"] +default_section = "THIRDPARTY" +sections = [ + "STDLIB", + "DJANGO", + "THIRDPARTY", + "FIRSTPARTY", + "LOCALFOLDER" +] + [build-system] requires = ["setuptools", "wheel"] diff --git a/wagtailflags/tests/test_conditions.py b/wagtailflags/tests/test_conditions.py index 1a8ac07..67b80be 100644 --- a/wagtailflags/tests/test_conditions.py +++ b/wagtailflags/tests/test_conditions.py @@ -1,9 +1,8 @@ from django.test import RequestFactory, TestCase import wagtail -from wagtail.core.models import Site - from flags.conditions import RequiredForCondition +from wagtail.core.models import Site from wagtailflags.conditions import site_condition diff --git a/wagtailflags/tests/test_signals.py b/wagtailflags/tests/test_signals.py index 09e451b..c5ebb71 100644 --- a/wagtailflags/tests/test_signals.py +++ b/wagtailflags/tests/test_signals.py @@ -2,9 +2,8 @@ from django.test import TestCase -from wagtail.tests.utils import WagtailTestUtils - from flags.models import FlagState +from wagtail.tests.utils import WagtailTestUtils from wagtailflags.signals import flag_disabled, flag_enabled diff --git a/wagtailflags/tests/test_views.py b/wagtailflags/tests/test_views.py index 3f4328f..bacc69c 100644 --- a/wagtailflags/tests/test_views.py +++ b/wagtailflags/tests/test_views.py @@ -1,8 +1,7 @@ from django.test import TestCase -from wagtail.tests.utils import WagtailTestUtils - from flags.models import FlagState +from wagtail.tests.utils import WagtailTestUtils class TestWagtailFlagsViews(TestCase, WagtailTestUtils): diff --git a/wagtailflags/tests/urls.py b/wagtailflags/tests/urls.py index f09fcdc..7f8e99b 100644 --- a/wagtailflags/tests/urls.py +++ b/wagtailflags/tests/urls.py @@ -4,7 +4,8 @@ try: # pragma: no cover; >= 2.0 from django.urls import include, re_path except ImportError: # pragma: no cover; fallback for Django < 2.0 - from django.conf.urls import include, url as re_path + from django.conf.urls import include + from django.conf.urls import url as re_path urlpatterns = [ diff --git a/wagtailflags/wagtail_hooks.py b/wagtailflags/wagtail_hooks.py index 4118f96..65133a0 100644 --- a/wagtailflags/wagtail_hooks.py +++ b/wagtailflags/wagtail_hooks.py @@ -11,7 +11,8 @@ try: # pragma: no cover; >= 2.0 from django.urls import include, re_path, reverse except ImportError: # pragma: no cover; fallback for Django < 2.0 - from django.conf.urls import include, url as re_path + from django.conf.urls import include + from django.conf.urls import url as re_path from django.core.urlresolvers import reverse