Skip to content

Commit

Permalink
Run mypy through a pyenv/virtualenv enabler wrapper script (home-assi…
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored Feb 1, 2020
1 parent 79495d9 commit dc5ca46
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 73 deletions.
59 changes: 0 additions & 59 deletions .pre-commit-config-all.yaml

This file was deleted.

20 changes: 13 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
- repo: https://github.com/psf/black
rev: 19.10b0
Expand Down Expand Up @@ -48,3 +41,16 @@ repos:
rev: v2.4.0
hooks:
- 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$
8 changes: 4 additions & 4 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ stages:
. venv/bin/activate
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: |
. venv/bin/activate
pre-commit run codespell --all-files
Expand Down Expand Up @@ -98,7 +98,7 @@ stages:
. venv/bin/activate
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: |
. venv/bin/activate
pre-commit run black --all-files --show-diff-on-failure
Expand Down Expand Up @@ -194,8 +194,8 @@ stages:
. venv/bin/activate
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: |
. venv/bin/activate
pre-commit run --config .pre-commit-config-all.yaml mypy --all-files
pre-commit run mypy --all-files
displayName: 'Run mypy'
2 changes: 1 addition & 1 deletion requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
@@ -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
black==19.10b0
Expand Down
2 changes: 1 addition & 1 deletion script/gen_requirements_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def requirements_test_output(reqs):

def requirements_pre_commit_output():
"""Generate output for pre-commit dependencies."""
source = ".pre-commit-config-all.yaml"
source = ".pre-commit-config.yaml"
pre_commit_conf = load_yaml(source)
reqs = []
for repo in (x for x in pre_commit_conf["repos"] if x.get("rev")):
Expand Down
18 changes: 18 additions & 0 deletions script/run-in-env.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ deps =
-r{toxinidir}/requirements_test.txt
-c{toxinidir}/homeassistant/package_constraints.txt
commands =
pre-commit run --config .pre-commit-config-all.yaml mypy {posargs: --all-files}
pre-commit run mypy {posargs: --all-files}

0 comments on commit dc5ca46

Please sign in to comment.