fix(run) Fix live / streaming / flushing of output#493
Merged
Conversation
Live updates were broken, e.g. flushing of output during `git clone`
Reviewer's GuideThis PR restores live output streaming by switching subprocess pipes to bytes mode, decoding output with a new utility to preserve carriage returns, and refactoring how stderr and stdout are read and decoded. Class diagram for ProgressCallbackProtocol and process function changesclassDiagram
class ProgressCallbackProtocol {
+__call__(output: str, timestamp: datetime.datetime) -> None
}
class process {
+console_to_str(s: bytes) -> str
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #493 +/- ##
==========================================
- Coverage 54.09% 54.05% -0.04%
==========================================
Files 40 40
Lines 3627 3637 +10
Branches 793 794 +1
==========================================
+ Hits 1962 1966 +4
- Misses 1314 1319 +5
- Partials 351 352 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey @tony - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/libvcs/_internal/run.py:25` </location>
<code_context>
logger = logging.getLogger(__name__)
+console_encoding = sys.stdout.encoding
+
+
</code_context>
<issue_to_address>
sys.stdout.encoding may be None in some environments.
If console_encoding is None, provide a fallback like 'utf-8' to avoid potential TypeError when decoding.
</issue_to_address>
### Comment 2
<location> `src/libvcs/_internal/run.py:228` </location>
<code_context>
if callback and callable(callback) and proc.stderr is not None:
- line = str(proc.stderr.read(128))
+ line = console_to_str(proc.stderr.read(128))
if line:
callback(output=line, timestamp=datetime.datetime.now())
</code_context>
<issue_to_address>
Reading fixed-size chunks may split multibyte characters.
This approach can cause decode errors or corrupted output. Buffer the data and decode only complete lines, or use an incremental decoder to handle multibyte characters correctly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #485.
Live updates were broken, e.g. flushing of output during
git cloneSummary by Sourcery
Fix live streaming and flushing of subprocess output in
run.pyby switching to byte-mode I/O, preserving carriage returns for progress updates, and decoding output via a console-encoding fallback.Bug Fixes:
console_to_strhelper that tries the console’s encoding and falls back to UTF-8Enhancements:
console_to_str