[core] Enable ruff PGH (pygrep-hooks) lint family (#16651)

This commit is contained in:
J. Nick Koston
2026-05-26 15:29:54 -05:00
committed by GitHub
parent 96816e2491
commit 52ead52ef2
10 changed files with 22 additions and 15 deletions

View File

@@ -56,7 +56,7 @@ from esphome.types import ConfigType
from esphome.writer import clean_build, clean_cmake_cache
from .boards import BOARDS, STANDARD_BOARDS
from .const import ( # noqa
from .const import (
KEY_ARDUINO_LIBRARIES,
KEY_BOARD,
KEY_COMPONENTS,
@@ -86,7 +86,7 @@ from .const import ( # noqa
)
# force import gpio to register pin schema
from .gpio import esp32_pin_to_code # noqa
from .gpio import esp32_pin_to_code # noqa: F401
_LOGGER = logging.getLogger(__name__)
AUTO_LOAD = ["preferences"]

View File

@@ -14,7 +14,7 @@ from esphome.core import CORE
from .const import KEY_HOST
# force import gpio to register pin schema
from .gpio import host_pin_to_code # noqa
from .gpio import host_pin_to_code # noqa: F401
CODEOWNERS = ["@esphome/core", "@clydebarrow"]
AUTO_LOAD = ["network", "preferences"]

View File

@@ -28,7 +28,7 @@ from esphome.core.config import BOARD_MAX_LENGTH
from esphome.helpers import copy_file_if_changed
from esphome.storage_json import StorageJSON
from . import gpio # noqa
from . import gpio # noqa: F401
from .const import (
COMPONENT_BK72XX,
CONF_GPIO_RECOVER,

View File

@@ -1,7 +1,7 @@
# Copyright (c) Kuba Szczodrzyński 2023-06-01.
# pylint: skip-file
# flake8: noqa
# ruff: noqa: C408, I001
import json
import re
@@ -313,8 +313,12 @@ def write_const(
# build component constants
comp_str = "\n".join(f'COMPONENT_{f} = "{f.lower()}"' for f in components)
# replace the 2nd regex group only
repl = lambda m: m.group(1) + comp_str + m.group(3)
code = re.sub(comp_regex, repl, code, flags=re.DOTALL | re.MULTILINE)
code = re.sub(
comp_regex,
lambda m: m.group(1) + comp_str + m.group(3),
code,
flags=re.DOTALL | re.MULTILINE,
)
# regex for finding the family list block
fam_regex = r"(# FAMILIES.+?\n)(.*?)(\n# FAMILIES)"
@@ -337,8 +341,12 @@ def write_const(
]
var_str = "\n".join(fam_lines)
# replace the 2nd regex group only
repl = lambda m: m.group(1) + var_str + m.group(3)
code = re.sub(fam_regex, repl, code, flags=re.DOTALL | re.MULTILINE)
code = re.sub(
fam_regex,
lambda m: m.group(1) + var_str + m.group(3),
code,
flags=re.DOTALL | re.MULTILINE,
)
# format with black
code = format_str(code, mode=FileMode())

View File

@@ -58,7 +58,7 @@ from .effects import (
RGB_EFFECTS,
validate_effects,
)
from .types import ( # noqa
from .types import ( # noqa: F401
AddressableLight,
AddressableLightState,
ColorMode,

View File

@@ -514,7 +514,7 @@ def validate_printf(value):
(?:hh|h|ll|l|j|z|t|L|w|I|I32|I64)? # size
[cCdiouxXeEfgGaAnpsSZ] # type
)
""" # noqa
"""
matches = re.findall(cfmt, value[CONF_FORMAT], flags=re.VERBOSE)
if len(matches) != len(value[CONF_ARGS]):
raise cv.Invalid(

View File

@@ -6,7 +6,6 @@ from esphome.const import CONF_ARGS, CONF_FORMAT
CONF_IF_NAN = "if_nan"
# noqa
f_regex = re.compile(
r"""
( # start of capture group 1
@@ -20,7 +19,6 @@ f_regex = re.compile(
""",
flags=re.VERBOSE,
)
# noqa
c_regex = re.compile(
r"""
( # start of capture group 1

View File

@@ -65,7 +65,7 @@ from .const import (
)
# force import gpio to register pin schema
from .gpio import nrf52_pin_to_code # noqa
from .gpio import nrf52_pin_to_code # noqa: F401
CODEOWNERS = ["@tomaszduda23"]
AUTO_LOAD = ["zephyr", "preferences"]

View File

@@ -50,7 +50,7 @@ from .const import (
)
# force import gpio to register pin schema
from .gpio import rp2040_pin_to_code # noqa
from .gpio import rp2040_pin_to_code # noqa: F401
_LOGGER = logging.getLogger(__name__)
CODEOWNERS = ["@jesserockz"]

View File

@@ -127,6 +127,7 @@ select = [
"LOG", # flake8-logging
"NPY", # numpy-specific rules
"PERF", # performance
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PTH", # flake8-use-pathlib