# Commands Cache (xonsh.commands_cache)¶

Module for caching command & alias names as well as for predicting whether a command will be able to be run in the background.

A background predictor is a function that accepts a single argument list and returns whether or not the process can be run in the background (returns True) or must be run the foreground (returns False).

class xonsh.commands_cache.CommandsCache[source]

A lazy cache representing the commands available on the file system. The keys are the command names and the values a tuple of (loc, has_alias) where loc is either a str pointing to the executable on the file system or None (if no executable exists) and has_alias is a boolean flag for whether the command has an alias.

cached_name(name)[source]

Returns the name that would appear in the cache, if it exists.

default_predictor(name, cmd0)[source]
default_predictor_readbin(name, cmd0, timeout, failure)[source]

Make a default predictor by analyzing the content of the binary. Should only works on POSIX. Return failure if the analysis fails.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
static get_possible_names(name)[source]

Generates the possible PATHEXT extension variants of a given executable name on Windows as a list, conserving the ordering in PATHEXT. Returns a list as name being the only item in it on other platforms.

is_empty()[source]

Returns whether the cache is populated or not.

is_only_functional_alias(name)[source]

Returns whether or not a command is only a functional alias, and has no underlying executable. For example, the “cd” command is only available as a functional alias.

items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
lazy_is_only_functional_alias(name)[source]

Returns whether or not a command is only a functional alias, and has no underlying executable. For example, the “cd” command is only available as a functional alias. This search is performed lazily.

lazy_locate_binary(name, ignore_alias=False)[source]

Locates an executable in the cache, without checking its validity.

lazyget(key, default=None)[source]

A lazy value getter.

lazyin(key)[source]

Checks if the value is in the current cache without the potential to update the cache. It just says whether the value is known now. This may not reflect precisely what is on the $PATH. lazyiter()[source] Returns an iterator over the current cache contents without the potential to update the cache. This may not reflect what is on the$PATH.

lazylen()[source]

Returns the length of the current cache contents without the potential to update the cache. This may not reflect precisely what is on the \$PATH.

locate_binary(name, ignore_alias=False)[source]

Locates an executable on the file system using the cache.

predict_threadable(cmd)[source]

Predicts whether a command list is able to be run on a background thread, rather than the main thread.

static remove_dups(p)[source]
values() → an object providing a view on D's values
all_commands
xonsh.commands_cache.default_threadable_predictors()[source]

Generates a new defaultdict for known threadable predictors. The default is to predict true.

xonsh.commands_cache.predict_false(args)[source]

Never say the process is threadable.

xonsh.commands_cache.predict_help_ver(args)[source]

Predict the backgroundability of commands that have help & version switches: -h, –help, -v, -V, –version. If either of these options is present, the command is assumed to print to stdout normally and is therefore threadable. Otherwise, the command is assumed to not be threadable. This is useful for commands, like top, that normally enter alternate mode but may not in certain circumstances.

xonsh.commands_cache.predict_hg(args)[source]

Predict if mercurial is about to be run in interactive mode. If it is interactive, predict False. If it isn’t, predict True. Also predict False for certain commands, such as split.

xonsh.commands_cache.predict_shell(args)[source]

Predict the backgroundability of the normal shell interface, which comes down to whether it is being run in subproc mode.

xonsh.commands_cache.predict_true(args)[source]

Always say the process is threadable.