From 87ca61ddd7e5316ba9e703e8145dfeeaf5a024fd Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Mon, 16 Dec 2019 11:06:17 +0100 Subject: [PATCH] Add check-json to CI and Pre-commit (#29912) * Add check-json to CI and Pre-commit * Add ignore pre-commit hooks to gen_requirements_all --- .pre-commit-config-all.yaml | 4 ++++ .pre-commit-config.yaml | 6 +++++- azure-pipelines-ci.yml | 4 ++++ script/gen_requirements_all.py | 7 +++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config-all.yaml b/.pre-commit-config-all.yaml index ec9492e0210d..1eabfcb0017c 100644 --- a/.pre-commit-config-all.yaml +++ b/.pre-commit-config-all.yaml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23d1d9c73f9c..226708bb9471 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: - repo: https://github.com/PyCQA/bandit rev: 1.6.2 hooks: - - id: bandit + - id: bandit args: - --quiet - --format=custom @@ -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 diff --git a/azure-pipelines-ci.yml b/azure-pipelines-ci.yml index 464b1079957c..78de90c85528 100644 --- a/azure-pipelines-ci.yml +++ b/azure-pipelines-ci.yml @@ -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' diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index 0dfefc958c35..f40a89a9d9a2 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -65,6 +65,8 @@ enum34==1000000000.0.0 pycrypto==1000000000.0.0 """ +IGNORE_PRE_COMMIT_HOOK_ID = ("check-json",) + def has_tests(module: str): """Test if a module has tests. @@ -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",