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.

path is the input value as discovered (whatever locate_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. resolved is the same value after PATHEXT lookup and (in default mode) os.path.realpath; when symlinks weren’t followed and no PATHEXT substitution happened, it equals path. Both may be a string, a list (alias args where [0] is the executable), or None (not found / no such alias).

bad is True when the entry is unusable: symlink loop, missing file, not a regular file, lacks +x, or its --version probe failed (Windows Store python.exe alias). version is the trimmed --version output, populated only for python-family entries.

display renders path for the colored row; list paths are space-joined the way the CLI shows them, plain strings pass through, and None becomes None so callers can detect “not found” without re-checking path. resolved_display renders the same thing for resolved. differs reports whether the resolved value is meaningfully different from the input — when it’s False, the colored renderer suppresses the name resolved: row.

bad: bool = False
property differs

True when resolved is set and is not identical to path.

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 a Resolved (or, for env getters, a plain string / None). Construct with resolve=False to skip symlink resolution — the accessibility / +x check still runs, matching the --no-resolve CLI flag.

Caching is off by default so a long-lived instance always reflects the current $PATH and alias state — callers that read a getter twice after mutating the environment get the new value, not a stale snapshot. Pass cache=True to enable per-instance memoization for the lifetime of the report; xcontext_main does this so each --version subprocess runs at most once per invocation.

get_commands_pip() Resolved[source]

Return the pip binary that $PATH resolves to.

get_commands_pytest() Resolved[source]

Return the pytest binary that $PATH resolves to.

get_commands_python() Resolved[source]

Return the python binary on $PATH, with version probed.

The version probe doubles as a spawn check — a Windows Store python.exe App Execution Alias can be located on $PATH but raises WinError 1920 on execution. Such entries get bad=True so the row renders red.

get_commands_uv() Resolved[source]

Return the uv binary that $PATH resolves to.

get_commands_xonsh() Resolved[source]

Return the xonsh binary that $PATH resolves to.

get_env_conda_default_env()[source]

Return $CONDA_DEFAULT_ENV or None if unset.

get_env_virtual_env()[source]

Return $VIRTUAL_ENV or None if unset.

get_session_xpip() Resolved[source]

Return the xpip alias value (typically [python, -m, pip]).

get_session_xpython() Resolved[source]

Return the python interpreter that’s running this xonsh.

Inside an AppImage, sys.executable points at the AppImage bootstrap rather than the bundled python — fall back to $_ so the displayed binary is something the user can actually invoke.

get_session_xxonsh() Resolved[source]

Return the path to the currently running xonsh interpreter.

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 second name 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 in session and commands carries 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 _resolved suffix (e.g. xxonsh_resolved). This mirrors the colored output’s secondary row: with --no-resolve (or when paths already match their realpath) the _resolved keys are omitted entirely instead of duplicating the value. env only contains variables that are set.