feat: oxidize open_stream
Metadata
Current evaluation
Merged PR #416 restored Rust-backed Emitter.open_stream(), refactoring Printer to static state and adding Emitter.init_logger(). It built on prerequisite emitter oxidation in #411.
Resolution: closed resolved
Reason: PR #416 received approval from two reviewers and was merged, completing the CRAFT-4964 open_stream oxidation based on prerequisite PR #411.
Evaluated by: mr-cal-bot
No scores available.
Issue body
- [x] Have you followed the guidelines for contributing?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] Have you successfully run `make lint && make test`?
---
This is based on (and thus requires) #411. The diff will be pretty noisy until it is merged.
I recommend not reviewing the code directly until I've had an opportunity to clean up the commit history once #411 lands, but this can be tested using the scripts below in the meantime.
This PR adds the `open_stream` method back to the emitter. This required refactoring the `Printer` class to not solely exist as a field on an `Emitter` instance, as the stream handler object needed access too. Now, the `Printer` is a global, static variable that gets initialized upon the first print. For similar reasons, the logging mechanism has been moved into the printer and must be explicitly initialized via the new `Emitter.init_logger()`.
Here is some example code to test the changes:
```py
# testing.py
import subprocess
from craft_cli import EmitterMode
from craft_cli._rs.emitter import Emitter
e = Emitter("blah.log", EmitterMode.TRACE, "example.com", "hello from rust!")
e.init_logger()
with e.open_stream() as stream:
subprocess.run(["bash", "testing.sh"], stdout=stream, stderr=stream)
```
```bash
# testing.sh
for i in {1..6}; do
echo $i
sleep 1
done
```
Known bugs: It seems that trace-level events (and perhaps others?) duplicate the timestamp in logs (tracked in CRAFT 4999). Also, the `text` parameter for `open_stream` is missing until CRAFT 4968 is complete, as otherwise the two tasks would duplicate work to add prefix behaviors.
CRAFT-4964.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #416 restored Rust-backed Emitter.open_stream(), refactoring Printer to static state and adding Emitter.init_logger(). It built on prerequisite emitter oxidation in #411. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #416 restored Rust-backed Emitter.open_stream(), refactoring Printer to static state and adding Emitter.init_logger(). It built on prerequisite emitter oxidation in #411. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged oxidized open_stream implementation. Refactored Printer into a global static variable and moved logging into it, requiring explicit initialization via Emitter.init_logger(). Depends on PR 411. Merged despite some failing CI tests. |
Update history
No update history recorded yet.
Related work
-
Related To:
craft-cli#411
(confidence 100%)
Required prerequisite PR that first replaced the Python emitter with its Rust extension.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #411 feat: oxidize the emitter | craft-cli | merged | Merged #411 reimplemented Craft CLI's emitter in Rust with PyO3/Maturin, removed global emit, and switched the build backend. | |
| #419 feat: oxidize streaming_brief feature | craft-cli | merged | Merged in canonical/craft-cli#419, restoring streaming_brief output and prefixing messages piped through Emitter.open_stream. |