Skip to content

Commit

Permalink
pybricksdev/compile: use relative paths
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlech committed May 4, 2024
1 parent 73696c5 commit 76e5e1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Use relative paths when compiling multi-file projects.

## [1.0.0-alpha.48] - 2024-05-04

### Changed
Expand Down
5 changes: 4 additions & 1 deletion pybricksdev/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ async def compile_multi_file(path: str, abi: Union[int, Tuple[int, int]]):
for name, module in finder.modules.items():
if not module.__file__:
continue
mpy = await compile_file(module.__file__, abi_major)

relative_file = os.path.relpath(module.__file__, os.path.dirname(path))

mpy = await compile_file(relative_file, abi_major)

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

0 comments on commit 76e5e1d

Please sign in to comment.