From 3a608314c491ef43d1e0a15ddcb0d4fd9556df41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 18 Oct 2019 03:12:58 +0300 Subject: [PATCH] Mypy setup fixes (#27825) * Install our core dependencies for mypy in azure To match local setups and tox. * Use "system" mypy in pre-commit instead of the "real" mypy hook The results of mypy 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. * Reintroduce needed ruamel.yaml type ignore This ignore is required when ruamel.yaml is installed, and we want it to be as it's part of the core dependency set. --- .pre-commit-config.yaml | 14 +++++++++++--- azure-pipelines-ci.yml | 4 ++-- homeassistant/util/ruamel_yaml.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48d77cfdc6f..3773a3213aa 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,9 +13,17 @@ repos: additional_dependencies: - flake8-docstrings==1.3.1 - pydocstyle==4.0.0 -- repo: https://github.com/pre-commit/mirrors-mypy.git - rev: v0.730 +# 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 - args: [] + name: mypy + entry: mypy + language: system + types: [python] + require_serial: true exclude: ^script/scaffold/templates/ diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index a566baf6561..257eac57c2d 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -174,12 +174,12 @@ stages: steps: - template: templates/azp-step-cache.yaml@azure parameters: - keyfile: 'requirements_test.txt | homeassistant/package_constraints.txt' + keyfile: 'requirements_test.txt | setup.py | homeassistant/package_constraints.txt' build: | python -m venv venv . venv/bin/activate - pip install -r requirements_test.txt -c homeassistant/package_constraints.txt + pip install -e . -r requirements_test.txt -c homeassistant/package_constraints.txt - script: | . venv/bin/activate mypy homeassistant diff --git a/homeassistant/util/ruamel_yaml.py b/homeassistant/util/ruamel_yaml.py index 6793784abae..b7e8927888c 100644 --- a/homeassistant/util/ruamel_yaml.py +++ b/homeassistant/util/ruamel_yaml.py @@ -90,7 +90,7 @@ def load_yaml(fname: str, round_trip: bool = False) -> JSON_TYPE: if round_trip: yaml = YAML(typ="rt") # type ignore: https://bitbucket.org/ruamel/yaml/pull-requests/42 - yaml.preserve_quotes = True + yaml.preserve_quotes = True # type: ignore else: if ExtSafeConstructor.name is None: ExtSafeConstructor.name = fname