Added `$XONSH_TRACE_SUBPROC=3` (#5459)

Show std if `$XONSH_TRACE_SUBPROC=3`.

### Motivation

* It's very helpful if you want to understand how subproc is working. 
* It's helpful to trace `SpecModifierAlias`.
* It's helpful to trace cases like #2618

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andy Kipp 2024-05-31 12:50:25 +02:00 committed by GitHub
parent a953c29443
commit aaf3c99a3b
Failed to generate hash of commit
2 changed files with 40 additions and 5 deletions

23
news/trace3.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* Added mode ``$XONSH_TRACE_SUBPROC=3`` to show more information about pipeline.
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -958,7 +958,7 @@ def _trace_specs(trace_mode, specs, cmds, captured):
else:
r = {"cmds": cmds, "captured": captured}
print(f"Trace run_subproc({repr(r)})", file=sys.stderr)
if trace_mode == 2:
if trace_mode >= 2:
for i, s in enumerate(specs):
pcls = s.cls.__module__ + "." + s.cls.__name__
pcmd = (
@ -967,11 +967,23 @@ def _trace_specs(trace_mode, specs, cmds, captured):
p = {
"cmd": pcmd,
"cls": pcls,
"alias": s.alias_name,
"bin": s.binary_loc,
"threadable": s.threadable,
"bg": s.background,
}
p |= {
a: getattr(s, a, None)
for a in ["alias_name", "binary_loc", "threadable", "background"]
}
if trace_mode == 3:
p |= {
a: getattr(s, a, None)
for a in [
"stdin",
"stdout",
"stderr",
"captured",
"captured_stdout",
"captured_stderr",
]
}
p = {k: v for k, v in p.items() if v is not None}
print(f"{i}: {repr(p)}", file=sys.stderr)