envs_manager#

Tools for managing conda environments.

Functions#

get_user_environments_txt_file([userhome]) → str

Gets the path to the user's environments.txt file.

register_env(location) → None

Registers an environment by adding it to environments.txt file.

unregister_env(location) → None

Unregisters an environment by removing its entry from the environments.txt file if certain conditions are met.

list_all_known_prefixes() → list[str]

Lists all known conda environment prefixes.

query_all_prefixes(spec) → collections.abc.Iterator[tuple[str, tuple]]

Queries all known prefixes for a given specification.

_clean_environments_txt(environments_txt_file[, ...]) → tuple[str, ...]

Cleans the environments.txt file by removing specified locations.

_rewrite_environments_txt(environments_txt_file, prefixes) → None

Rewrites the environments.txt file with the specified prefixes.

get_user_environments_txt_file(userhome: str = '~') → str#

Gets the path to the user's environments.txt file.

Parameters:

userhome -- The home directory of the user.

Returns:

Path to the environments.txt file.

register_env(location: str) → None#

Registers an environment by adding it to environments.txt file.

Parameters:

location -- The file path of the environment to register.

unregister_env(location: str) → None#

Unregisters an environment by removing its entry from the environments.txt file if certain conditions are met.

The environment is only unregistered if its associated 'conda-meta' directory exists and contains no significant files other than 'history'. If these conditions are met, the environment's path is removed from environments.txt.

Parameters:

location -- The file path of the environment to unregister.

list_all_known_prefixes() → list[str]#

Lists all known conda environment prefixes.

Returns:

A list of all known conda environment prefixes.

query_all_prefixes(spec: str) → collections.abc.Iterator[tuple[str, tuple]]#

Queries all known prefixes for a given specification.

Parameters:

spec -- The specification to query for.

Returns:

An iterator of tuples containing the prefix and the query results.

_clean_environments_txt(environments_txt_file: str, remove_location: str | None = None) → tuple[str, ...]#

Cleans the environments.txt file by removing specified locations.

Parameters:
  • environments_txt_file -- The file path of environments.txt.

  • remove_location -- Optional location to remove from the file.

Returns:

A tuple of the cleaned lines.

_rewrite_environments_txt(environments_txt_file: str, prefixes: list[str]) → None#

Rewrites the environments.txt file with the specified prefixes.

Parameters:
  • environments_txt_file -- The file path of environments.txt.

  • prefixes -- List of prefixes to write into the file.