diff --git a/.pre-commit-config-all.yaml b/.pre-commit-config-all.yaml new file mode 100644 index 00000000000..98829e25fc3 --- /dev/null +++ b/.pre-commit-config-all.yaml @@ -0,0 +1,42 @@ +# This configuration includes the full set of hooks we use. In +# addition to the defaults (see .pre-commit-config.yaml), this +# includes hooks that require our development and test dependencies +# installed and the virtualenv containing them active by the time +# pre-commit runs to produce correct results. +# +# If this is not a problem for your workflow, using this config is +# recommended, install it with +# pre-commit install --config .pre-commit-config-all.yaml +# Otherwise, see the default .pre-commit-config.yaml for a lighter one. + +repos: +- repo: https://github.com/psf/black + rev: 19.10b0 + hooks: + - id: black + args: + - --safe + - --quiet + files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$ +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.7.8 + hooks: + - id: flake8 + additional_dependencies: + - flake8-docstrings==1.3.1 + - pydocstyle==4.0.0 + files: ^(homeassistant|script|tests)/.+\.py$ +# 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 +# another set of our dependencies there... no. Use the "system" one +# and reuse the environment that is set up anyway already instead. +- repo: local + hooks: + - id: mypy + name: mypy + entry: mypy + language: system + types: [python] + require_serial: true + files: ^homeassistant/.+\.py$ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2b99393639..4beff14965b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,10 @@ +# This configuration includes the default, minimal set of hooks to be +# run on all commits. It requires no specific setup and one can just +# start using pre-commit with it. +# +# See .pre-commit-config-all.yaml for a more complete one that comes +# with a better coverage at the cost of some specific setup needed. + repos: - repo: https://github.com/psf/black rev: 19.10b0 @@ -15,17 +22,3 @@ repos: - flake8-docstrings==1.3.1 - pydocstyle==4.0.0 files: ^(homeassistant|script|tests)/.+\.py$ -# 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 -# another set of our dependencies there... no. Use the "system" one -# and reuse the environment that is set up anyway already instead. -- repo: local - hooks: - - id: mypy - name: mypy - entry: mypy - language: system - types: [python] - require_serial: true - files: ^homeassistant/.+\.py$ diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index f1abf2ff9db..e80f4b8d0ba 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -45,7 +45,7 @@ stages: . venv/bin/activate pip install -r requirements_test.txt -c homeassistant/package_constraints.txt - pre-commit install-hooks + pre-commit install-hooks --config .pre-commit-config-all.yaml - script: | . venv/bin/activate pre-commit run flake8 --all-files @@ -84,7 +84,7 @@ stages: . venv/bin/activate pip install -r requirements_test.txt -c homeassistant/package_constraints.txt - pre-commit install-hooks + pre-commit install-hooks --config .pre-commit-config-all.yaml - script: | . venv/bin/activate pre-commit run black --all-files @@ -182,8 +182,8 @@ stages: . venv/bin/activate pip install -e . -r requirements_test.txt -c homeassistant/package_constraints.txt - pre-commit install-hooks + pre-commit install-hooks --config .pre-commit-config-all.yaml - script: | . venv/bin/activate - pre-commit run mypy --all-files + pre-commit run --config .pre-commit-config-all.yaml mypy --all-files displayName: 'Run mypy' diff --git a/requirements_test.txt b/requirements_test.txt index f2935a423bf..06a2ef1621d 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -2,7 +2,7 @@ # make new things fail. Manually update these pins when pulling in a # new version -# When updating this file, update .pre-commit-config.yaml too +# When updating this file, update .pre-commit-config*.yaml too asynctest==0.13.0 black==19.10b0 codecov==2.0.15 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e757272a789..d7b4e4ffb01 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -3,7 +3,7 @@ # make new things fail. Manually update these pins when pulling in a # new version -# When updating this file, update .pre-commit-config.yaml too +# When updating this file, update .pre-commit-config*.yaml too asynctest==0.13.0 black==19.10b0 codecov==2.0.15 diff --git a/tox.ini b/tox.ini index f6d12fe30f5..118d0722b7c 100644 --- a/tox.ini +++ b/tox.ini @@ -41,4 +41,4 @@ deps = -r{toxinidir}/requirements_test.txt -c{toxinidir}/homeassistant/package_constraints.txt commands = - pre-commit run mypy {posargs: --all-files} + pre-commit run --config .pre-commit-config-all.yaml mypy {posargs: --all-files}