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
This commit is contained in:
Sorin Sbarnea 2019-06-14 16:59:40 +01:00
parent 1111d4ad0d
commit 6d152eaf98
7 changed files with 85 additions and 38 deletions

11
.ansible-lint Normal file
View File

@ -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

36
.pre-commit-config.yaml Normal file
View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

53
tox.ini
View File

@ -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 =

View File

@ -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: