From 4e0fe4ad6e4005b338fd70ad97dda6b6d150b324 Mon Sep 17 00:00:00 2001 From: mauwii Date: Fri, 17 Feb 2023 06:37:17 +0100 Subject: [PATCH] update black / flake8 related settings - add flake8-black to dev extras - update `.flake8` - update flake8 pre-commit hook --- .flake8 | 50 +++++++++++++++++++++++++++++++++++++---- .pre-commit-config.yaml | 3 +++ pyproject.toml | 28 ++++++++++++++--------- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/.flake8 b/.flake8 index 35fb6f8ea2..5137321b60 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,47 @@ [flake8] -max-line-length = 88 -extend-select = C,E,F,W,B,B9 -# B905 should be enabled when we drop support for 3.9 -extend-ignore = E203, E501, B905 +# line length is intentionally set to 80 here because black uses Bugbear +max-line-length = 80 +extend-ignore = + # See https://github.com/PyCQA/pycodestyle/issues/373 + E203, + # use Bugbear's B950 instead + E501, + # from black repo https://github.com/psf/black/blob/main/.flake8 + E266, W503, B907 +extend-select = + # Bugbear line length + B950 +exclude = + .venv, + .git, + .tox, + dist, + doc, + *lib/python*, + *egg, + build + scripts/orig_scripts/* + ldm/models/* + ldm/modules/* + ldm/data/* + ldm/generate.py + ldm/util.py + ldm/simplet2i.py +per-file-ignores = + # B950 line too long + # W605 invalid escape sequence + # F841 assigned to but never used + # F401 imported but unused + tests/test_prompt_parser.py: B950, W605, F401 + tests/test_textual_inversion.py: F841 + # B023 Function definition does not bind loop variable + scripts/legacy_api.py: F401, B950, B023, F841 + ldm/invoke/__init__.py: F401 + # B010 Do not call setattr with a constant attribute value + ldm/invoke/server_legacy.py: B010 + +# ===================== +# flake-quote settings: +# ===================== +# Set this to match black style: +inline-quotes = double diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd38a6128b..3dcfb7a2c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,9 @@ repos: rev: 6.0.0 hooks: - id: flake8 + additional_dependencies: + - flake8-black + - flake8-bugbear - repo: https://github.com/pre-commit/mirrors-prettier rev: 'v2.7.1' hooks: diff --git a/pyproject.toml b/pyproject.toml index 8e65f89efb..d8101b29e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,14 @@ readme={content-type="text/markdown", file="README.md"} requires-python=">=3.9, <3.11" [project.optional-dependencies] -"dev"=["black", "flake8", "flake8-bugbear", "isort", "pre-commit"] +"dev"=[ + "black[jupyter]", + "flake8", + "flake8-black", + "flake8-bugbear", + "isort", + "pre-commit", +] "dist"=["pip-tools", "pipdeptree", "twine"] "docs"=[ "mkdocs-git-revision-date-localized-plugin", @@ -139,24 +146,25 @@ version={attr="ldm.invoke.__version__"} [tool.black] exclude=''' /( - .git - | .tox - | .venv - | _build - | build - | dist - | node_modules + .git + | .tox + | .venv + | _build + | build + | dist + | node_modules )/ ''' include='.pyi?$' line-length=88 -source=['invokeai/backend', 'ldm/invoke'] +source=["installer", "invokeai/backend", "ldm/invoke"] target-version=['py39'] [tool.isort] -extend_ignore=["scripts"] profile="black" py_version=39 +skip_gitignore=true +skip_glob=["scripts/orig_scripts/*"] [tool.coverage.run] branch=true