mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
Fix load_yaml returning unresolved IncludeFile for top-level !include
Move the IncludeFile resolution into _load_yaml_internal so all callers get resolved content, rather than patching individual call sites.
This commit is contained in:
@@ -599,9 +599,14 @@ def _load_yaml_internal(fname: Path) -> Any:
|
||||
listener(fname)
|
||||
try:
|
||||
with fname.open(encoding="utf-8") as f_handle:
|
||||
return parse_yaml(fname, f_handle)
|
||||
res = parse_yaml(fname, f_handle)
|
||||
except (UnicodeDecodeError, OSError) as err:
|
||||
raise EsphomeError(f"Error reading file {fname}: {err}") from err
|
||||
# Top-level !include returns a deferred IncludeFile; resolve it so
|
||||
# callers always receive the final content.
|
||||
if isinstance(res, IncludeFile):
|
||||
res = res.load()
|
||||
return res
|
||||
|
||||
|
||||
def parse_yaml(file_name: Path, file_handle: TextIOWrapper, yaml_loader=None) -> Any:
|
||||
|
||||
@@ -221,9 +221,6 @@ def analyze_yaml_file(yaml_file: Path) -> dict[str, Any]:
|
||||
|
||||
try:
|
||||
data = yaml_util.load_yaml(yaml_file)
|
||||
# Top-level !include returns an IncludeFile that must be resolved
|
||||
if isinstance(data, yaml_util.IncludeFile):
|
||||
data = data.load()
|
||||
result["loaded"] = True
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
return result
|
||||
|
||||
@@ -27,7 +27,6 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from esphome import yaml_util
|
||||
from esphome.config_helpers import merge_config
|
||||
from esphome.yaml_util import IncludeFile
|
||||
from script.analyze_component_buses import PACKAGE_DEPENDENCIES, get_common_bus_packages
|
||||
|
||||
# Prefix for dependency markers in package tracking
|
||||
@@ -47,12 +46,7 @@ def load_yaml_file(yaml_file: Path) -> dict:
|
||||
if not yaml_file.exists():
|
||||
raise FileNotFoundError(f"YAML file not found: {yaml_file}")
|
||||
|
||||
data = yaml_util.load_yaml(yaml_file)
|
||||
# Top-level !include (e.g., `!include common.yaml`) returns an IncludeFile
|
||||
# that must be resolved before we can work with it as a dict.
|
||||
if isinstance(data, IncludeFile):
|
||||
data = data.load()
|
||||
return data
|
||||
return yaml_util.load_yaml(yaml_file)
|
||||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
|
||||
Reference in New Issue
Block a user