From f0b251d92422cec2d941c6598f8a0d7602c28225 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 28 Dec 2018 10:56:15 +0000 Subject: [PATCH] Run all linters via pre-commit Executes all linters via pre-commit, which is much faster, guarantees their version locking and allows upgrading them with a single command. Before this change the only linter running via pre-commit was ansible-lint. Now we also run bashate, flake8 and yamllint via pre-commit. For developer convenience we still keep the old tox environments which allow running a single linter. Change-Id: Ia0737c50de0f01de8576089d72de8940c16e9e0e --- .ansible-lint | 6 +++ .pre-commit-config.yaml | 47 ++++++++++++++++--- .yamllint | 4 +- LICENSE | 1 - ansible-role-requirements.yml | 2 +- ansible.cfg | 1 - devmode.sh | 1 - doc/source/basic-usage.rst | 2 - doc/source/conf.py | 1 + doc/source/rhosp.rst | 2 +- doc/source/troubleshoot.rst | 2 +- library/generate_macs.py | 10 ++-- .../notes/2.0.0-1579472457180d77.yaml | 1 - ...k-out-general-config-8a02f40113e58dbc.yaml | 1 - roles/virtbmc/tasks/main.yml | 2 +- setup.cfg | 6 +++ test-requirements.txt | 5 +- tox.ini | 44 ++++------------- zuul.d/layout.yaml | 1 + 19 files changed, 77 insertions(+), 62 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index 2bb3ffb29..c5400df30 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -1,5 +1,11 @@ +--- parseable: true skip_list: - ANSIBLE0006 - ANSIBLE0012 - ANSIBLE0016 + - '204' # [E204] Lines should be no longer than 120 chars + # E602 https://github.com/ansible/ansible-lint/issues/450 + - '602' # [E602] Don't compare to empty string + # E405 is too new and we need to enable it in a separate change + - '405' # [E405] Remote package tasks should have a retry diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e245a3bc5..0b2f2b735 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,42 @@ +--- repos: -- repo: https://github.com/willthames/ansible-lint.git - rev: v3.5.1 - hooks: - - id: ansible-lint - entry: env ANSIBLE_LIBRARY=./library ansible-lint - files: \.(yaml|yml)$ + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.1.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: flake8 + additional_dependencies: + - hacking<1.2.0,>=1.1.0 + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.14.0 + hooks: + - id: yamllint + files: \.(yaml|yml)$ + types: [file, yaml] + entry: yamllint --strict -f parsable + - repo: https://github.com/ansible/ansible-lint + rev: v4.0.1 + hooks: + - id: ansible-lint + files: \.(yaml|yml)$ + entry: env ANSIBLE_LIBRARY=./library ansible-lint --force-color -v + - 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/.yamllint b/.yamllint index 89e93b0c4..d13360a51 100644 --- a/.yamllint +++ b/.yamllint @@ -1,10 +1,12 @@ --- +extends: default rules: + document-start: disable line-length: max: 999 allow-non-breakable-words: true allow-non-breakable-inline-mappings: true key-duplicates: enable ignore: | - .tox \ No newline at end of file + .tox diff --git a/LICENSE b/LICENSE index 8f71f43fe..8dada3eda 100644 --- a/LICENSE +++ b/LICENSE @@ -199,4 +199,3 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - diff --git a/ansible-role-requirements.yml b/ansible-role-requirements.yml index d6b753858..9dfe9824f 100644 --- a/ansible-role-requirements.yml +++ b/ansible-role-requirements.yml @@ -1,5 +1,5 @@ +--- - name: image-build src: https://github.com/redhat-openstack/ansible-role-tripleo-image-build scm: git version: master - diff --git a/ansible.cfg b/ansible.cfg index 7479c5b3f..d022f81b1 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -20,4 +20,3 @@ pipelining = True control_path = %(directory)s/%%h-%%r ssh_args = -o ControlMaster=auto -o ControlPersist=270s -o ServerAliveInterval=30 -o GSSAPIAuthentication=no retries = 3 - diff --git a/devmode.sh b/devmode.sh index 9fba69498..db86e9cea 100755 --- a/devmode.sh +++ b/devmode.sh @@ -204,4 +204,3 @@ bash $BASE_QUICKSTART_DIR/ci-scripts/full-deploy.sh $RELEASE $BUILD_SYS $CONFIG popd - diff --git a/doc/source/basic-usage.rst b/doc/source/basic-usage.rst index 8323b2a39..6ad70efa4 100644 --- a/doc/source/basic-usage.rst +++ b/doc/source/basic-usage.rst @@ -125,5 +125,3 @@ The full documentation is in the ``doc/source`` directory, it can be built using:: tox -e docs - - diff --git a/doc/source/conf.py b/doc/source/conf.py index f99cf758d..81a6fb255 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/doc/source/rhosp.rst b/doc/source/rhosp.rst index f6f55c91f..86a274deb 100644 --- a/doc/source/rhosp.rst +++ b/doc/source/rhosp.rst @@ -41,4 +41,4 @@ An example invocation of TripleO-Quickstart:: ./quickstart.sh -R rhos-11-rhn-baseos-undercloud -E baseos_rhel_libvirt --tags all $VIRTHOST -[1] `product subscription documentation `_ \ No newline at end of file +[1] `product subscription documentation `_ diff --git a/doc/source/troubleshoot.rst b/doc/source/troubleshoot.rst index 572fca4db..cd994941e 100644 --- a/doc/source/troubleshoot.rst +++ b/doc/source/troubleshoot.rst @@ -18,4 +18,4 @@ the directory. Alternatively, you can manually remove the directory before executing ``quickstart.sh``. - rm -r ~/.quickstart \ No newline at end of file + rm -r ~/.quickstart diff --git a/library/generate_macs.py b/library/generate_macs.py index 59ad16dde..f304c6f75 100644 --- a/library/generate_macs.py +++ b/library/generate_macs.py @@ -15,6 +15,9 @@ # generate_baremetal_macs method ripped from # openstack/tripleo-incubator/scripts/configure-vm +import math +import random + DOCUMENTATION = ''' --- module: generate_macs @@ -24,9 +27,6 @@ description: - Generate a list of Ethernet MAC addresses suitable for baremetal testing. ''' -import math -import random - MAX_NUM_MACS = math.trunc(0xff / 2) @@ -86,6 +86,8 @@ def main(): module.exit_json(**result) # see http://docs.ansible.com/developing_modules.html#common-module-boilerplate -from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.basic import AnsibleModule # noqa + + if __name__ == '__main__': main() diff --git a/releasenotes/notes/2.0.0-1579472457180d77.yaml b/releasenotes/notes/2.0.0-1579472457180d77.yaml index 96d82c268..c25df5f0b 100644 --- a/releasenotes/notes/2.0.0-1579472457180d77.yaml +++ b/releasenotes/notes/2.0.0-1579472457180d77.yaml @@ -39,4 +39,3 @@ other: - Undercloud deploy role moved to tripleo-quickstart-extras - Added repo configuration to the release configs for usage by the repo-setup role in tripleo-quickstart-extras - diff --git a/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml b/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml index c2de7db71..afbe4db91 100644 --- a/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml +++ b/releasenotes/notes/break-out-general-config-8a02f40113e58dbc.yaml @@ -23,4 +23,3 @@ deprecations: tested into featureset files. For example, the old minimal.yml file was split into no_netiso.yml and 1ctlr_1comp.yml - diff --git a/roles/virtbmc/tasks/main.yml b/roles/virtbmc/tasks/main.yml index d177166d4..13242b2cf 100644 --- a/roles/virtbmc/tasks/main.yml +++ b/roles/virtbmc/tasks/main.yml @@ -2,4 +2,4 @@ - name: Include VBMC setup if enabled include_tasks: configure-vbmc.yml - when: enable_vbmc|bool \ No newline at end of file + when: enable_vbmc|bool diff --git a/setup.cfg b/setup.cfg index 9cbfbe3c9..f5fbb8374 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,3 +37,9 @@ universal = 1 [pbr] skip_authors = True skip_changelog = True + +[flake8] +# E123, E125 skipped as they are invalid PEP-8. +show-source = True +ignore = E123,E125 +builtins = _ diff --git a/test-requirements.txt b/test-requirements.txt index 640fe306c..cca8b7756 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,9 +1,6 @@ openstackdocstheme>=1.11.0 # Apache-2.0 -hacking<0.11,>=0.10 -bashate>=0.2 # Apache-2.0 docutils>=0.11 sphinx>=1.6.2 # BSD reno>=1.8.0 # Apache-2.0 -yamllint # GPLv3 -pre-commit # MIT \ No newline at end of file +pre-commit # MIT diff --git a/tox.ini b/tox.ini index de9486d7a..606f57166 100644 --- a/tox.ini +++ b/tox.ini @@ -26,49 +26,27 @@ basepython = python3 commands = python setup.py build_sphinx [testenv:bashate] +envdir = {toxworkdir}/linters 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 "git ls-files | xargs grep --binary-files=without-match \ - --files-with-match '^.!.*\(ba\)\?sh$' \ - --exclude-dir .tox \ - --exclude-dir .git \ - | xargs bashate --error . --verbose --ignore=E006,E040" + python -m pre_commit run bashate -a [testenv:pep8] -basepython = python3 +envdir = {toxworkdir}/linters commands = - # Run hacking/flake8 check for all python files - bash -c "git ls-files | xargs grep --binary-files=without-match \ - --files-with-match '^.!.*python$' \ - --exclude-dir .tox \ - --exclude-dir .git \ - --exclude-dir .eggs \ - --exclude-dir *.egg-info \ - --exclude-dir dist \ - --exclude-dir *lib/python* \ - --exclude-dir doc \ - | xargs flake8 --verbose" + python -m pre_commit run flake8 -a [testenv:ansible-lint] -basepython=python2 setenv = ANSIBLE_LIBRARY=./library +envdir = {toxworkdir}/linters commands = - python -m pre_commit run --all-files + python -m pre_commit run ansible-lint -a [testenv:linters] basepython = python3 commands = - python -m yamllint . - {[testenv:bashate]commands} - {[testenv:pep8]commands} - {[testenv:ansible-lint]commands} + # check only modified files: + python -m pre_commit run -a [testenv:releasenotes] basepython = python3 @@ -79,9 +57,3 @@ commands = bash -c ci-scripts/releasenotes_tox.sh changedir = {toxinidir} commands = {posargs:echo done} - -[flake8] -# E123, E125 skipped as they are invalid PEP-8. -show-source = True -ignore = E123,E125 -builtins = _ diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index 6f07f35e5..cb7b6fa93 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -1,3 +1,4 @@ +--- - project: templates: - tripleo-undercloud-jobs