Skip to content

Commit

Permalink
Add check-json to CI and Pre-commit (home-assistant#29912)
Browse files Browse the repository at this point in the history
* Add check-json to CI and Pre-commit

* Add ignore pre-commit hooks to gen_requirements_all
  • Loading branch information
frenck authored and balloob committed Dec 16, 2019
1 parent d1e59b2 commit 87ca61d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ repos:
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
Expand Down
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.6.2
hooks:
- id: bandit
- id: bandit
args:
- --quiet
- --format=custom
Expand All @@ -35,3 +35,7 @@ repos:
rev: v4.3.21
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-json
4 changes: 4 additions & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ stages:
. venv/bin/activate
pre-commit run isort --all-files
displayName: 'Run isort'
- script: |
. venv/bin/activate
pre-commit run check-json --all-files
displayName: 'Run check-json'
- job: 'Validate'
pool:
vmImage: 'ubuntu-latest'
Expand Down
7 changes: 5 additions & 2 deletions script/gen_requirements_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
pycrypto==1000000000.0.0
"""

IGNORE_PRE_COMMIT_HOOK_ID = ("check-json",)


def has_tests(module: str):
"""Test if a module has tests.
Expand Down Expand Up @@ -256,8 +258,9 @@ def requirements_pre_commit_output():
reqs = []
for repo in (x for x in pre_commit_conf["repos"] if x.get("rev")):
for hook in repo["hooks"]:
reqs.append(f"{hook['id']}=={repo['rev']}")
reqs.extend(x for x in hook.get("additional_dependencies", ()))
if hook["id"] not in IGNORE_PRE_COMMIT_HOOK_ID:
reqs.append(f"{hook['id']}=={repo['rev']}")
reqs.extend(x for x in hook.get("additional_dependencies", ()))
output = [
f"# Automatically generated "
f"from {source} by {Path(__file__).name}, do not edit",
Expand Down

0 comments on commit 87ca61d

Please sign in to comment.