Skip to content
Back to top
View this page
Edit this page

# xonsh.platform

Module for platform-specific constants and implementations, as well as compatibility layers to make use of the ‘best’ implementation available on a platform.

xonsh.platform.bash_command()

  Determines the command for Bash on the current platform.

xonsh.platform.best_shell_type()

xonsh.platform.git_for_windows_path()

  Returns the path to git for windows, if available and None otherwise.

xonsh.platform.githash()

  Returns a tuple contains two strings: the hash and the date.

xonsh.platform.has_prompt_toolkit()

  Tests if the prompt_toolkit is available.

xonsh.platform.is_readline_available()

  Checks if readline is available to import.

xonsh.platform.linux_distro()

  The id of the Linux distribution running on, possibly ‘unknown’. None on non-Linux platforms.

xonsh.platform.path_bshell()

  Absolute path to the system Bourne shell, like libc `_PATH_BSHELL`.

  `/bin/sh` everywhere except Android: Termux ships `sh` under `$PREFIX/bin` and stock Android under `/system/bin` (bionic’s `_PATH_BSHELL`); plain `/bin/sh` may not exist on either. Candidates are checked for existence, so FHS userlands running on top of Android (proot-distro, UserLAnd, …) keep their own `/bin/sh`. NixOS needs no special casing — `/bin/sh` is its single `/bin` FHS concession. If no candidate exists, fall back to `sh` from `$PATH` (POSIX mandates the utility, not a fixed path).

xonsh.platform.pathbasename(p)

  This is a safe version of os.path.basename(), which does not work on input without a drive. This version does.

xonsh.platform.pathsplit(p)

  This is a safe version of os.path.split(), which does not work on input without a drive.

xonsh.platform.ptk_above_min_supported()

xonsh.platform.ptk_below_max_supported()

xonsh.platform.ptk_version()

  Returns prompt_toolkit.__version__ if available, else `None`.

xonsh.platform.ptk_version_info()

  Returns prompt_toolkit’s version as tuple of integers.

xonsh.platform.pygments_version()

  pygments.__version__ version if available, else None.

xonsh.platform.pygments_version_info()

  Returns pygments’s version as tuple of integers.

xonsh.platform.win_ansi_support()

xonsh.platform.windows_bash_command()

  Determines the command for Bash on windows.

xonsh.platform.windows_expanduser(path)

  A Windows-specific expanduser() function for xonsh. This is needed since os.path.expanduser() does not check on Windows if the user actually exists. This restricts expanding the ‘~’ if it is not followed by a separator. That is only ‘~/’ and ‘~’ are expanded.

xonsh.platform.CAN_RESIZE_WINDOW = <xonsh.lib.lazyasd.LazyBool object>

  `True` if we can resize terminal window, as provided by the presense of signal.SIGWINCH, else `False`.

xonsh.platform.DEFAULT_ENCODING = 'utf-8'

  Default string encoding.

xonsh.platform.IN_APPIMAGE = False

  `True` if in AppImage, else `False`.

xonsh.platform.IN_FLATPAK = <xonsh.lib.lazyasd.LazyBool object>

  `True` if in Flastpak, else `False`.

xonsh.platform.ON_ANACONDA = <xonsh.lib.lazyasd.LazyBool object>

  `True` if executed in an Anaconda instance, else `False`.

xonsh.platform.ON_ANDROID = <xonsh.lib.lazyasd.LazyBool object>

  `True` on any Android userland — Termux, UserLAnd, proot-distro, Linux Deploy chroot, etc.

  Detection is layered: PEP 738 sets `sys.platform == "android"` and `platform.system() == "Android"` on Python 3.13+; for older Python versions and proot/chroot setups where those checks miss, we fall back to the presence of the `ANDROID_ROOT` environment variable (always exported by the Android init) and finally to `/system/build.prop`.

  Implies the Android app sandbox: `/` is typically unlistable, `os.tcsetpgrp` and `os.link` are restricted, the filesystem is non-FHS. Code that needs Android-wide behaviour (e.g. `skipif` on tests that walk the FS root) should key off this flag rather than `ON_TERMUX` so non-Termux Android shells (UserLAnd, …) are covered.

xonsh.platform.ON_CYGWIN = False

  `True` if executed on a Cygwin Windows platform, else `False`.

xonsh.platform.ON_DARWIN = False

  `True` if executed on a Darwin platform, else `False`.

xonsh.platform.ON_DRAGONFLY = False

  `True` if on a DragonFly BSD operating system, else `False`.

xonsh.platform.ON_FREEBSD = False

  `True` if on a FreeBSD operating system, else `False`.

xonsh.platform.ON_LINUX = True

  `True` if executed on a Linux platform, else `False`.

xonsh.platform.ON_MSYS = False

  `True` if executed on a MSYS Windows platform, else `False`.

xonsh.platform.ON_NETBSD = False

  `True` if on a NetBSD operating system, else `False`.

xonsh.platform.ON_OPENBSD = False

  `True` if on a OpenBSD operating system, else `False`.

xonsh.platform.ON_POSIX = True

  `True` if executed on a POSIX-compliant platform, else `False`.

xonsh.platform.ON_TERMUX = False

  `True` specifically inside the Termux app (and forks that keep its `TERMUX_VERSION` env var).

  Detected via `TERMUX_VERSION` which Termux exports in every shell it spawns. Implies `ON_ANDROID`, plus the Termux userland layout under `$PREFIX = /data/data/com.termux/files/usr`. Use this flag for Termux-specific path defaults (`$PREFIX/bin`, completion script locations, etc.); use `ON_ANDROID` for sandbox/bionic concerns that apply to any Android userland.

xonsh.platform.ON_WINDOWS = False

  `True` if executed on a native Windows platform, else `False`.

xonsh.platform.PYTHON_VERSION_INFO = (3, 14, 6)

  Version of Python interpreter as three-value tuple.

xonsh.platform.minimum_required_ptk_version = (2, 0, 0)

  Minimum version of prompt-toolkit supported by Xonsh