From 5e250d8a76a88f1fcc91fa4a12b926f3c1ce0f43 Mon Sep 17 00:00:00 2001 From: Volker Stolz Date: Tue, 23 Apr 2024 17:13:25 +0200 Subject: [PATCH] Augment SyntaxError raised during dependency collection with offending filename (#109204) * Capture parsing exception when collecting dependencies and augment with offending filename. Whereas before any syntax error in some component-file would result in an opaque SyntaxError without pointing out the file, now the result will show as: ``` File "/usr/local/Cellar/python@3.11/3.11.7_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/pool.py", line 873, in next raise value SyntaxError: Can't parse file homeassistant/components/your/file.py ``` * tweak * D'oh, had pre-commit hook still off. --------- Co-authored-by: Erik Montnemery --- script/hassfest/dependencies.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/hassfest/dependencies.py b/script/hassfest/dependencies.py index 6fe7700cb3f..1547bc1e829 100644 --- a/script/hassfest/dependencies.py +++ b/script/hassfest/dependencies.py @@ -32,7 +32,11 @@ class ImportCollector(ast.NodeVisitor): self._cur_fil_dir = fil.relative_to(self.integration.path) self.referenced[self._cur_fil_dir] = set() - self.visit(ast.parse(fil.read_text())) + try: + self.visit(ast.parse(fil.read_text())) + except SyntaxError as e: + e.add_note(f"File: {fil}") + raise self._cur_fil_dir = None def _add_reference(self, reference_domain: str) -> None: