xonsh.xoreutils.xcontext

The xontext command.

class xonsh.xoreutils.xcontext.Resolved(path: object = None, bad: bool = False, version: str = '')[source]

A resolved binary path probed by XContext.

path may be a string (resolved file path), a list (alias args where path[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.

The display property renders the entry as a single string — 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.

bad: bool = False
property display
path: object = None
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.

By default, all displayed binary paths (xxonsh, xpython, xpip and the $PATH-resolved xonsh/python/pip/pytest) have their symlinks followed to the real underlying files. This also makes the match check that decides the label color (GREEN for match, BLUE for mismatch) more accurate, because two paths that ultimately point to the same file compare equal after resolution.

Parameters:
no_resolve-n, –no-resolve

Show raw paths as-is without following symlinks (turns off the default resolution).

as_json-j, –json

Emit the resolved paths as a JSON object on stdout instead of the colored text report. Top-level keys mirror the text sections (session, commands, env); commands always includes every probed name with null for entries not on $PATH; env only contains variables that are set.