xonsh.xoreutils.xcontext¶
The xontext command.
- class xonsh.xoreutils.xcontext.Resolved(path: object = None, resolved: object = None, bad: bool = False, version: str = '')[source]¶
A binary path probed by
XContext.pathis the input value as discovered (whateverlocate_executable(),get_current_xonsh(),sys.executable, or the alias lookup returned) — preserved verbatim so the colored output and the JSON consumer can show the user the path they would actually type.resolvedis the same value after PATHEXT lookup and (in default mode)os.path.realpath; when symlinks weren’t followed and no PATHEXT substitution happened, it equalspath. Both may be a string, a list (alias args where[0]is the executable), orNone(not found / no such alias).badis True when the entry is unusable: symlink loop, missing file, not a regular file, lacks+x, or its--versionprobe failed (Windows Storepython.exealias).versionis the trimmed--versionoutput, populated only for python-family entries.displayrenderspathfor the colored row; list paths are space-joined the way the CLI shows them, plain strings pass through, andNonebecomesNoneso callers can detect “not found” without re-checkingpath.resolved_displayrenders the same thing forresolved.differsreports whether the resolved value is meaningfully different from the input — when it’s False, the colored renderer suppresses thename resolved:row.- bad: bool = False¶
- property differs¶
True when
resolvedis set and is not identical topath.Drives whether the colored renderer emits the secondary
name resolved:row — same value on both sides would just duplicate the line.
- property display¶
- path: object = None¶
- resolved: object = None¶
- property resolved_display¶
- version: str = ''¶
- class xonsh.xoreutils.xcontext.XContext(resolve=True, cache=False)[source]¶
Lazy collector of every value displayed by
xcontext.Each
get_*method computes its value and returns aResolved(or, for env getters, a plain string /None). Construct withresolve=Falseto skip symlink resolution — the accessibility /+xcheck still runs, matching the--no-resolveCLI flag.Caching is off by default so a long-lived instance always reflects the current
$PATHand alias state — callers that read a getter twice after mutating the environment get the new value, not a stale snapshot. Passcache=Trueto enable per-instance memoization for the lifetime of the report;xcontext_maindoes this so each--versionsubprocess runs at most once per invocation.- get_commands_python() Resolved[source]¶
Return the
pythonbinary on$PATH, with version probed.The version probe doubles as a spawn check — a Windows Store
python.exeApp Execution Alias can be located on$PATHbut raises WinError 1920 on execution. Such entries getbad=Trueso the row renders red.
- xonsh.xoreutils.xcontext.xcontext_main(no_resolve: bool = False, as_json: bool = False, _stdout=None)[source]¶
Report information about the current xonsh environment.
The colored text report shows the input path of each binary on a
name:row and — when symlink resolution (or, on Windows, the PATHEXT lookup) changes it — the resolved path on a secondname resolved:row. The label-color match check (GREEN/BLUE) uses the resolved paths so two entries that ultimately point to the same underlying file compare equal even when their input paths differ.- Parameters:
- no_resolve-n, –no-resolve
Show raw paths as-is without following symlinks (turns off the default resolution). The accessibility / executable check still runs, so broken entries are still flagged in red.
- as_json-j, –json
Emit the paths as a JSON object on stdout instead of the colored text report. Top-level keys mirror the text sections (
session,commands,env). Each entry insessionandcommandscarries the input path under its base key (e.g.xxonsh) — and, only when the resolved path differs from the input, an additional sibling key with a_resolvedsuffix (e.g.xxonsh_resolved). This mirrors the colored output’s secondary row: with--no-resolve(or when paths already match their realpath) the_resolvedkeys are omitted entirely instead of duplicating the value.envonly contains variables that are set.