[ci] Block new CONF_ constants from being added to esphome/const.py (#15145)

This commit is contained in:
Jonathan Swoboda
2026-03-24 15:31:08 -04:00
committed by GitHub
parent b3390d40fb
commit 3cd50f0495

View File

@@ -525,6 +525,29 @@ def lint_constants_usage():
return errs
# Maximum allowed CONF_ constants in esphome/const.py.
# This file is frozen — new constants go in esphome/components/const/__init__.py.
# Decrease this number when constants are moved out of const.py.
CONST_PY_MAX_CONF = 1011
@lint_content_check(include=["esphome/const.py"])
def lint_const_py_frozen(fname, content):
"""Block new CONF_ constants from being added to esphome/const.py.
New constants should go in esphome/components/const/__init__.py instead.
"""
count = sum(1 for line in content.splitlines() if line.startswith("CONF_"))
if count > CONST_PY_MAX_CONF:
return (
"esphome/const.py is frozen. "
"Add new constants to esphome/components/const/__init__.py instead."
)
if count < CONST_PY_MAX_CONF:
return f"CONST_PY_MAX_CONF in ci-custom.py should be updated to {count}."
return None
def relative_cpp_search_text(fname: Path, content) -> str:
parts = fname.parts
integration = parts[2]