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(env, aliases=None)[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, using predictor from original command if the command is an alias, elseif build a predictor based on binary analysis on POSIX, else return predict_true.

default_predictor_alias(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.
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.

get_predictor_threadable(cmd0)[source]

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

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
iter_commands()[source]

Wrapper for handling windows path behaviour

keys() a set-like object providing a view on D's keys
lazy_is_only_functional_alias(name) bool[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.

Parameters:
namestr

name of binary to search for

ignore_aliasbool, optional

Force return of binary path even if alias of name exists (default False)

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.

Parameters:
namestr

name of binary to search for

ignore_aliasbool, optional

Force return of binary path even if alias of name exists (default False)

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(paths)[source]
update_cache()[source]
values() an object providing a view on D's values
CACHE_FILE = 'path-commands-cache.pickle'
property all_commands
property cache_file

Keeping a property that lies on instance-attribute

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_env(args, cmd_cache: CommandsCache)[source]

Predict if env is launching a threadable command or not. The launched command is extracted from env args, and the predictor of lauched command is used.

xonsh.commands_cache.predict_false(_, __)[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(_, __)[source]

Always say the process is threadable.