From 1c6cfa1e4669d107d76e58b9cfdca3437add8dc6 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Thu, 19 Jul 2018 15:40:32 +0100 Subject: [PATCH] Run bashate via pre-commit Migrates bashate linting task to pre-commit in order to allow fast and transparent execution before uploading changes to gerrit. Other linters can be run as well, including flake8 and ansible-linter. This also lowers the footprint on developer machines because each linter/version is stored only once on disk, regardless how many repositories are using it. Only action needed for enabling pre-commit as a developer is to run `pip install pre-commit`, everything else is done transparently after. Partial-Bug: #1786286 Change-Id: I6ad834bbfbaf7645c542e4f922e89bc4449247c3 --- .pre-commit-config.yaml | 14 ++++++++++++++ test-requirements.txt | 2 +- tox.ini | 13 +------------ 3 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..c6c053b7e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +--- +repos: + - repo: https://github.com/openstack-dev/bashate.git + rev: 0.6.0 + hooks: + - id: bashate + entry: bashate --error . --verbose --ignore=E006,E040 + # Run bashate check for all bash scripts + # Ignores the following rules: + # E006: Line longer than 79 columns (as many scripts use jinja + # templating, this is very difficult) + # E040: Syntax error determined using `bash -n` (as many scripts + # use jinja templating, this will often fail and the syntax + # error will be discovered in execution anyway) diff --git a/test-requirements.txt b/test-requirements.txt index 698abc9fb..402a18ad8 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ openstackdocstheme>=1.11.0 # Apache-2.0 hacking<0.11,>=0.10 -bashate>=0.2 # Apache-2.0 +pre-commit>=1.10 # MIT License ansible-lint>=3.5.0 sphinx>=1.6.2 # BSD reno>=1.8.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 1e44d15c3..747da8e09 100644 --- a/tox.ini +++ b/tox.ini @@ -23,18 +23,7 @@ commands = python setup.py build_sphinx [testenv:bashate] commands = -# Run bashate check for all bash scripts -# Ignores the following rules: -# E006: Line longer than 79 columns (as many scripts use jinja -# templating, this is very difficult) -# E040: Syntax error determined using `bash -n` (as many scripts -# use jinja templating, this will often fail and the syntax -# error will be discovered in execution anyway) - bash -c "grep --recursive --binary-files=without-match \ - --files-with-match '^.!.*\(ba\)\?sh$' \ - --exclude-dir .tox \ - --exclude-dir .git \ - {toxinidir} | xargs bashate --error . --verbose --ignore=E006,E040" + python -m pre_commit run bashate --all-files [testenv:pep8] commands =