diff --git a/.pre-commit-config-all.yaml b/.pre-commit-config-all.yaml index cb01bff85cb..ec9492e0210 100644 --- a/.pre-commit-config-all.yaml +++ b/.pre-commit-config-all.yaml @@ -35,6 +35,10 @@ repos: - --format=custom - --configfile=tests/bandit.yaml files: ^(homeassistant|script|tests)/.+\.py$ +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort # Using a local "system" mypy instead of the mypy hook, because its # results depend on what is installed. And the mypy hook runs in a # virtualenv of its own, meaning we'd need to install and maintain diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6f37ae6355..23d1d9c73f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,3 +31,7 @@ repos: - --format=custom - --configfile=tests/bandit.yaml files: ^(homeassistant|script|tests)/.+\.py$ +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index cbad0c9af08..5a289cbbc70 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -54,6 +54,10 @@ stages: . venv/bin/activate pre-commit run bandit --all-files displayName: 'Run bandit' + - script: | + . venv/bin/activate + pre-commit run isort --all-files + displayName: 'Run isort' - job: 'Validate' pool: vmImage: 'ubuntu-latest' diff --git a/pylintrc b/pylintrc index 3235d583865..0ffbb138f9e 100644 --- a/pylintrc +++ b/pylintrc @@ -25,6 +25,7 @@ good-names=id,i,j,k,ex,Run,_,fp # unnecessary-pass - readability for functions which only contain pass # import-outside-toplevel - TODO # too-many-ancestors - it's too strict. +# wrong-import-order - isort guards this disable= format, abstract-class-little-used, @@ -49,7 +50,8 @@ disable= too-many-statements, too-many-boolean-expressions, unnecessary-pass, - unused-argument + unused-argument, + wrong-import-order enable= use-symbolic-message-instead diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 14b866c7034..7a20962ff7c 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -4,4 +4,5 @@ bandit==1.6.2 black==19.10b0 flake8-docstrings==1.5.0 flake8==3.7.9 +isort==v4.3.21 pydocstyle==5.0.1