Skip to content

Commit dc5ca46

Browse files
authored
Run mypy through a pyenv/virtualenv enabler wrapper script (home-assistant#30922)
1 parent 79495d9 commit dc5ca46

7 files changed

+38
-73
lines changed

.pre-commit-config-all.yaml

-59
This file was deleted.

.pre-commit-config.yaml

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# This configuration includes the default, minimal set of hooks to be
2-
# run on all commits. It requires no specific setup and one can just
3-
# start using pre-commit with it.
4-
#
5-
# See .pre-commit-config-all.yaml for a more complete one that comes
6-
# with a better coverage at the cost of some specific setup needed.
7-
81
repos:
92
- repo: https://github.com/psf/black
103
rev: 19.10b0
@@ -48,3 +41,16 @@ repos:
4841
rev: v2.4.0
4942
hooks:
5043
- id: check-json
44+
- repo: local
45+
hooks:
46+
# Run mypy through our wrapper script in order to get the possible
47+
# pyenv and/or virtualenv activated; it may not have been e.g. if
48+
# committing from a GUI tool that was not launched from an activated
49+
# shell.
50+
- id: mypy
51+
name: mypy
52+
entry: script/run-in-env.sh mypy
53+
language: script
54+
types: [python]
55+
require_serial: true
56+
files: ^homeassistant/.+\.py$

azure-pipelines-ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ stages:
4343
4444
. venv/bin/activate
4545
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
46-
pre-commit install-hooks --config .pre-commit-config-all.yaml
46+
pre-commit install-hooks
4747
- script: |
4848
. venv/bin/activate
4949
pre-commit run codespell --all-files
@@ -98,7 +98,7 @@ stages:
9898
9999
. venv/bin/activate
100100
pip install -r requirements_test.txt -c homeassistant/package_constraints.txt
101-
pre-commit install-hooks --config .pre-commit-config-all.yaml
101+
pre-commit install-hooks
102102
- script: |
103103
. venv/bin/activate
104104
pre-commit run black --all-files --show-diff-on-failure
@@ -194,8 +194,8 @@ stages:
194194
195195
. venv/bin/activate
196196
pip install -e . -r requirements_test.txt -c homeassistant/package_constraints.txt
197-
pre-commit install-hooks --config .pre-commit-config-all.yaml
197+
pre-commit install-hooks
198198
- script: |
199199
. venv/bin/activate
200-
pre-commit run --config .pre-commit-config-all.yaml mypy --all-files
200+
pre-commit run mypy --all-files
201201
displayName: 'Run mypy'

requirements_test_pre_commit.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automatically generated from .pre-commit-config-all.yaml by gen_requirements_all.py, do not edit
1+
# Automatically generated from .pre-commit-config.yaml by gen_requirements_all.py, do not edit
22

33
bandit==1.6.2
44
black==19.10b0

script/gen_requirements_all.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def requirements_test_output(reqs):
253253

254254
def requirements_pre_commit_output():
255255
"""Generate output for pre-commit dependencies."""
256-
source = ".pre-commit-config-all.yaml"
256+
source = ".pre-commit-config.yaml"
257257
pre_commit_conf = load_yaml(source)
258258
reqs = []
259259
for repo in (x for x in pre_commit_conf["repos"] if x.get("rev")):

script/run-in-env.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh -eu
2+
3+
# Activate pyenv and virtualenv if present, then run the specified command
4+
5+
# pyenv, pyenv-virtualenv
6+
if [ -s .python-version ]; then
7+
PYENV_VERSION=$(head -n 1 .python-version)
8+
export PYENV_VERSION
9+
fi
10+
11+
# other common virtualenvs
12+
for venv in venv .venv .; do
13+
if [ -f $venv/bin/activate ]; then
14+
. $venv/bin/activate
15+
fi
16+
done
17+
18+
exec "$@"

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ deps =
4545
-r{toxinidir}/requirements_test.txt
4646
-c{toxinidir}/homeassistant/package_constraints.txt
4747
commands =
48-
pre-commit run --config .pre-commit-config-all.yaml mypy {posargs: --all-files}
48+
pre-commit run mypy {posargs: --all-files}

0 commit comments

Comments
 (0)