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

# xonsh.xontribs

Tools for helping manage xontributions.

exception xonsh.xontribs.XontribNotInstalled

  raised when the requested xontrib is not found

  add_note(note, /)

    Add a note to the exception

  with_traceback(tb, /)

    Set self.__traceback__ to tb and return self.

  args

class xonsh.xontribs.ExitCode(*values)
  as_integer_ratio(/)

    Return a pair of integers, whose ratio is equal to the original int.

    The ratio is in lowest terms and has a positive denominator.

        >>> (10).as_integer_ratio()
        (10, 1)
        >>> (-10).as_integer_ratio()
        (-10, 1)
        >>> (0).as_integer_ratio()
        (0, 1)

  bit_count(/)

    Number of ones in the binary representation of the absolute value of self.

    Also known as the population count.

        >>> bin(13)
        '0b1101'
        >>> (13).bit_count()
        3

  bit_length(/)

    Number of bits necessary to represent self in binary.

        >>> bin(37)
        '0b100101'
        >>> (37).bit_length()
        6

  conjugate(/)

    Returns self, the complex conjugate of any int.

  classmethod from_bytes(/, bytes, byteorder='big', *, signed=False)

    Return the integer represented by the given array of bytes.

    bytes

      Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

    byteorder

      The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

    signed

      Indicates whether two’s complement is used to represent the integer.

  is_integer(/)

    Returns True. Exists for duck type compatibility with float.is_integer.

  to_bytes(/, length=1, byteorder='big', *, signed=False)

    Return an array of bytes representing an integer.

    length

      Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

    byteorder

      The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

    signed

      Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

  INIT_FAILED = 2
  NOT_FOUND = 1
  OK = 0
  denominator

    the denominator of a rational number in lowest terms

  imag

    the imaginary part of a complex number

  numerator

    the numerator of a rational number in lowest terms

  real

    the real part of a complex number

class xonsh.xontribs.Xontrib(module: str, distribution: Distribution | None = None)

  Meta class that is used to describe a xontrib

  Create new instance of Xontrib(module, distribution)

  count(value, /)

    Return number of occurrences of value.

  get_description()
  index(value, start=0, stop=sys.maxsize, /)

    Return first index of value.

    Raises ValueError if the value is not present.

  distribution: Distribution | None

    short description about the xontrib.

  property is_auto_loaded
  property is_loaded
  property license
  module: str

    path to the xontrib module

  property url

class xonsh.xontribs.XontribAlias(threadable=True, **kwargs)

  Manage xonsh extensions

  exception Error(message: str, errno=1)

    Special case, when raised, the traceback will not be shown. Instead the process with exit with error code and message

    add_note(note, /)

      Add a note to the exception

    with_traceback(tb, /)

      Set self.__traceback__ to tb and return self.

    args
  build()

    Sub-classes should return constructed ArgumentParser

  create_parser(func=None, has_args=False, allowed_params=None, **kwargs) → ArgParser

    create root parser

  err(*args, **kwargs)

    Write text to error stream

  out(*args, **kwargs)

    Write text to output stream

  write_to(stream: str, *args, **kwargs)
  xonsh_complete(command, **kwargs)
  property parser

xonsh.xontribs.auto_load_xontribs_from_entrypoints(blocked: Sequence[str] = (), verbose=False)

  Load xontrib modules exposed via setuptools’s entrypoints

xonsh.xontribs.find_xontrib(name, full_module=False)

  Finds a xontribution from its name.

xonsh.xontribs.get_module_docstring(module: str) → str

  Find the module and return its docstring without actual import

xonsh.xontribs.get_xontribs() → dict[str, Xontrib]

  Return xontrib definitions lazily.

xonsh.xontribs.prompt_xontrib_install(names: list[str])

  Returns a formatted string with name of xontrib package to prompt user

xonsh.xontribs.update_context(name, ctx: dict, full_module=False)

  Updates a context in place from a xontrib.

xonsh.xontribs.xontrib_context(name, full_module=False)

  Return a context dictionary for a xontrib of a given name.

xonsh.xontribs.xontrib_data()

  Collects and returns the data about installed xontribs.

xonsh.xontribs.xontrib_names_completer(**_)

xonsh.xontribs.xontrib_unload_completer(**_)

xonsh.xontribs.xontribs_list(to_json=False, _stdout=None)

  List installed xontribs and show whether they are loaded or not

  Parameters:
    to_json-j, –json

      reports results as json

xonsh.xontribs.xontribs_load(names: ~typing.Annotated[~typing.Sequence[str], ((), (('nargs', '+'), ('completer', <function xontrib_names_completer at 0x7d741d1e7270>)))] = (), verbose=False, full_module=False, suppress_warnings=False)

  Load xontribs from a list of names

  Parameters:
    names

      names of xontribs

    verbose-v, –verbose

      verbose output

    full_module-f, –full

      indicates that the names are fully qualified module paths and not inside `xontrib` package

    suppress_warnings-s, –suppress-warnings

      no warnings about missing xontribs and return code 0

xonsh.xontribs.xontribs_loaded()

  Returns list of loaded xontribs.

xonsh.xontribs.xontribs_reload(names: ~typing.Annotated[~typing.Sequence[str], ((), (('nargs', '+'), ('completer', <function xontrib_unload_completer at 0x7d741d1e7320>)))] = (), verbose=False)

  Reload the given xontribs

  Parameters:
    names

      name of xontribs to reload

    verbose-v, –verbose

      verbose output

xonsh.xontribs.xontribs_unload(names: ~typing.Annotated[~typing.Sequence[str], ((), (('nargs', '+'), ('completer', <function xontrib_unload_completer at 0x7d741d1e7320>)))] = (), verbose=False)

  Unload the given xontribs

  Parameters:
    names

      name of xontribs to unload

    verbose-v, –verbose

      verbose output

  Notes

  Proper cleanup can be implemented by the xontrib. The default is equivalent to `del sys.modules[module]`.