Run mypy through a pyenv/virtualenv enabler wrapper script (#30922)
This commit is contained in:
parent
79495d9f3a
commit
dc5ca461a9
7 changed files with 38 additions and 73 deletions
|
@ -1,59 +0,0 @@
|
||||||
# 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://github.com/PyCQA/flake8
|
|
||||||
rev: 3.7.9
|
|
||||||
hooks:
|
|
||||||
- id: flake8
|
|
||||||
additional_dependencies:
|
|
||||||
- flake8-docstrings==1.5.0
|
|
||||||
- pydocstyle==5.0.2
|
|
||||||
files: ^(homeassistant|script|tests)/.+\.py$
|
|
||||||
- repo: https://github.com/PyCQA/bandit
|
|
||||||
rev: 1.6.2
|
|
||||||
hooks:
|
|
||||||
- id: bandit
|
|
||||||
args:
|
|
||||||
- --quiet
|
|
||||||
- --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
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v2.4.0
|
|
||||||
hooks:
|
|
||||||
- id: check-json
|
|
||||||
# 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$
|
|
|
@ -1,10 +1,3 @@
|
||||||
# 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:
|
repos:
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 19.10b0
|
rev: 19.10b0
|
||||||
|
@ -48,3 +41,16 @@ repos:
|
||||||
rev: v2.4.0
|
rev: v2.4.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-json
|
- id: check-json
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
# Run mypy through our wrapper script in order to get the possible
|
||||||
|
# pyenv and/or virtualenv activated; it may not have been e.g. if
|
||||||
|
# committing from a GUI tool that was not launched from an activated
|
||||||
|
# shell.
|
||||||
|
- id: mypy
|
||||||
|
name: mypy
|
||||||
|
entry: script/run-in-env.sh mypy
|
||||||
|
language: script
|
||||||
|
types: [python]
|
||||||
|
require_serial: true
|
||||||
|
files: ^homeassistant/.+\.py$
|
||||||
|
|
|
@ -43,7 +43,7 @@ stages:
|
||||||
|
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
|
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
|
||||||
pre-commit install-hooks --config .pre-commit-config-all.yaml
|
pre-commit install-hooks
|
||||||
- script: |
|
- script: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pre-commit run codespell --all-files
|
pre-commit run codespell --all-files
|
||||||
|
@ -98,7 +98,7 @@ stages:
|
||||||
|
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
|
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
|
||||||
pre-commit install-hooks --config .pre-commit-config-all.yaml
|
pre-commit install-hooks
|
||||||
- script: |
|
- script: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pre-commit run black --all-files --show-diff-on-failure
|
pre-commit run black --all-files --show-diff-on-failure
|
||||||
|
@ -194,8 +194,8 @@ stages:
|
||||||
|
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install -e . -r requirements_test.txt -c homeassistant/package_constraints.txt
|
pip install -e . -r requirements_test.txt -c homeassistant/package_constraints.txt
|
||||||
pre-commit install-hooks --config .pre-commit-config-all.yaml
|
pre-commit install-hooks
|
||||||
- script: |
|
- script: |
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pre-commit run --config .pre-commit-config-all.yaml mypy --all-files
|
pre-commit run mypy --all-files
|
||||||
displayName: 'Run mypy'
|
displayName: 'Run mypy'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Automatically generated from .pre-commit-config-all.yaml by gen_requirements_all.py, do not edit
|
# Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit
|
||||||
|
|
||||||
bandit==1.6.2
|
bandit==1.6.2
|
||||||
black==19.10b0
|
black==19.10b0
|
||||||
|
|
|
@ -253,7 +253,7 @@ def requirements_test_output(reqs):
|
||||||
|
|
||||||
def requirements_pre_commit_output():
|
def requirements_pre_commit_output():
|
||||||
"""Generate output for pre-commit dependencies."""
|
"""Generate output for pre-commit dependencies."""
|
||||||
source = ".pre-commit-config-all.yaml"
|
source = ".pre-commit-config.yaml"
|
||||||
pre_commit_conf = load_yaml(source)
|
pre_commit_conf = load_yaml(source)
|
||||||
reqs = []
|
reqs = []
|
||||||
for repo in (x for x in pre_commit_conf["repos"] if x.get("rev")):
|
for repo in (x for x in pre_commit_conf["repos"] if x.get("rev")):
|
||||||
|
|
18
script/run-in-env.sh
Executable file
18
script/run-in-env.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh -eu
|
||||||
|
|
||||||
|
# Activate pyenv and virtualenv if present, then run the specified command
|
||||||
|
|
||||||
|
# pyenv, pyenv-virtualenv
|
||||||
|
if [ -s .python-version ]; then
|
||||||
|
PYENV_VERSION=$(head -n 1 .python-version)
|
||||||
|
export PYENV_VERSION
|
||||||
|
fi
|
||||||
|
|
||||||
|
# other common virtualenvs
|
||||||
|
for venv in venv .venv .; do
|
||||||
|
if [ -f $venv/bin/activate ]; then
|
||||||
|
. $venv/bin/activate
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
exec "$@"
|
2
tox.ini
2
tox.ini
|
@ -45,4 +45,4 @@ deps =
|
||||||
-r{toxinidir}/requirements_test.txt
|
-r{toxinidir}/requirements_test.txt
|
||||||
-c{toxinidir}/homeassistant/package_constraints.txt
|
-c{toxinidir}/homeassistant/package_constraints.txt
|
||||||
commands =
|
commands =
|
||||||
pre-commit run --config .pre-commit-config-all.yaml mypy {posargs: --all-files}
|
pre-commit run mypy {posargs: --all-files}
|
||||||
|
|
Loading…
Add table
Reference in a new issue