From 2c73622a23c1f23981f290441e8e6f87433e1c4b Mon Sep 17 00:00:00 2001 From: Inessa Vasilevskaya Date: Tue, 30 Nov 2021 20:14:02 +0100 Subject: [PATCH] Add isort check for changed files After discussing with pstodulk a massive change introducing isort rules and fixing all occurrencies may be too annoying, so let's make it gradually - intoduce a handmade isort check for changed files only. This patch also introduces a lint_fix target that can do fix the order inplace automatically. --- .isort.cfg | 9 +++++++++ Makefile | 16 ++++++++++++++++ requirements.txt | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000..6e90fc79c3 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,9 @@ +[settings] +line_length=119 +known_first_party=leapp +multi_line_output=3 +honor_noqa=true +# NOTE(ivasilev) Ideal solution would be order_by_type with classes exception (for ex. RPM) but this isn't supported +# in 4.3.2 +case_sensitive=false +order_by_type=false diff --git a/Makefile b/Makefile index d0b31d0c99..a804791e2d 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ help: @echo " install-deps-fedora create python virtualenv and install there" @echo " leapp-repository with dependencies for Fedora OS" @echo " lint lint source code" + @echo " lint_fix attempt to fix isort violations inplace" @echo " test lint source code and run tests" @echo " test_no_lint run tests without linting the source code" @echo "" @@ -260,6 +261,21 @@ lint: echo "--- Linting done. ---"; \ fi + . $(VENVNAME)/bin/activate; \ + git diff $(MASTER_BRANCH) --name-only | xargs isort -c --diff || \ + { \ + echo; \ + echo "------------------------------------------------------------------------------"; \ + echo "Hint: Apply the required changes."; \ + echo " Execute the following command to apply them automatically: make lint_fix"; \ + exit 1; \ + } && echo "--- isort check done. ---"; + +lint_fix: + . $(VENVNAME)/bin/activate; \ + git diff $(MASTER_BRANCH) --name-only | xargs isort && \ + echo "--- isort inplace fixing done. ---;" + test_no_lint: . $(VENVNAME)/bin/activate; \ snactor repo find --path repos/; \ diff --git a/requirements.txt b/requirements.txt index f5c33e947b..051914d5d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ ### Additional requirements flake8 -flake8-import-order +isort funcsigs==1.0.2 mock==2.0.0 pylint