Skip to content

Commit 3ee6f1c

Browse files
committed
pybricksdev.connections.pybricks: restore PybricksHub.output
This attribute is used in motor test code in pybricks-micropython so should not be removed. Fixes: pybricks/support#1037
1 parent 67a3335 commit 3ee6f1c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
### Fixed
10+
- Restored `PybricksHub.output` attribute ([support#1037]).
11+
12+
[support#1037]: https://github.com/orgs/pybricks/discussions/1037
13+
914
## [1.0.0-alpha.43] - 2023-04-19
1015

1116
### Added

pybricksdev/connections/pybricks.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
import os
88
import struct
9-
from typing import Awaitable, Optional, TypeVar
9+
from typing import Awaitable, List, Optional, TypeVar
1010

1111
import reactivex.operators as op
1212
import semver
@@ -93,6 +93,16 @@ def __init__(self):
9393
# REVISIT: this can potentially waste a lot of RAM if not drained
9494
self._stdout_line_queue = asyncio.Queue()
9595

96+
# REVISIT: It would be better to be able to subscribe to output instead
97+
# of always capturing it even if it is not used. This is currently
98+
# used in motor test code in pybricks-micropython.
99+
self.output: List[bytes] = []
100+
"""
101+
Contains lines printed to stdout of the hub as a a list of bytes.
102+
103+
List is reset each time :meth:`run()` is called.
104+
"""
105+
96106
# prior to Pybricks Profile v1.3.0, NUS was used for stdio
97107
self._legacy_stdio = False
98108

@@ -148,6 +158,8 @@ def _line_handler(self, line: bytes) -> None:
148158
print(line_str, file=self.log_file)
149159
return
150160

161+
self.output.append(line)
162+
151163
if self.print_output:
152164
print(line_str)
153165
return
@@ -425,6 +437,7 @@ async def run(
425437

426438
# Reset output buffer
427439
self.log_file = None
440+
self.output = []
428441
self._stdout_buf.clear()
429442
self._stdout_line_queue = asyncio.Queue()
430443
self.print_output = print_output

0 commit comments

Comments
 (0)