From a46aea73bafae51bc6215a679c82226c415a5ed3 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 29 Sep 2026 00:11:47 +0200 Subject: [PATCH] Speed up hassfest dependencies plugin (#183500) --- script/hassfest/dependencies.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/script/hassfest/dependencies.py b/script/hassfest/dependencies.py index 33a3012764bb..3ae610773582 100644 --- a/script/hassfest/dependencies.py +++ b/script/hassfest/dependencies.py @@ -8,7 +8,6 @@ from pathlib import Path from homeassistant.const import Platform from homeassistant.requirements import DISCOVERY_INTEGRATIONS -from . import ast_parse_module from .model import Config, Integration # Duplicated from homeassistant.bootstrap to avoid importing bootstrap (and its @@ -35,13 +34,22 @@ class ImportCollector(ast.NodeVisitor): self._cur_fil_dir = fil.relative_to(self.integration.path) self.referenced[self._cur_fil_dir] = set() - try: - self.visit(ast_parse_module(fil)) - except SyntaxError as e: - e.add_note(f"File: {fil}") - raise + source = fil.read_text() + # Every reference contains this text, so skip parsing files without it + if "homeassistant.components" in source: + try: + self.visit(ast.parse(source)) + except SyntaxError as e: + e.add_note(f"File: {fil}") + raise self._cur_fil_dir = None + def generic_visit(self, node: ast.AST) -> None: + """Visit child statements only, imports never appear in expressions.""" + for field in ("body", "orelse", "finalbody", "handlers", "cases"): + for child in getattr(node, field, ()): + self.visit(child) + def _add_reference(self, reference_domain: str) -> None: """Add a reference.""" assert self._cur_fil_dir