From 48946e8588b2b4db392c3eca99852385d293c439 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 28 Jan 2020 09:25:44 +0000 Subject: [PATCH] Fix tox.ini misconfigurations Previous setup introduce several problems because pre-commit was never run with all configured hooks. New setup does not require any changes to tox.ini when new linters/hooks are added. - openstack-tox-pep8 removed, replaced by generic linters - fixed bug where CI did not run all linters, mainly because of tox.ini env layout - kept only one linters environment with its sole requirement - saved considerable amount of time wasted installing unused dependencies - moved doc8 config to setup.cfg (standard location) Change-Id: Idda6418ea1dcc3877e078f3cd9c59631fcc2ec68 --- setup.cfg | 5 ++++ test-requirements.txt | 1 - tox.ini | 67 ++++++++++--------------------------------- 3 files changed, 20 insertions(+), 53 deletions(-) diff --git a/setup.cfg b/setup.cfg index 90be9a2..d7886a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,3 +50,8 @@ skip_changelog = True # based on https://github.com/psf/black ignore = E203,E501,W503,W504,D # "D" added because we do not use docstrings checks, yet + +[doc8] +# Settings for doc8: +extensions = .rst +ignore = D001 diff --git a/test-requirements.txt b/test-requirements.txt index 93e532e..b621105 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,3 @@ -pre-commit # MIT netaddr # BSD mock>=2.0.0 # BSD stestr>=2.0.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index c2ab5de..77f4dac 100644 --- a/tox.ini +++ b/tox.ini @@ -42,55 +42,21 @@ whitelist_externals = deps = bindep commands = bindep test +[testenv:linters] +description = + Runs all linters, if you want to run a single one, use posargs to mention + it. Example `tox -e linters -- ansible-lint` +deps = + pre-commit>=1.20 # MIT +commands = + python -m pre_commit run -a {posargs} + +# Use 'linters' instead, kept only for compatibility with: +# https://opendev.org/openstack/openstack-zuul-jobs/src/branch/master/zuul.d/project-templates.yaml#L459 [testenv:pep8] envdir = {toxworkdir}/linters -commands = - python -m pre_commit run flake8 -a - -[testenv:ansible-lint] -envdir = {toxworkdir}/linters -deps = - {[testenv:linters]deps} -commands = - python -m pre_commit run ansible-lint -a -# bash -c "ANSIBLE_ROLES_PATH='{toxinidir}/roles' \ -# ansible-galaxy install -fr {toxinidir}/ansible-role-requirements.yml" - -[testenv:yamllint] -envdir = {toxworkdir}/linters -deps = {[testenv:linters]deps} -commands = - python -m pre_commit run yamllint -a - -[testenv:bashate] -envdir = {toxworkdir}/linters -deps = {[testenv:linters]deps} -commands = - python -m pre_commit run bashate -a - -[testenv:whitespace] -envdir = {toxworkdir}/linters -deps = {[testenv:linters]deps} -commands = - python -m pre_commit run trailing-whitespace -a - -[testenv:shebangs] -envdir = {toxworkdir}/linters -deps = {[testenv:linters]deps} -commands = - python -m pre_commit run check-executables-have-shebangs -a - -[testenv:linters] -deps = - -r {toxinidir}/requirements.txt - -r {toxinidir}/test-requirements.txt -commands = - {[testenv:pep8]commands} - {[testenv:ansible-lint]commands} - {[testenv:bashate]commands} - {[testenv:yamllint]commands} - {[testenv:whitespace]commands} - {[testenv:shebangs]commands} +deps = {[testenv:linters]deps} +commands = {[testenv:linters]commands} [testenv:releasenotes] basepython = python3 @@ -106,11 +72,6 @@ commands= doc8 doc sphinx-build -a -E -W -d doc/build/doctrees --keep-going -b html doc/source doc/build/html -T -[doc8] -# Settings for doc8: -extensions = .rst -ignore = D001 - [testenv:venv] commands = {posargs} @@ -140,3 +101,5 @@ deps = oslotest commands = python -m pytest -ra --continue-on-collection-errors -v --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} -k {posargs} + +# do not put tool config in tox.ini, use setup.cfg or tool specific files