envs_manager#

Tools for managing conda environments.

Functions#

get_user_environments_txt_file(→ str)

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

register_env(→ None)

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

unregister_env(→ 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(...)

Queries all known prefixes for a given specification.

_clean_environments_txt(→ tuple[str, Ellipsis])

Cleans the environments.txt file by removing specified locations.

_rewrite_environments_txt(→ 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 (str) -- The home directory of the user.

Returns:

Path to the environments.txt file.

Return type:

str

register_env(location: str) None#

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

Parameters:

location (str) -- The file path of the environment to register.

Returns:

None

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 (str) -- The file path of the environment to unregister.

Returns:

None

list_all_known_prefixes() list[str]#

Lists all known conda environment prefixes.

Returns:

A list of all known conda environment prefixes.

Return type:

List[str]

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

Queries all known prefixes for a given specification.

Parameters:

spec (str) -- The specification to query for.

Returns:

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

Return type:

Iterator[Tuple[str, Tuple]]

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

Cleans the environments.txt file by removing specified locations.

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

  • remove_location (Optional[str]) -- Optional location to remove from the file.

Returns:

A tuple of the cleaned lines.

Return type:

Tuple[str, ...]

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

Rewrites the environments.txt file with the specified prefixes.

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

  • prefixes (List[str]) -- List of prefixes to write into the file.

Returns:

None