Run benchmarks when top-level esphome Python modules change

This commit is contained in:
J. Nick Koston
2026-08-05 19:44:36 -05:00
parent 2dfcde477f
commit de0e7621cc
4 changed files with 83 additions and 3 deletions
+12 -3
View File
@@ -63,6 +63,7 @@ from helpers import (
CPP_FILE_EXTENSIONS,
ESPHOME_TESTS_COMPONENTS_PATH,
PYTHON_FILE_EXTENSIONS,
base_python_changed,
changed_files,
core_changed,
filter_component_and_test_cpp_files,
@@ -662,11 +663,14 @@ def should_run_benchmarks(branch: str | None = None) -> bool:
Benchmarks run when any of the following conditions are met:
1. Core C++ files changed (esphome/core/*)
2. The host platform changed (esphome/components/host/*) — benchmarks
2. Top-level Python modules changed (esphome/*.py) — the Python
benchmarks exercise config loading (config.py, yaml_util.py, ...),
so a slowdown there is invisible unless the benchmarks job runs
3. The host platform changed (esphome/components/host/*) — benchmarks
are built and run on the host platform, so its implementations of
``millis()``/``micros()``/etc. affect every benchmark
3. A directly changed component has benchmark files (no dependency expansion)
4. Benchmark infrastructure changed (tests/benchmarks/*, script/cpp_benchmark.py,
4. A directly changed component has benchmark files (no dependency expansion)
5. Benchmark infrastructure changed (tests/benchmarks/*, script/cpp_benchmark.py,
script/build_helpers.py, script/setup_codspeed_lib.py)
Unlike unit tests, benchmarks do NOT expand to dependent components.
@@ -683,6 +687,11 @@ def should_run_benchmarks(branch: str | None = None) -> bool:
if core_changed(files):
return True
# Top-level esphome/*.py modules are what the Python benchmarks in
# tests/benchmarks/python/ exercise
if base_python_changed(files):
return True
# Host platform supplies the runtime that benchmarks execute on
if any(f.startswith("esphome/components/host/") for f in files):
return True
+21
View File
@@ -1380,6 +1380,27 @@ def core_changed(files: list[str]) -> bool:
)
def base_python_changed(files: list[str]) -> bool:
"""Check if any Python module directly in esphome/ has changed.
Matches top-level modules like esphome/config.py and esphome/yaml_util.py
but not files in subdirectories such as esphome/components/ or
esphome/dashboard/.
Args:
files: List of file paths to check
Returns:
True if any top-level esphome Python module has changed
"""
return any(
f.startswith("esphome/")
and f.endswith(PYTHON_FILE_EXTENSIONS)
and "/" not in f.removeprefix("esphome/")
for f in files
)
def get_cpp_changed_components(files: list[str]) -> list[str]:
"""Get components that have changed C++ files or tests.