Built-Ins (xonsh.built_ins)

The xonsh built-ins. Note that this module is named ‘built_ins’ so as not to be confused with the special Python builtins module.

class xonsh.built_ins.Aliases(*args, **kwargs)[source]

Represents a location to hold and look up aliases.

clear() → None. Remove all items from D.
get(key, default=None)[source]

Returns the (possibly modified) key. If the key is not present, the default value is returned. If the key is a string, then it is parsed and evaluated in a built-ins only context and then return. If the value is a non-string Iterable of strings, then it is returned directly. If the value is callable, it is also returned without modification. Otherwise, it fails.

items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update(*args, **kwargs)[source]
values() → an object providing a view on D's values
class xonsh.built_ins.Env(*args, **kwargs)[source]

A xonsh environment, whose variables have limited typing (unlike BASH). Most variables are, by default, strings (like BASH). However, the following rules also apply based on variable-name:

  • PATH: any variable whose name ends in PATH is a list of strings.
  • XONSH_HISTORY_SIZE: this variable is an int.
  • LC_* (locale categories): locale catergory names get/set the Python locale via locale.getlocale() and locale.setlocale() functions.

An Env instance may be converted to an untyped version suitable for use in a subprocess.

If no initial environment is given, os.environ is used.

clear() → None. Remove all items from D.
detype()[source]
get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

replace_env()[source]

Replaces the contents of os.environ with a detyped version of the xonsh environement.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
undo_replace_env()[source]

Replaces the contents of os.environ with a detyped version of the xonsh environement.

update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → an object providing a view on D's values
class xonsh.built_ins.ProcProxy(stdout, stderr)
count(value) → integer -- return number of occurrences of value
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

stderr

Alias for field number 1

stdout

Alias for field number 0

xonsh.built_ins.expand_path(s)[source]

Takes a string path and expands ~ to home and environment vars.

xonsh.built_ins.globpath(s)[source]

Simple wrapper around glob that also expands home and env vars.

xonsh.built_ins.helper(x, name='')[source]

Prints help about, and then returns that variable.

xonsh.built_ins.iglobpath(s)[source]

Simple wrapper around iglob that also expands home and env vars.

xonsh.built_ins.load_builtins(execer=None)[source]

Loads the xonsh builtins into the Python builtins. Sets the BUILTINS_LOADED variable to True.

xonsh.built_ins.regexpath(s)[source]

Takes a regular expression string and returns a list of file paths that match the regex.

xonsh.built_ins.reglob(path, parts=None, i=None)[source]

Regular expression-based globbing.

xonsh.built_ins.run_subproc(cmds, captured=True)[source]

Runs a subprocess, in its many forms. This takes a list of ‘commands,’ which may be a list of command line arguments or a string, represnting a special connecting character. For example:

$ ls | grep wakka

is represented by the following cmds:

[['ls'], '|', ['grep', 'wakka']]

Lastly, the captured argument affects only the last real command.

xonsh.built_ins.subproc_captured(*cmds)[source]

Runs a subprocess, capturing the output. Returns the stdout that was produced as a str.

xonsh.built_ins.subproc_uncaptured(*cmds)[source]

Runs a subprocess, without capturing the output. Returns the stdout that was produced as a str.

xonsh.built_ins.superhelper(x, name='')[source]

Prints help about, and then returns that variable.

xonsh.built_ins.unload_builtins()[source]

Removes the xonsh builtins from the Python builins, if the BUILTINS_LOADED is True, sets BUILTINS_LOADED to False, and returns.

xonsh.built_ins.xonsh_builtins(execer=None)[source]

A context manager for using the xonsh builtins only in a limited scope. Likely useful in testing.

This Page