Skip to content

Commit a1a8a56

Browse files
committed
pybricksdev/compile.py: Add better error message
When compiling multi-file projects that contain a namespace pacakge (folder without __init__.py), we hit Python bug python/cpython#84530. This adds a try/except block to catch the error and raise a more helpful error message. Issue: pybricks/support#1602
1 parent 978c346 commit a1a8a56

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Changed
1010
- Use relative paths when compiling multi-file projects.
11+
- Better error message when hitting Python bug when compiling multi-file projects.
1112

1213
### Fixed
1314
- Fixed `pybricksdev` BLE commands not working on Windows when `pythoncom`

pybricksdev/compile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ async def compile_multi_file(path: str, abi: Union[int, Tuple[int, int]]):
116116
# compile files using Python to find imports contained within the same directory as path
117117
search_path = [os.path.dirname(path)]
118118
finder = ModuleFinder(search_path)
119-
finder.run_script(path)
119+
120+
try:
121+
finder.run_script(path)
122+
except AttributeError as e:
123+
raise RuntimeError(
124+
"ModuleFinder doesn't currently handle implicit namespace packages. Did you forget to put an __init__.py file in one of your subdirectories? See https://github.com/pybricks/support/issues/1602"
125+
) from e
120126

121127
# we expect missing modules, namely builtin MicroPython packages like pybricks.*
122128
logger.debug("missing modules: %r", finder.any_missing())

0 commit comments

Comments
 (0)