From d33cc9025312f3ac9e9b454c8d76c6d5a5a37221 Mon Sep 17 00:00:00 2001 From: Alexander Burmak Date: Fri, 21 Jul 2023 19:18:50 +0300 Subject: [PATCH] flake8 linter --- .flake8 | 12 ++++++-- .github/workflows/workflow.yml | 8 ++++-- Makefile | 28 +++++++++++++++++++ README.md | 3 +- pyproject.toml | 3 ++ src/ch_tools/chadmin/cli/chs3_backup_group.py | 3 +- .../chadmin/cli/object_storage_group.py | 4 +-- src/ch_tools/common/cli/formatting.py | 2 +- 8 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.flake8 b/.flake8 index 1a52b0fc..60dddde4 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,10 @@ [flake8] -; ignoring the checks: -; E402 (module level import not at top of file) to set warning filtering before importing modules -ignore = E402 +; Disabling the checks that conflict with "black": +; E122 "continuation line missing indentation or outdented" +; E126 "continuation line over-indented for hanging indent" +; E131 "continuation line unaligned for hanging indent" +; E203 "whitespace before ':'" +; E501 "line too long (129 > 120 characters)" +; W503 "line break before binary operator" +select = E,F,W,C,S +ignore = E122,E126,E131,E203,E501,W503 diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 75feffde..f2030e5b 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -14,8 +14,12 @@ jobs: - uses: actions/setup-python@v4 with: { python-version: "3.11", cache: pip } - run: pip install .[test] - - {name: "lint: black", run: black --check --diff . } - - {name: "lint: isort", run: isort --check --diff . } + - name: "lint: isort" + run: make isort + - name: "lint: black" + run: make black + - name: "lint: flake8" + run: make flake8 # Temporarily disabled due to bugs in typing in click library # https://github.com/pallets/click/pull/2559 # https://github.com/python/mypy/issues/13250 diff --git a/Makefile b/Makefile index 03d28a1e..a18f4dcc 100644 --- a/Makefile +++ b/Makefile @@ -130,9 +130,37 @@ clean: rm -rf debian/files debian/.debhelper rm -rf debian/ch-tools* + +.PHONY: lint +lint: isort black flake8 + +.PHONY: isort +isort: + isort --check --diff . + +.PHONY: black +black: + black --check --diff . + +.PHONY: flake8 +flake8: + flake8 src tests + +.PHONY: format +format: + isort . + black . + + .PHONY: help help: @echo "Base targets:" + @echo " lint Run linters. Alias for \"isort black flake8\"." + @echo " isort Perform isort checks." + @echo " black Perform black checks." + @echo " flake8 Perform flake8 checks." + @echo " format Re-format source code to conform style settings enforced by" + @echo " isort and black tools." @echo " prepare-changelog Add an autobuild version entity to changelog" @echo " prepare-version Update version based on latest commit" @echo " build-python-package Build 'ch-tools' Python package" diff --git a/README.md b/README.md index ca7df611..4a12a00a 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ flit build --no-use-vcs flit install # lint -black . -isort . +make lint # unit tests pytest diff --git a/pyproject.toml b/pyproject.toml index c5deb9be..b24874fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,6 +105,9 @@ test = [ "flit", "black", "isort", + "flake8", + "flake8-string-format", + "flake8-print", "mypy", "types-pyyaml", "types-requests", diff --git a/src/ch_tools/chadmin/cli/chs3_backup_group.py b/src/ch_tools/chadmin/cli/chs3_backup_group.py index 7413b34c..6cc68cb4 100644 --- a/src/ch_tools/chadmin/cli/chs3_backup_group.py +++ b/src/ch_tools/chadmin/cli/chs3_backup_group.py @@ -1,8 +1,7 @@ import os -from typing import List import requests -from click import ClickException, Context, argument, group, option, pass_context +from click import ClickException, argument, group, option, pass_context from ch_tools.chadmin.internal.backup import unfreeze_backup, unfreeze_table from ch_tools.chadmin.internal.system import match_ch_version diff --git a/src/ch_tools/chadmin/cli/object_storage_group.py b/src/ch_tools/chadmin/cli/object_storage_group.py index 1cb4104b..da797abe 100644 --- a/src/ch_tools/chadmin/cli/object_storage_group.py +++ b/src/ch_tools/chadmin/cli/object_storage_group.py @@ -4,9 +4,9 @@ import sys from datetime import datetime, timedelta, timezone from gzip import GzipFile -from io import IOBase, TextIOWrapper +from io import TextIOWrapper from pathlib import Path -from typing import Dict, Iterator, List, Optional, Union +from typing import Dict, List, Optional import click from click import Context, group, option, pass_context diff --git a/src/ch_tools/common/cli/formatting.py b/src/ch_tools/common/cli/formatting.py index 75e2300e..2ef06721 100644 --- a/src/ch_tools/common/cli/formatting.py +++ b/src/ch_tools/common/cli/formatting.py @@ -13,7 +13,7 @@ import humanfriendly from click import style -from cloup import Color, Context +from cloup import Color from deepdiff.helper import notpresent from pygments import highlight from pygments.formatters.terminal256 import Terminal256Formatter