switch to pre-commit

Switch to using pre-commit for linters. This consolodates our
codespell job into the general pep8 job. To ensure that CI matches what
users get and to not require users to do anything different, call
pre-commit from tox. Brought over some tox.ini differences from the
ironic repo.

Change-Id: Ic2af465a1f9446e9753cdd0d2d9d8c567df71dc1
Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
This commit is contained in:
Doug Goldstein 2024-09-17 15:05:35 -05:00
parent 1a3ce79a99
commit d40564de3e
No known key found for this signature in database
5 changed files with 72 additions and 26 deletions

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

@ -0,0 +1,56 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
args: ['--fix', 'lf']
exclude: |
(?x)(
.*.svg$|
)
- id: fix-byte-order-marker
- id: check-merge-conflict
- id: debug-statements
- id: check-json
files: .*\.json$
- id: check-yaml
files: .*\.(yaml|yml)$
exclude: releasenotes/.*$
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: remove-tabs
exclude: '.*\.(svg)$'
- repo: https://opendev.org/openstack/hacking
rev: 6.1.0
hooks:
- id: hacking
additional_dependencies: []
exclude: '^(doc|releasenotes|tools)/.*$'
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: [--write-changes]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v1.0.0
hooks:
- id: sphinx-lint
args: [--enable=default-role]
files: ^doc/|releasenotes|api-ref
- repo: https://opendev.org/openstack/bashate
rev: 2.1.0
hooks:
- id: bashate
args: ["-iE006,E044", "-eE005,E042"]
name: bashate
description: This hook runs bashate for linting shell scripts
entry: bashate
language: python
types: [shell]
- repo: https://github.com/PyCQA/doc8
rev: v1.1.2
hooks:
- id: doc8

View File

@ -2,3 +2,5 @@
requires = ["pbr>=6.0.0", "setuptools>=64.0.0"]
build-backend = "pbr.build"
[tool.doc8]
ignore = ["D001"]

29
tox.ini
View File

@ -1,28 +1,31 @@
[tox]
minversion = 4.4.0
envlist = py3,pep8
ignore_basepython_conflict=true
[testenv]
basepython = python3
constrain_package_deps = true
usedevelop = True
setenv =
VIRTUAL_ENV={envdir}
PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
PYTHONWARNINGS=default::DeprecationWarning
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:pep8]
deps=
hacking~=6.0.0 # Apache-2.0
flake8-import-order>=0.17.1 # LGPLv3
pycodestyle>=2.0.0,<3.0.0 # MIT
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
commands = flake8 {posargs}
deps = pre-commit
allowlist_externals = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure {posargs}
[testenv:codespell]
description =
Run codespell to check spelling
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure codespell
[testenv:venv]
setenv = PYTHONHASHSEED=0
@ -90,11 +93,3 @@ import-order-style = pep8
application-import-names = sushy
filename = *.py
[testenv:codespell]
description =
Run codespell to check spelling
deps = codespell
# note(JayF): {posargs} lets us run `tox -ecodespell -- -w` to get codespell
# to correct spelling issues in our code it's aware of.
commands =
codespell {posargs}

View File

@ -10,10 +10,8 @@
- ironic-cross-sushy
- sushy-tempest-bios-redfish-pxe
- sushy-tempest-uefi-redfish-vmedia
- sushy-tox-codespell
gate:
jobs:
- ironic-cross-sushy
- sushy-tempest-bios-redfish-pxe
- sushy-tempest-uefi-redfish-vmedia
- sushy-tox-codespell

View File

@ -3,6 +3,7 @@
parent: ironic-tempest-bios-redfish-pxe
irrelevant-files:
- ^.*\.rst$
- ^\.pre-commit-config\.yaml$
- ^doc/.*$
- ^test-requirements.txt$
- ^sushy/tests/.*$
@ -14,15 +15,9 @@
parent: ironic-tempest-uefi-redfish-vmedia
irrelevant-files:
- ^.*\.rst$
- ^\.pre-commit-config\.yaml$
- ^doc/.*$
- ^test-requirements.txt$
- ^sushy/tests/.*$
required-projects:
- openstack/sushy
- job:
name: sushy-tox-codespell
parent: openstack-tox
timeout: 7200
vars:
tox_envlist: codespell