mirror of
https://github.com/esphome/esphome.git
synced 2026-10-04 10:09:13 +00:00
[substitutions] !include ${filename}, Substitutions in include filename paths (package refactor part 5) (#12213)
Co-authored-by: J. Nick Koston <nick@home-assistant.io> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
co-authored by
J. Nick Koston
J. Nick Koston
parent
801f3fadaa
commit
d20d613c1d
@@ -0,0 +1,25 @@
|
||||
"""Helpers for detecting substitution variables and Jinja expressions."""
|
||||
|
||||
import re
|
||||
|
||||
from esphome.const import VALID_SUBSTITUTIONS_CHARACTERS
|
||||
|
||||
SUBSTITUTION_VARIABLE_PROG = re.compile(
|
||||
rf"\$([{VALID_SUBSTITUTIONS_CHARACTERS}]+|\{{[{VALID_SUBSTITUTIONS_CHARACTERS}]*\}})"
|
||||
)
|
||||
|
||||
_JINJA_RE = re.compile(
|
||||
r"<%.+?%>" # Block: <% ... %>
|
||||
r"|\$\{[^}]+\}", # Braced: ${ ... }
|
||||
flags=re.MULTILINE,
|
||||
)
|
||||
|
||||
|
||||
def has_jinja(value: str) -> bool:
|
||||
"""Check if a string contains Jinja expressions."""
|
||||
return _JINJA_RE.search(value) is not None
|
||||
|
||||
|
||||
def has_substitution_or_expression(value: str) -> bool:
|
||||
"""Check if a string contains substitution variables ($name, ${name}) or Jinja expressions."""
|
||||
return SUBSTITUTION_VARIABLE_PROG.search(value) is not None or has_jinja(value)
|
||||
Reference in New Issue
Block a user