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 <erik@montnemery.com>
This commit is contained in:
Volker Stolz 2024-04-23 17:13:25 +02:00 committed by GitHub
parent 90efe5ac90
commit 5e250d8a76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: