xonsh.procs.executables

Interfaces to locate executable files on file system.

xonsh.procs.executables.clear_paths(paths)[source]

Remove duplicates and nonexistent directories from paths.

xonsh.procs.executables.get_paths(env=None)[source]

Return tuple with deduplicated and existent paths from $PATH.

xonsh.procs.executables.get_possible_names(name, env=None)[source]

Expand name to all possible variants based on PATHEXT.

PATHEXT is a Windows convention containing extensions to be considered when searching for an executable file.

Conserves order of any extensions found and gives precedence to the bare name.

xonsh.procs.executables.is_executable(filepath, check_file_exist=True)

Check the file is executable in POSIX.

Parameters:
filepathstr

Path to file.

check_file_existbool

If False do not check that file exists. This made to consistency with is_executable_in_windows.

xonsh.procs.executables.is_executable_in_posix(filepath, check_file_exist=True)[source]

Check the file is executable in POSIX.

Parameters:
filepathstr

Path to file.

check_file_existbool

If False do not check that file exists. This made to consistency with is_executable_in_windows.

xonsh.procs.executables.is_executable_in_windows(filepath, check_file_exist=True, env=None)[source]

Check the file is executable in Windows.

Parameters:
filepathstr

Path to file.

check_file_existbool

If False do not check that file exists. This helps to disable double checking in case the file already checked in upstream code. This is important for Windows where checking can take a long time.

xonsh.procs.executables.is_explicit_path(name)[source]

Return whether name is written as a path rather than a bare name.

This follows the rule used by other shells: if the command name contains a path separator (/, or \ on Windows) it is an explicit path — resolved against the file system, relative to the current directory or as an absolute path, and never looked up in $PATH. This covers ./name, ../name, ~/name, sub/name and absolute paths alike.

A bare name with no separator (e.g. "binfile") is not an explicit path: it is resolved through $PATH and, for security reasons, never against the current working directory.

xonsh.procs.executables.is_file(filepath)[source]

Check that filepath is file and exist.

xonsh.procs.executables.locate_executable(name, env=None)[source]

Search executable binary name in $PATH and return full path.

xonsh.procs.executables.locate_file(name, env=None, check_executable=False, use_pathext=False)[source]

Search file name in the current working directory and in $PATH and return full path.

A name containing a path separator (./name, ../name, ~/name, sub/name or an absolute path) is an explicit path and is resolved only against the location it points at. If the file is not there the result is None — we must not fall back to a $PATH search, otherwise a command such as ./name or sub/name would be located in $PATH even though it does not exist in the current directory (see gh-6532). Only a bare name with no separator is looked up in $PATH.

xonsh.procs.executables.locate_file_in_path_env(name, env=None, check_executable=False, use_pathext=False)[source]

Search file name in $PATH and return full path.

Compromise. There is no way to get case sensitive file name without listing all files. If the file name is CaMeL.exe and we found that camel.EXE exists there is no way to get back the case sensitive name. We don’t want to read the list of files in all $PATH directories because of performance reasons. So we’re ok to get existent but case insensitive (or different) result from resolver. May be in the future file systems as well as Python Path will be smarter to get the case sensitive name. The task for reading and returning case sensitive filename we give to completer in interactive mode with commands_cache.

xonsh.procs.executables.locate_relative_path(name, env=None, check_executable=False, use_pathext=False)[source]

Return absolute path for a name written as a path (containing a separator).

We should not locate files without a separator (e.g. "binfile") for security reasons, like other shells. If the current directory has “binfile” it can be called only by providing a path such as “./binfile” explicitly.