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 <work@seanmooney.info>
This commit is contained in:
Sean Mooney
2026-02-24 19:16:49 +00:00
parent 7b000ffddc
commit 631994f01e
9 changed files with 26 additions and 14 deletions

View File

@@ -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)/.*$'

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,3 @@
#!/usr/bin/python
# Copyright 2018 Intel, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may

View File

@@ -1,4 +1,3 @@
#!/usr/bin/python
# Copyright 2021 Intel, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may

View File

@@ -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

View File

@@ -1,4 +1,3 @@
#!/bin/bash
# plugin.sh - devstack plugin for cyborg
# devstack plugin contract defined at:

0
tools/flake8wrap.sh Normal file → Executable file
View File