path#

Common path utilities.

Functions#

is_path(value)

expand(path)

paths_equal(path1, path2)

Examples

url_to_path(url)

Convert a file:// URL to a path.

tokenized_startswith(test_iterable, startswith_iterable)

get_all_directories(→ list[tuple[str]])

get_leaf_directories(→ Sequence[str])

explode_directories(→ set[str])

pyc_path(py_path, python_major_minor_version)

This must not return backslashes on Windows as that will break

missing_pyc_files(python_major_minor_version, files)

parse_entry_point_def(ep_definition)

get_python_short_path([python_version])

get_python_site_packages_short_path(python_version)

get_major_minor_version(string[, with_dot])

get_bin_directory_short_path()

win_path_ok(path)

win_path_double_escape(path)

win_path_backout(path)

ensure_pad(name[, pad])

Examples

is_private_env_name(env_name)

Examples

is_private_env_path(env_path)

Examples

right_pad_os_sep(path)

split_filename(path_or_url)

get_python_noarch_target_path(source_short_path, ...)

win_path_to_unix(path[, root_prefix])

which(executable)

Backwards-compatibility wrapper. Use shutil.which directly if possible.

strip_pkg_extension(path)

Examples

is_package_file(path)

Examples

Attributes#

PATH_MATCH_REGEX

KNOWN_EXTENSIONS

_VERSION_REGEX

PATH_MATCH_REGEX = '\\./|\\.\\.|~|/|[a-zA-Z]:[/\\\\]|\\\\\\\\|//'#
KNOWN_EXTENSIONS = ('.conda', '.tar.bz2', '.json', '.jlap', '.json.zst')#
is_path(value)#
expand(path)#
paths_equal(path1, path2)#

Examples

>>> paths_equal('/a/b/c', '/a/b/c/d/..')
True
url_to_path(url)#

Convert a file:// URL to a path.

Relative file URLs (i.e. file:relative/path) are not supported.

tokenized_startswith(test_iterable, startswith_iterable)#
get_all_directories(files: Iterable[str]) list[tuple[str]]#
get_leaf_directories(files: Iterable[str]) Sequence[str]#
explode_directories(child_directories: Iterable[tuple[str, Ellipsis]]) set[str]#
pyc_path(py_path, python_major_minor_version)#

This must not return backslashes on Windows as that will break tests and leads to an eventual need to make url_to_path return backslashes too and that may end up changing files on disc or to the result of comparisons with the contents of them.

missing_pyc_files(python_major_minor_version, files)#
parse_entry_point_def(ep_definition)#
get_python_short_path(python_version=None)#
get_python_site_packages_short_path(python_version)#
_VERSION_REGEX#
get_major_minor_version(string, with_dot=True)#
get_bin_directory_short_path()#
win_path_ok(path)#
win_path_double_escape(path)#
win_path_backout(path)#
ensure_pad(name, pad='_')#

Examples

>>> ensure_pad('conda')
'_conda_'
>>> ensure_pad('_conda')
'__conda_'
>>> ensure_pad('')
''
is_private_env_name(env_name)#

Examples

>>> is_private_env_name("_conda")
False
>>> is_private_env_name("_conda_")
True
is_private_env_path(env_path)#

Examples

>>> is_private_env_path('/some/path/to/envs/_conda_')
True
>>> is_private_env_path('/not/an/envs_dir/_conda_')
False
right_pad_os_sep(path)#
split_filename(path_or_url)#
get_python_noarch_target_path(source_short_path, target_site_packages_short_path)#
win_path_to_unix(path, root_prefix='')#
which(executable)#

Backwards-compatibility wrapper. Use shutil.which directly if possible.

strip_pkg_extension(path: str)#

Examples

>>> strip_pkg_extension("/path/_license-1.1-py27_1.tar.bz2")
('/path/_license-1.1-py27_1', '.tar.bz2')
>>> strip_pkg_extension("/path/_license-1.1-py27_1.conda")
('/path/_license-1.1-py27_1', '.conda')
>>> strip_pkg_extension("/path/_license-1.1-py27_1")
('/path/_license-1.1-py27_1', None)
is_package_file(path)#

Examples

>>> is_package_file("/path/_license-1.1-py27_1.tar.bz2")
True
>>> is_package_file("/path/_license-1.1-py27_1.conda")
True
>>> is_package_file("/path/_license-1.1-py27_1")
False