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_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.exceptions module#
- exception conda_project.exceptions.CommandNotFoundError[source]#
Bases:
CondaProjectError
- exception conda_project.exceptions.CondaProjectLockFailed[source]#
Bases:
CondaProjectError
conda_project.project module#
- class conda_project.project.Command(**data)[source]#
Bases:
BaseModel
-
cmd:
str
#
-
command_variables:
Optional
[Dict
[str
,Optional
[str
]]]#
-
environment:
Optional
[Environment
]#
-
name:
str
#
-
project:
CondaProject
#
-
cmd:
- 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_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:
- 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'#
- 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
#
-
sources:
Tuple
[Path
,...
]#
conda_project.project_file module#
- class conda_project.project_file.BaseYaml(**data)[source]#
Bases:
BaseModel
- class conda_project.project_file.Command(**data)[source]#
Bases:
BaseModel
-
cmd:
str
#
-
environment:
Optional
[str
]#
-
variables:
Optional
[Dict
[str
,Optional
[str
]]]#
-
cmd:
- class conda_project.project_file.CondaProjectYaml(**data)[source]#
Bases:
BaseYaml
-
environments:
OrderedDict
[str
,List
[Path
]]#
-
name:
str
#
-
variables:
Dict
[str
,Optional
[str
]]#
-
environments:
- class conda_project.project_file.EnvironmentYaml(**data)[source]#
Bases:
BaseYaml
-
channels:
Union
[UniqueOrderedList
,List
[str
],None
]#
- property conda_matchspecs#
-
dependencies:
List
[Union
[str
,Dict
[str
,List
[str
]]]]#
-
name:
Optional
[str
]#
- property pip_requirements#
-
platforms:
Optional
[List
[str
]]#
-
prefix:
Optional
[Path
]#
-
variables:
Optional
[Dict
[str
,str
]]#
-
channels:
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
- 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