From b612bde7fa81214b5f52bf7fafa2515357844dc8 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Fri, 24 Jan 2025 23:11:07 -0500 Subject: [PATCH] migrate lints to pre-commit Migrated the existing lints to pre-commit and switched some over to ruff to follow the changes that have landed in the ironic repo. Change-Id: I361ca1b8d4ac9738f9c45ba6a87c377f5aca22a8 Signed-off-by: Doug Goldstein --- .pre-commit-config.yaml | 88 +++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 11 ++++++ tox.ini | 18 ++------- 3 files changed, 102 insertions(+), 15 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 000000000..96defa272 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,88 @@ +--- +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + # NOTE(cardoe): release notes aren't modifed after their release + exclude: | + (?x)( + ^releasenotes/notes/check-if-ESP-is-mounted-f9e0eff3609c2668.yaml$| + ^releasenotes/notes/fix-high-cpu-usage-eventlet-1dccf3b81dd42c47.yaml$| + ^releasenotes/notes/image-security-5c23b890409101c9.yaml$| + ^releasenotes/notes/software-raid-use-label-as-rootfs-uuid-d9a3827180f1a238.yaml$| + ) + - 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: | + (?x)( + .*.svg$| + ^ironic_python_agent/tests/unit/test_efi_utils.py$| + ) + - 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,E003", "-eE005,E042"] + name: bashate + description: This hook runs bashate for linting shell scripts + entry: bashate + language: python + types: [shell] + - repo: https://github.com/PyCQA/bandit + rev: 1.7.10 + hooks: + - id: bandit + args: ["-x", "tests/", "-n5", "-ll", "-c", "tools/bandit.yml"] + name: bandit + description: 'Bandit is a tool for finding common security issues in Python code' + entry: bandit + language: python + language_version: python3 + types: [ python ] + require_serial: true + - repo: https://github.com/PyCQA/doc8 + rev: v1.1.2 + hooks: + - id: doc8 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.3 + hooks: + - id: ruff + args: ['--fix', '--unsafe-fixes'] diff --git a/pyproject.toml b/pyproject.toml index 5e862a959..ec2802ecf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,14 @@ [build-system] requires = ["pbr>=6.0.0", "setuptools>=64.0.0"] build-backend = "pbr.build" + +[tool.ruff] +line-length = 79 + +[tool.ruff.lint] +select = [ + "E", # pycodestyle (error) + "F", # pyflakes + "G", # flake8-logging-format + "LOG", # flake8-logging +] diff --git a/tox.ini b/tox.ini index 3f8f8e0ba..5a9a83f79 100644 --- a/tox.ini +++ b/tox.ini @@ -46,21 +46,9 @@ setenv = commands = stestr run {posargs} [testenv:pep8] -deps = - hacking~=6.1.0 # Apache-2.0 - bashate~=2.1.0 # Apache-2.0 - flake8-import-order~=0.18.0 # LGPLv3 - pycodestyle>=2.0.0,<3.0.0 # MIT - doc8~=1.1.0 # Apache-2.0 - -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -allowlist_externals = bash - {toxinidir}/tools/run_bashate.sh -commands = - flake8 {posargs:ironic_python_agent examples} - # Run bashate during pep8 runs to ensure violations are caught by - # the check and gate queues. - {toxinidir}/tools/run_bashate.sh {toxinidir} - doc8 doc/source README.rst examples/README.rst +deps = pre-commit +allowlist_externals = pre-commit +commands = pre-commit run --all-files --show-diff-on-failure {posargs} [testenv:cover] setenv = VIRTUAL_ENV={envdir}