utils#

Utility functions.

Functions#

path_identity(path)

Used as a dummy path converter where no conversion necessary

unix_path_to_win(path[, root_prefix])

Convert a path or :-separated string of paths into a Windows representation

win_path_to_cygwin(path)

cygwin_path_to_win(path)

translate_stream(stream, translator)

human_bytes(n)

Return the number of bytes n in more human readable form.

sys_prefix_unfollowed()

Since conda is installed into non-root environments as a symlink only

quote_for_shell(*arguments)

Properly quote arguments for command line passing.

massage_arguments(arguments[, errors])

wrap_subprocess_call(root_prefix, prefix, dev_mode, ...)

get_comspec()

Returns COMSPEC from envvars.

ensure_dir_exists(func)

Ensures that the directory exists for functions returning

Attributes#

path_identity(path)#

Used as a dummy path converter where no conversion necessary

unix_path_to_win(path, root_prefix='')#

Convert a path or :-separated string of paths into a Windows representation

Does not add cygdrive. If you need that, set root_prefix to "/cygdrive"

win_path_to_cygwin(path)#
cygwin_path_to_win(path)#
translate_stream(stream, translator)#
human_bytes(n)#

Return the number of bytes n in more human readable form.

Examples

>>> human_bytes(42)
'42 B'
>>> human_bytes(1042)
'1 KB'
>>> human_bytes(10004242)
'9.5 MB'
>>> human_bytes(100000004242)
'93.13 GB'
unix_shell_base#
msys2_shell_base#
shells#
sys_prefix_unfollowed()#

Since conda is installed into non-root environments as a symlink only and because sys.prefix follows symlinks, this function can be used to get the 'unfollowed' sys.prefix.

This value is usually the same as the prefix of the environment into which conda has been symlinked. An example of when this is necessary is when conda looks for external sub-commands in find_commands.py

quote_for_shell(*arguments)#

Properly quote arguments for command line passing.

For POSIX uses shlex.join, for Windows uses a custom implementation to properly escape metacharacters.

Parameters:

arguments (list of str) -- Arguments to quote.

Returns:

Quoted arguments.

Return type:

str

_RE_UNSAFE#
massage_arguments(arguments, errors='assert')#
wrap_subprocess_call(root_prefix, prefix, dev_mode, debug_wrapper_scripts, arguments, use_system_tmp_path=False)#
get_comspec()#

Returns COMSPEC from envvars.

Ensures COMSPEC envvar is set to cmd.exe, if not attempt to find it.

Raises:

KeyError -- COMSPEC is undefined and cannot be found.

Returns:

COMSPEC value.

Return type:

str

ensure_dir_exists(func)#

Ensures that the directory exists for functions returning a Path object containing a directory