From 9706ebcd1859fdfdce6bc1176df0d6eb5d41a543 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 24 Jun 2025 00:11:06 +0900 Subject: [PATCH] Switch to pre-commit This borrows the existing setting from sushy, which was added by [1], to apply the consistent checks. Note that flake8-import-order is additionally enabled in this change, while it is being restored in sushy by [2]. [1] https://review.opendev.org/c/openstack/sushy/+/929704 [2] https://review.opendev.org/c/openstack/sushy/+/953124 Co-Authored-By: Doug Goldstein Change-Id: I8520821579f523bb74b20d0ba44ec4cc574a26bc --- .pre-commit-config.yaml | 38 ++++++++++++++++++++++ sushy_tools/emulator/templates/system.json | 2 +- tox.ini | 24 +++++--------- 3 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..7e8d7f67 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +--- +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$ + exclude: sushy_tools/emulator/templates/.*$ + - 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: + - flake8-import-order>=0.19,<0.20 + exclude: '^(doc|releasenotes|tools)/.*$' + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + args: [--write-changes] diff --git a/sushy_tools/emulator/templates/system.json b/sushy_tools/emulator/templates/system.json index c019b99f..3065b840 100644 --- a/sushy_tools/emulator/templates/system.json +++ b/sushy_tools/emulator/templates/system.json @@ -35,7 +35,7 @@ "BootSourceOverrideMode": {{ boot_source_mode|string|tojson }} {%- endif %} {%- else %} - "Hdd" + "Hdd" ] {%- endif %} {%- else %} diff --git a/tox.ini b/tox.ini index a599327f..0a9f8308 100644 --- a/tox.ini +++ b/tox.ini @@ -18,12 +18,15 @@ commands = stestr run {posargs} stestr slowest [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] commands = {posargs} @@ -67,12 +70,3 @@ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build import-order-style = pep8 application-import-names = sushy_tools 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}