conda_project package#

Subpackages#

Submodules#

conda_project.conda module#

conda_project.conda.call_conda(args, condarc_path=None, verbose=False, logger=None, variables=None)[source]#

Call conda CLI with subprocess.run

Return type:

CompletedProcess

conda_project.conda.conda_activate(prefix, working_dir, env=None)[source]#
conda_project.conda.conda_info()[source]#
conda_project.conda.conda_prefix(env=None)[source]#

Return the path to a conda environment

Return type:

Path

conda_project.conda.conda_run(cmd, prefix, working_dir, env=None, extra_args=None)[source]#
Return type:

NoReturn

conda_project.conda.current_platform()[source]#

Load the current platform by calling conda info.

Return type:

str

conda_project.conda.env_export(prefix, from_history=True, pin_versions=True, verbose=False)[source]#

Create an environment.yml spec and lockfile from an existing environment

Return type:

Tuple[EnvironmentYaml, Lockfile]

conda_project.conda.is_conda_env(prefix)[source]#
Return type:

bool

conda_project.exceptions module#

exception conda_project.exceptions.CommandNotFoundError[source]#

Bases: CondaProjectError

exception conda_project.exceptions.CondaProjectError[source]#

Bases: Exception

exception conda_project.exceptions.CondaProjectLockFailed[source]#

Bases: CondaProjectError

conda_project.project module#

class conda_project.project.BaseCommands(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

allow_mutation = False#
keys()[source]#
values()[source]#
class conda_project.project.BaseEnvironments(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

allow_mutation = False#
keys()[source]#
values()[source]#
class conda_project.project.Command(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

arbitrary_types_allowed = True#
cmd: str#
command_variables: Optional[Dict[str, Optional[str]]]#
environment: Optional[Environment]#
name: str#
project: CondaProject#
run(environment=None, external_environment=None, extra_args=None, verbose=False)[source]#
Return type:

NoReturn

class conda_project.project.CondaProject(directory='.')[source]#

Bases: object

A project managed by conda-project.

directory#

The project base directory. Defaults to the current working directory.

condarc#

A path to the local .condarc file. Defaults to <directory>/.condarc.

environment_file#

A path to the environment file.

lock_file#

A path to the conda-lock file.

Parameters:

directory (Union[Path, str]) – The project base directory.

Raises:

CondaProjectError – If no suitable environment file is found.

check(verbose=False)[source]#

Check the project for inconsistencies or errors.

This will check that conda-lock.<env>.yml file(s) exist for each environment and that they are up-to-date against the environment specification.

Returns:

True if all environments are locked and update to date,

False if any environment is not locked or out-of-date.

Return type:

Boolean

property commands: BaseCommands#
property default_command: Command#
property default_environment: Environment#
property environments: BaseEnvironments#
classmethod from_archive(fn, storage_options=None, output_directory='.')[source]#

Extra a conda-project archive and load the project

classmethod init(directory='.', name=None, dependencies=None, channels=None, platforms=None, conda_configs=None, from_environment=None, lock_dependencies=False, verbose=False)[source]#

Initialize a new project.

Creates the environment.yml file from the specified dependencies, channels, and platforms. Further a local .condarc can also be created in the directory.

Parameters:
  • directory (Union[Path, str]) – The path to use as the project directory. The directory will be created if it doesn’t exist.

  • name (Optional[str]) – Name of the project. The default is the basename of the project directory.

  • dependencies (Optional[List[str]]) – List of package dependencies to include in the environment.yml in MatchSpec format.

  • channels (Optional[List[str]]) – List of channels to search for dependencies. The default value is [‘defaults’]

  • platforms (Optional[List[str]]) – List of platforms over which to lock the dependencies. The default is osx-64, linux-64, win-64 and your current platform if it is not already included.

  • conda_configs (Optional[List[str]]) – List of conda configuration parameters to include in the .condarc file written to the project directory.

  • from_environment (Optional[str]) – Name (string) or prefix (path) to an environment to initialize the project default environment.

  • lock_dependencies (bool) – Create the conda-lock.<env>.yml file(s) for the requested dependencies. Default is False.

  • verbose (bool) – Print information to stdout. The default value is False.

Return type:

CondaProject

Returns:

CondaProject instance for the project directory.

class conda_project.project.Environment(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

allow_mutation = False#
arbitrary_types_allowed = True#
extra = 'forbid'#
activate(verbose=False)[source]#
Return type:

None

add(dependencies, channels=None, verbose=False)[source]#
Return type:

None

clean(verbose=False)[source]#

Remove the conda environment.

Return type:

None

install(force=False, as_platform=None, verbose=False)[source]#

Install all dependencies into the conda environment.

Creates a new conda environment and installs the packages from the environment.yaml file. Environments are always created from the conda-lock.<env>.yml file(s). The conda-lock.<env>.yml file(s) will be created if they do not already exist.

Parameters:
  • force (bool) – If True, will force creation of a new conda environment.

  • as_platform (Optional[str]) – Install dependencies as an explicit platform. By default, the platform will be identified for the system.

  • verbose (bool) – A verbose flag passed into the conda create command.

Raises:

CondaProjectError – If no suitable environment file can be found.

Return type:

Path

Returns:

The path to the created environment.

property is_consistent: bool#

Returns True if the conda environment exists and is consistent with the environment source and lock files, False otherwise. If is_locked is False is_prepared is False.

Type:

bool

property is_locked: bool#
property is_locked_current_platform: bool#
lock(force=False, verbose=False)[source]#

Generate locked package lists for the supplied or default platforms

Utilizes conda-lock to build the conda-lock.<env>.yml file(s).

Parameters:
  • force (bool) – Rebuild the conda-lock.<env>.yml file even if no changes were made to the dependencies.

  • verbose (bool) – A verbose flag passed into the conda lock command.

Return type:

None

lockfile: Path#
name: str#
prefix: Path#
project: CondaProject#
remove(dependencies, verbose=False)[source]#
Return type:

None

sources: Tuple[Path, ...]#
class conda_project.project.Variable(**data)[source]#

Bases: BaseModel

default_value: str#
key: str#

conda_project.project_file module#

class conda_project.project_file.BaseYaml(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

json_encoders = {<class 'pathlib.Path'>: <function BaseYaml.Config.<lambda>>}#
classmethod parse_yaml(fn)[source]#
yaml(stream, drop_empty_keys=False)[source]#
class conda_project.project_file.Command(**data)[source]#

Bases: BaseModel

class Config[source]#

Bases: object

extra = 'forbid'#
cmd: str#
environment: Optional[str]#
variables: Optional[Dict[str, Optional[str]]]#
class conda_project.project_file.CondaProjectYaml(**data)[source]#

Bases: BaseYaml

commands: OrderedDict[str, Union[Command, str]]#
environments: OrderedDict[str, List[Path]]#
name: str#
variables: Dict[str, Optional[str]]#
class conda_project.project_file.EnvironmentYaml(**data)[source]#

Bases: BaseYaml

add_dependencies(dependencies, channels=None)[source]#
Return type:

None

channels: Union[UniqueOrderedList, List[str], None]#
property conda_matchspecs#
classmethod convert_channels_list(v)[source]#
dependencies: List[Union[str, Dict[str, List[str]]]]#
name: Optional[str]#
classmethod only_pip_key_allowed(v)[source]#
property pip_requirements#
platforms: Optional[List[str]]#
prefix: Optional[Path]#
remove_dependencies(dependencies)[source]#
Return type:

None

variables: Optional[Dict[str, str]]#
class conda_project.project_file.UniqueOrderedList(iterable)[source]#

Bases: list

append(_UniqueOrderedList__object)[source]#

Append object to the end of the list.

Return type:

None

extend(_UniqueOrderedList__iterable)[source]#

Extend list by appending elements from the iterable.

Return type:

None

conda_project.utils module#

class conda_project.utils.Spinner(prefix)[source]#

Bases: object

Multithreaded CLI spinner context manager

prefix#

Text to display at the start of the line

Parameters:

prefix (str) – Text to display at the start of the line

start()[source]#
Return type:

None

stop()[source]#
Return type:

None

conda_project.utils.dedupe_list_of_dicts(data, key, keep)[source]#
Return type:

list

conda_project.utils.detect_shell()[source]#
conda_project.utils.env_variable(key, value)[source]#

Temporarily set environment variable in a context manager.

Return type:

Generator

conda_project.utils.execvped(file, args, env, cwd)[source]#

A cross-platform os.execvpe - like executor

The goal is the be able to launch a command in a working directory, with environment variables and exit to the shell with the return code of the command and ensure that on error the previous working directory is restored.

The “d” in the function name refers to the requirement that the working directory (cwd) flag be used.

Return type:

NoReturn

conda_project.utils.find_file(directory, options)[source]#

Search for a file in a directory from a tuple of variants.

Return type:

Optional[Path]

Returns:

The path to the file if found else None

Raises:

CondaProjectError if more than one of the options is found

conda_project.utils.get_envs_paths()[source]#
Return type:

List[Path]

conda_project.utils.is_windows()[source]#
conda_project.utils.merge_dicts(*dicts)[source]#
conda_project.utils.prepare_variables(project_directory, *variable_dicts)[source]#
Return type:

Dict[str, str]

Module contents#