From 631994f01e77cdca578f8f1dc68cb0e954a59639 Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Tue, 24 Feb 2026 19:16:49 +0000 Subject: [PATCH] Update pre-commit hooks and fix violations Replace the local flake8 hook with upstream pre-commit-hooks, autopep8, and openstack/hacking. Add hooks for JSON validation, shebang/executable consistency, large file detection, and case-conflict checks. we use the hacking hook to provide the correct version fo flake8 instead of usign the local flake8 hook and addtionally installing hacking. Fix violations caught by the new hooks: - Remove spurious shebangs from non-executable module files (fpga and nic prepare_test_data.py, devstack lib and plugin) - Make tools/flake8wrap.sh executable to match its shebang - Exclude *-curl.json doc samples from JSON validation (they contain curl commands, not bare JSON) - Fix PEP8 blank line spacing in devspec.py and middleware Generated-By: claude-code sonnet 4.6 Change-Id: Ideda2a6d1f31765484bfacc05ebba0785d427968 Signed-off-by: Sean Mooney --- .pre-commit-config.yaml | 29 ++++++++++++++----- cyborg/accelerator/drivers/pci/devspec.py | 3 ++ cyborg/api/middleware/auth_token.py | 1 + cyborg/api/middleware/parsable_error.py | 1 + .../drivers/fpga/intel/prepare_test_data.py | 1 - .../drivers/nic/intel/prepare_test_data.py | 1 - devstack/lib/cyborg | 3 -- devstack/plugin.sh | 1 - tools/flake8wrap.sh | 0 9 files changed, 26 insertions(+), 14 deletions(-) mode change 100755 => 100644 cyborg/tests/unit/accelerator/drivers/fpga/intel/prepare_test_data.py mode change 100644 => 100755 tools/flake8wrap.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 44e5c685..a2972973 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,23 +6,36 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: + # whitespace - id: trailing-whitespace - id: mixed-line-ending args: ['--fix', 'lf'] exclude: '.*\.(svg)$' - id: fix-byte-order-marker + # file format and permissions - id: check-executables-have-shebangs - - id: check-merge-conflict + - id: check-shebang-scripts-are-executable - id: debug-statements - id: check-yaml files: .*\.(yaml|yml)$ - - repo: local + - id: check-json + files: .*\.json$ + exclude: .*-curl.*\.json$ + - id: check-ast + # git + - id: check-added-large-files + - id: check-case-conflict + - id: detect-private-key + - id: check-merge-conflict + exclude: '.*\.(rst|inc)$' + - repo: https://github.com/hhatto/autopep8 + rev: v2.3.2 hooks: - - id: flake8 - name: flake8 - additional_dependencies: - - hacking>=3.0.1,<3.1.0 - language: python - entry: flake8 + - id: autopep8 files: '^.*\.py$' + - repo: https://opendev.org/openstack/hacking + rev: 7.0.0 + hooks: + - id: hacking + additional_dependencies: [] exclude: '^(doc|releasenotes|tools)/.*$' diff --git a/cyborg/accelerator/drivers/pci/devspec.py b/cyborg/accelerator/drivers/pci/devspec.py index 91ad68a7..565f60d3 100644 --- a/cyborg/accelerator/drivers/pci/devspec.py +++ b/cyborg/accelerator/drivers/pci/devspec.py @@ -71,6 +71,7 @@ class PhysicalPciAddress(PciAddressSpec): This function class will validate the address fields for a single PCI device. """ + def __init__(self, pci_addr): try: if isinstance(pci_addr, dict): @@ -147,6 +148,7 @@ class PciAddressRegexSpec(PciAddressSpec): The validation includes check for all PCI address attributes and validate their regex. """ + def __init__(self, pci_addr): try: self.domain = pci_addr.get('domain', REGEX_ANY) @@ -188,6 +190,7 @@ class WhitelistPciAddress(object): | passthrough_whitelist = {"vendor_id":"1137","product_id":"0071"} """ + def __init__(self, pci_addr, is_physical_function): self.is_physical_function = is_physical_function self._init_address_fields(pci_addr) diff --git a/cyborg/api/middleware/auth_token.py b/cyborg/api/middleware/auth_token.py index ab445d2c..74c4d10a 100644 --- a/cyborg/api/middleware/auth_token.py +++ b/cyborg/api/middleware/auth_token.py @@ -33,6 +33,7 @@ class AuthTokenMiddleware(auth_token.AuthProtocol): for public routes in the API. """ + def __init__(self, app, conf, public_api_routes=None): public_api_routes = public_api_routes or [] self.app = app diff --git a/cyborg/api/middleware/parsable_error.py b/cyborg/api/middleware/parsable_error.py index 2a52b0fe..563980be 100644 --- a/cyborg/api/middleware/parsable_error.py +++ b/cyborg/api/middleware/parsable_error.py @@ -25,6 +25,7 @@ from oslo_serialization import jsonutils class ParsableErrorMiddleware(object): """Replace error body with something the client can parse.""" + def __init__(self, app): self.app = app diff --git a/cyborg/tests/unit/accelerator/drivers/fpga/intel/prepare_test_data.py b/cyborg/tests/unit/accelerator/drivers/fpga/intel/prepare_test_data.py old mode 100755 new mode 100644 index 68bd548c..e1093850 --- a/cyborg/tests/unit/accelerator/drivers/fpga/intel/prepare_test_data.py +++ b/cyborg/tests/unit/accelerator/drivers/fpga/intel/prepare_test_data.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright 2018 Intel, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cyborg/tests/unit/accelerator/drivers/nic/intel/prepare_test_data.py b/cyborg/tests/unit/accelerator/drivers/nic/intel/prepare_test_data.py index 49a133f6..9ef91e93 100644 --- a/cyborg/tests/unit/accelerator/drivers/nic/intel/prepare_test_data.py +++ b/cyborg/tests/unit/accelerator/drivers/nic/intel/prepare_test_data.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # Copyright 2021 Intel, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/devstack/lib/cyborg b/devstack/lib/cyborg index 631f6704..163e7abd 100644 --- a/devstack/lib/cyborg +++ b/devstack/lib/cyborg @@ -1,5 +1,3 @@ -#!/bin/bash -# # lib/cyborg # Functions to control the configuration and operation of the **Cyborg** service @@ -286,4 +284,3 @@ function cyborg_configure_tempest { # Restore xtrace + pipefail $_XTRACE_CYBORG $_PIPEFAIL_CYBORG - diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 041271a1..5e5316a1 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -1,4 +1,3 @@ -#!/bin/bash # plugin.sh - devstack plugin for cyborg # devstack plugin contract defined at: diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh old mode 100644 new mode 100755