This commit is contained in:
a 2024-04-25 22:45:22 +02:00 committed by Noorhteen Raja NJ
parent 71ab4d2aeb
commit c9d87ab9b5
2 changed files with 24 additions and 21 deletions

View file

@ -1186,9 +1186,11 @@ The file should contain a function with the signature
" - ptk style name (string) - ``$XONSH_STYLE_OVERRIDES['pygments.keyword'] = '#ff0000'``\n\n" " - ptk style name (string) - ``$XONSH_STYLE_OVERRIDES['pygments.keyword'] = '#ff0000'``\n\n"
"(The rules above are all have the same effect.)", "(The rules above are all have the same effect.)",
) )
XONSH_TRACE_SUBPROC = Var.with_default( XONSH_TRACE_SUBPROC = Var(
False, default=always_false,
"Set to ``True`` to show arguments list of every executed subprocess command.", convert=to_bool_or_int,
doc="Set to ``True`` or ``1`` to show arguments list of every executed subprocess command. "
"Use ``2`` to have full specification.",
) )
XONSH_TRACE_COMPLETIONS = Var.with_default( XONSH_TRACE_COMPLETIONS = Var.with_default(
False, False,

View file

@ -887,28 +887,29 @@ def run_subproc(cmds, captured=False, envs=None):
specs = cmds_to_specs(cmds, captured=captured, envs=envs) specs = cmds_to_specs(cmds, captured=captured, envs=envs)
if XSH.env.get("XONSH_TRACE_SUBPROC", False): if (trace := XSH.env.get("XONSH_TRACE_SUBPROC", False)):
tracer = XSH.env.get("XONSH_TRACE_SUBPROC_FUNC") tracer = XSH.env.get("XONSH_TRACE_SUBPROC_FUNC", None)
if callable(tracer): if callable(tracer):
tracer(cmds, captured=captured) tracer(cmds, captured=captured)
else: else:
r = {"cmds": cmds, "captured": captured} r = {"cmds": cmds, "captured": captured}
print(f"Trace run_subproc({repr(r)}):", file=sys.stderr) print(f"Trace run_subproc({repr(r)})", file=sys.stderr)
for i, s in enumerate(specs): if int(trace) == 2:
pcls = s.cls.__module__ + "." + s.cls.__name__ for i, s in enumerate(specs):
pcmd = ( pcls = s.cls.__module__ + "." + s.cls.__name__
[s.args[0].__name__] + s.args[1:] if callable(s.args[0]) else s.args pcmd = (
) [s.args[0].__name__] + s.args[1:] if callable(s.args[0]) else s.args
p = { )
"cmd": pcmd, p = {
"cls": pcls, "cmd": pcmd,
"alias": s.alias_name, "cls": pcls,
"bin": s.binary_loc, "alias": s.alias_name,
"thread": s.threadable, "bin": s.binary_loc,
"bg": s.background, "thread": s.threadable,
} "bg": s.background,
p = {k: v for k, v in p.items() if v is not None} }
print(f"{i}: {repr(p)}") p = {k: v for k, v in p.items() if v is not None}
print(f"{i}: {repr(p)}")
cmds = [ cmds = [
_flatten_cmd_redirects(cmd) if isinstance(cmd, list) else cmd for cmd in cmds _flatten_cmd_redirects(cmd) if isinstance(cmd, list) else cmd for cmd in cmds