Overhauled redirection and output capturing#1654
Merged
kmvanbrunt merged 18 commits intomainfrom Apr 29, 2026
Merged
Conversation
…d usage output during the parsing phase.
…when rendering argparse help.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1654 +/- ##
==========================================
- Coverage 99.49% 99.49% -0.01%
==========================================
Files 21 21
Lines 4741 4733 -8
==========================================
- Hits 4717 4709 -8
Misses 24 24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
tleonhardt
requested changes
Apr 29, 2026
tleonhardt
previously approved these changes
Apr 29, 2026
tleonhardt
previously approved these changes
Apr 29, 2026
tleonhardt
previously approved these changes
Apr 29, 2026
tleonhardt
approved these changes
Apr 29, 2026
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.
cmd2redirection now only captures output directed toself.stdout(e.g., viaself.poutput()). Standardprint()calls write directly tosys.stdoutand are not captured. However,print()calls withinpyscriptsand the interactive Python shell are treated as command output and sent toself.stdout, allowing them to be captured.This means we no longer alter the system-wide
sys.stdoutstream.To facilitate this change, our custom
argparsecode now writes all output toself.stdoutinstead ofsys.stdout.To support
pyscriptdevelopers who don't have access toself.stdout, theprint()function in that environment has been replaced with one that wrapsself.print_to(). It writes toself.stdoutby default and respects theallow_stylesetting. It also supports printingRichobjects. This means thatrun_pyscript script.py > out.txtwill capture anyprint()calls in the script.