Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pybricksdev/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
import logging
import os
import sys
from modulefinder import ModuleFinder
from typing import List, Optional

Expand Down Expand Up @@ -123,12 +124,26 @@ async def compile_multi_file(path: str, abi: int):
parts: List[bytes] = []

for name, module in finder.modules.items():
if not module.__file__:
continue # system module
mpy = await compile_file(module.__file__, abi)

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

# look for .mpy modules
for name in finder.any_missing():
for path in sys.path:
try:
with open(os.path.join(path, f"{name}.mpy"), "rb") as f:
mpy = f.read()
parts.append(len(mpy).to_bytes(4, "little"))
parts.append(name.encode() + b"\x00")
parts.append(mpy)
except IOError:
continue

return b"".join(parts)


Expand Down