From 800b1e7eb13696953a2fa6f76f2968f2a346ae3f Mon Sep 17 00:00:00 2001 From: Justin Slay Date: Wed, 13 Apr 2022 13:40:26 -0600 Subject: [PATCH] Added editorconfig, black, flake8, isort, pre-commit --- .editorconfig | 20 ++++++++++++++++++++ .flake8 | 23 +++++++++++++++++++++++ .gitignore | 3 +++ .pre-commit-config.yaml | 18 ++++++++++++++++++ pyproject.toml | 17 +++++++++++++++++ treemodeladmin/tests/urls.py | 3 ++- 6 files changed, 83 insertions(+), 1 deletion(-) 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..595d33f --- /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: ["treemodeladmin", "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: ["treemodeladmin"] diff --git a/pyproject.toml b/pyproject.toml index 70364bd..2d6007c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,5 +20,22 @@ exclude = ''' ) ''' +[tool.isort] +profile = "black" +line_length = 79 +lines_after_imports = 2 +skip = [".tox", "migrations", ".venv", "venv"] +known_django = ["django"] +known_wagtail = ["wagtail"] +default_section = "THIRDPARTY" +sections = [ + "STDLIB", + "DJANGO", + "WAGTAIL", + "THIRDPARTY", + "FIRSTPARTY", + "LOCALFOLDER" +] + [build-system] requires = ["setuptools", "wheel"] diff --git a/treemodeladmin/tests/urls.py b/treemodeladmin/tests/urls.py index 4ecceab..a784f54 100644 --- a/treemodeladmin/tests/urls.py +++ b/treemodeladmin/tests/urls.py @@ -4,7 +4,8 @@ try: from django.urls import include, re_path except ImportError: - 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 = [