Skip to content

Commit 31ec2dc

Browse files
committed
compile: Add option for binary output.
1 parent 35d1cb2 commit 31ec2dc

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
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+
### Added
10+
- Added the `--bin` option to the `compile` command.
11+
912
## [2.2.0] - 2025-10-25
1013

1114
### Added

pybricksdev/cli/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ def add_parser(self, subparsers: argparse._SubParsersAction):
115115
choices=[5, 6],
116116
type=int,
117117
)
118+
parser.add_argument(
119+
"--bin",
120+
action="store_true",
121+
help="output unformatted binary data only (useful for pipes)",
122+
)
118123
parser.tool = self
119124

120125
async def run(self, args: argparse.Namespace):
121126
from pybricksdev.compile import compile_multi_file, print_mpy
122127

123128
with _get_script_path(args.file) as script_path:
124129
mpy = await compile_multi_file(script_path, args.abi)
130+
if args.bin:
131+
sys.stdout.buffer.write(mpy)
132+
return
125133
print_mpy(mpy)
126134

127135

tests/test_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ async def test_compile_file(self):
503503
args = argparse.Namespace(
504504
file=stack.enter_context(open(temp_path, "r", encoding="utf-8")),
505505
abi=6,
506+
bin=False,
506507
)
507508

508509
# Mock the compile function
@@ -537,6 +538,7 @@ async def test_compile_stdin(self):
537538
args = argparse.Namespace(
538539
file=mock_stdin,
539540
abi=6,
541+
bin=False,
540542
)
541543

542544
# Mock the compile function and tempfile

0 commit comments

Comments
 (0)