From 6d152eaf98ab6903e598ca66baf731a6aa4a4d5b Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 14 Jun 2019 16:59:40 +0100 Subject: [PATCH] Linting hardening via pre-commit Ease linting by using pre-commit to manage execution of all linters. That change does not require any changes for user, they still can trigger the linting using `tox -e pep8`. Also syncs sphinx requirements with global openstaco ones as these were broken but the check job runs only when the file is touched. Change-Id: Ib07e40f1f87a33474ae9412ddf5ba359eb5d5068 --- .ansible-lint | 11 +++++++++ .pre-commit-config.yaml | 36 ++++++++++++++++++++++++++++ lower-constraints.txt | 3 --- setup.cfg | 12 ++++++++++ test-requirements.txt | 3 --- tox.ini | 53 ++++++++++++++++++----------------------- zuul.d/layout.yaml | 5 ++-- 7 files changed, 85 insertions(+), 38 deletions(-) create mode 100644 .ansible-lint create mode 100644 .pre-commit-config.yaml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 000000000..c5400df30 --- /dev/null +++ b/.ansible-lint @@ -0,0 +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 new file mode 100644 index 000000000..14efd7595 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,36 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.2.3 + hooks: + - 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: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://gitlab.com/pycqa/flake8 + rev: '3.7.7' + hooks: + - id: flake8 + - repo: https://github.com/ansible/ansible-lint + rev: v4.1.0a0 + hooks: + - id: ansible-lint + files: \.(yaml|yml)$ + exclude: ^workbooks/ + entry: 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,E042 + # 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/lower-constraints.txt b/lower-constraints.txt index b2b0feb93..ec1c6e599 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -2,7 +2,6 @@ alabaster==0.7.10 appdirs==1.3.0 asn1crypto==0.23.0 Babel==2.3.4 -bashate==0.2 cffi==1.7.0 cliff==2.8.0 cmd2==0.8.0 @@ -20,11 +19,9 @@ eventlet==0.20.0 extras==1.0.0 fasteners==0.7.0 fixtures==3.0.0 -flake8==2.5.5 futures==3.0.0;python_version=='2.7' or python_version=='2.6' gitdb==0.6.4 GitPython==1.0.1 -hacking==0.12.0 idna==2.6 imagesize==0.7.1 iso8601==0.1.11 diff --git a/setup.cfg b/setup.cfg index 111e2de47..0b6a635dc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -170,3 +170,15 @@ mistral.actions = [tool:pytest] norecursedirs = .git .tox dist log_cli = true + +[flake8] +show-source = True +# E123, E125 skipped as they are invalid PEP-8. +# W504/W503 are mutually exclusive and we should avoid them until community +# will pick a winner. +ignore = E123,E125,W503,W504 +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,releasenotes +builtins = _ + +[pycodestyle] +exclude = .eggs,.tox \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index ba693029d..aec5dbe71 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,8 +4,6 @@ openstackdocstheme>=1.18.1 # Apache-2.0 -hacking>=1.1.0,<1.2.0 # Apache-2.0 - coverage!=4.4,>=4.0 # Apache-2.0 docutils>=0.11 # OSI-Approved Open Source, Public Domain python-subunit>=1.0.0 # Apache-2.0/BSD @@ -18,5 +16,4 @@ testtools>=2.2.0 # MIT PyYAML>=3.12 # MIT reno>=2.5.0 # Apache-2.0 urllib3>=1.21.1 # MIT -bashate>=0.2 # Apache-2.0 requests-mock>=1.2.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index f138e3c1b..a1e861d6f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.8 -envlist = pep8,py37,py36,py27,molecule +envlist = linters,py37,py36,py27,molecule skipsdist = True [testenv] @@ -30,16 +30,20 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt commands = stestr run {posargs} -whitelist_externals = bash +whitelist_externals = + bash + tox [testenv:bindep] deps = bindep commands = bash -c "{toxinidir}/scripts/bindep-install" +# deprecated: covered by linters [testenv:pep8] -basepython = python3 -commands = flake8 - bash -c tools/check_duplicate_jinja_blocks.sh +skip_install = true +deps = +commands = + tox -e linters -- flake8 [testenv:venv] basepython = python3 @@ -65,22 +69,12 @@ commands = python setup.py build_sphinx basepython = python3 commands = oslo_debug_helper {posargs} +# deprecated: covered by linters [testenv:bashate] -basepython = python3 +skip_install = true +deps = 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,E042" - + tox -e linters -- bashate [testenv:molecule] deps = ansi2html @@ -96,17 +90,12 @@ deps = commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {posargs:roles} -[flake8] -# E123, E125 skipped as they are invalid PEP-8. - -show-source = True -ignore = E123,E125 -builtins = _ -exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,releasenotes - -[testenv:releasenotes] -basepython = python3 -commands = bash -c tools/releasenotes_tox.sh +[testenv:linters] +skip_install = true +deps = pre-commit +commands = + python -m pre_commit run -a {posargs:} + bash -c tools/check_duplicate_jinja_blocks.sh [testenv:lower-constraints] basepython = python3 @@ -115,6 +104,10 @@ deps = -r{toxinidir}/test-requirements.txt -r{toxinidir}/requirements.txt +[testenv:releasenotes] +basepython = python3 +commands = bash -c tools/releasenotes_tox.sh + [testenv:requirements] basepython = python3 deps = diff --git a/zuul.d/layout.yaml b/zuul.d/layout.yaml index 3bd398609..1c403c49b 100644 --- a/zuul.d/layout.yaml +++ b/zuul.d/layout.yaml @@ -14,14 +14,14 @@ - tripleo-standalone-scenarios-full check: jobs: - - openstack-tox-pep8 + - openstack-tox-linters - openstack-tox-py27 - openstack-tox-py35 - openstack-tox-py36 - openstack-tox-py37 - tripleo-ci-centos-7-containers-multinode: dependencies: &deps_unit_lint - - openstack-tox-pep8 + - openstack-tox-linters - openstack-tox-py27 - openstack-tox-py35 - openstack-tox-py36 @@ -80,6 +80,7 @@ gate: queue: tripleo jobs: + - openstack-tox-linters - openstack-tox-lower-constraints - tripleo-ci-centos-7-scenario009-multinode-oooq-container: files: