Skip to content

Commit 76e5e1d

Browse files
committed
pybricksdev/compile: use relative paths
In `compile_multi_file()` modules other than the main one were not using relative paths. This worked but resulted in the full path being compiled into the the resulting .mpy file which takes up more space. This change makes sure that all modules are compiled with relative paths instead.
1 parent 73696c5 commit 76e5e1d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- Use relative paths when compiling multi-file projects.
11+
912
## [1.0.0-alpha.48] - 2024-05-04
1013

1114
### Changed

pybricksdev/compile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ async def compile_multi_file(path: str, abi: Union[int, Tuple[int, int]]):
129129
for name, module in finder.modules.items():
130130
if not module.__file__:
131131
continue
132-
mpy = await compile_file(module.__file__, abi_major)
132+
133+
relative_file = os.path.relpath(module.__file__, os.path.dirname(path))
134+
135+
mpy = await compile_file(relative_file, abi_major)
133136

134137
parts.append(len(mpy).to_bytes(4, "little"))
135138
parts.append(name.encode() + b"\x00")

0 commit comments

Comments
 (0)