cenv_tool package¶
Submodules¶
cenv_tool.init_cenv module¶
Install config and cenv.sh.
-
cenv_tool.init_cenv.initialize_cenv(config_path, autoenv_script_path, autoenv_script_source_path, config_file, config_file_source, zshrc, bashrc)[source]¶ Install user-config and cenv.sh for autoactivate and autoupdate.
Parameters: - config_path (
Path) – the path for cenv config-stuff. - autoenv_script_path (
Path) – the path to install the cenv.sh script to. - autoenv_script_source_path (
Path) – the path where to get the cenv.sh script from - config_file (
Path) – the path to install the user-config into. - config_file_source (
Path) – the path where to get the config file from. - zshrc (
Path) – the path to the users .zshrc - bashrc (
Path) – the path to the users .bashrc
Return type: NoReturn- config_path (
cenv_tool.project module¶
Contain the logic for conda environment creation from meta.yaml.
cenv is a tool to handle conda environment creation and update from the
dependency-definition inside the meta.yaml file.
As default conda has two files for dependency management:
* the environment.yml
* and the meta.yaml
In the environment.yml the environment-definition is stored.
In the meta.yaml the required information to build a conda-package are
stored.
This means redundant information.
cenv collects the dependency-information and all project-specific settings
from the meta.yaml.
The collected information is used to create / update the projects conda environment.
-
class
cenv_tool.project.Project(rules, conda_folder=None, env_folder=None, env_name=None, dependencies=None, is_env=None, export_environment_yml=None, cmds=None, cmd_kwargs=None, is_git=None)[source]¶ Bases:
objectContain a python-project using conda environments.
Containing methods to display information to current project and methods to update the projects conda-environment from the settings defined in the projects
meta.yaml.-
_handle_existing_environment()[source]¶ Check if environment already exists and create a backup of it.
Return type: bool
-
_remove_backup_environment()[source]¶ Remove backup environment cloned from original environment.
Return type: NoReturn
-
_remove_previous_environment()[source]¶ Remove old version of project environment.
If the old environment can’t be removed, the backup made is removed.
Return type: NoReturn
-
_restore_environment_from_backup(cloned)[source]¶ Restore the environment from the cloned backup environment.
After restore the backup environment is removed.
Parameters: cloned ( bool) – indicates if the environment already existed and a backup was created.Return type: NoReturn
-
clone_environment_as_backup()[source]¶ Clone the existing environment as a backup.
If the backup already exists, the previous backup is removed, then the new one is created by cloning the current project environment.
Return type: NoReturn
-
cmd_kwargs¶
-
cmds¶
-
collect_available_envs()[source]¶ Collect the names of the conda environments currently installed.
Parameters: conda_folder – the path where conda is installed. Return type: List[str]Returns: list of currently installed conda-environments
-
conda_folder¶
-
create_environment(cloned)[source]¶ Create the environment for the project.
Try to create the environment for the project. If the environment already existed and a backup was made and any error occure, restore the backup environment. If everything worked correctly finally remove the backup (if one was made).
Parameters: cloned ( bool) – indicates if the environment already existed and a backup was created.Return type: NoReturn
-
dependencies¶
-
env_folder¶
-
env_name¶
-
export_environment_definition()[source]¶ Export projects environment definition to an
environment.yml.Return type: NoReturn
-
export_environment_yml¶
-
is_env¶
-
is_git¶
-
rules¶
-
update()[source]¶ Create / recreate the conda environment of the current project.
If the conda environment already exists, clone the environment as a backup and then remove original environment. Then create the new conda environment. If a backup was created it is removed afterwards. If any errors occurs during creation of the new environment, recreate the old environment from backup and remove the backup afterwards. If activated in the config-file, export the environment-definition of the created environment to an
environment.ymlfile. Finally store the md5sum of the meta.yaml for the autoupdate feature.Return type: NoReturn
-
cenv_tool.rules module¶
Rules-definitions required by cenv.
-
class
cenv_tool.rules.CondaCmdFormats(remove='{conda} remove -n {name} --all -y', export='{conda} env export -n {name} > conda-build/environment.yml', create='{conda} create -n {name} {pkgs} -y', clone='{conda} create -n {name}_backup --clone {name} -y', restore='{conda} create -n {name} --clone {name}_backup -y', clean='{conda} remove -n {name}_backup --all -y')[source]¶ Bases:
objectContain the formats for the conda commands to use inside cenv.
Variables: - remove – command to remove a conda environment.
- export – command to use to export a conda environment to an environment definition file (environment.yml).
- create – command to use for conda environment creation.
- clone – command to use to clone a conda environment.
- restore – command to use to recreate a conda environment from backup conda environment (clone).
- clean – command to use to remove the backup conda environment.
-
clean¶
-
clone¶
-
conda_bin(conda_folder)[source]¶ Combine the path of conda-folder with subpath of conda-bin.
Returns: the path to the conda-executable
-
create¶
-
export¶
-
remove¶
-
restore¶
-
class
cenv_tool.rules.Rules[source]¶ Bases:
objectContain the rules required by cenv-tool.
-
conda_cmds= CondaCmdFormats(remove='{conda} remove -n {name} --all -y', export='{conda} env export -n {name} > conda-build/environment.yml', create='{conda} create -n {name} {pkgs} -y', clone='{conda} create -n {name}_backup --clone {name} -y', restore='{conda} create -n {name} --clone {name}_backup -y', clean='{conda} remove -n {name}_backup --all -y')¶
-
git_folder= '.git'¶
-
cenv_tool.schemata module¶
Contain schemata required by cenv-tool.
-
class
cenv_tool.schemata.SMetaYaml(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.SchemaContain the representable of a complete
meta.yamlfile.Schema for a
meta.yamlfile to be used for cenv. Ensure the meta.yaml to load contains the relevant information about thepackage,source,build,requirementsandextra. Thetest-section is optional.-
opts= <marshmallow.schema.SchemaOpts object>¶
-
-
class
cenv_tool.schemata.SNBuild(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.SchemaContain the
build-section inside ameta.yaml.The
build-section requires to define the build-number, if the egg-dir should be preserved, the script to run on installation and if any entrypoints are defined for the package.-
opts= <marshmallow.schema.SchemaOpts object>¶
-
-
class
cenv_tool.schemata.SNCenv(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.Schema-
opts= <marshmallow.schema.SchemaOpts object>¶
-
-
class
cenv_tool.schemata.SNExtra(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.SchemaContain the
extra-section inside ameta.yaml.The
extra-section has to contains the information where to find the conda-folder, the name of the conda environment to use for the current project and the cenv-version used when themeta.yamlfile was created.-
opts= <marshmallow.schema.SchemaOpts object>¶
-
-
class
cenv_tool.schemata.SNPackage(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.SchemaContain the
package-section inside ameta.yaml.-
opts= <marshmallow.schema.SchemaOpts object>¶
-
-
class
cenv_tool.schemata.SNRequirements(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.SchemaContain
requirements-section inside ameta.yaml.The underlying
build- andrun-sections have to be valid!-
opts= <marshmallow.schema.SchemaOpts object>¶
-
cenv_tool.utils module¶
Contain utils required by cenv-tool.
-
exception
cenv_tool.utils.CenvProcessError[source]¶ Bases:
ExceptionRepresent a process error during cenv execution.
-
class
cenv_tool.utils._NullUndefined(hint=None, obj=missing, name=None, exc=<class 'jinja2.exceptions.UndefinedError'>)[source]¶ Bases:
jinja2.runtime.UndefinedHandle jinja2-variables with undefined content of
meta.yaml.
-
class
cenv_tool.utils._StrDict[source]¶ Bases:
dictHandle dictionaries for jinja2-variables of
meta.yaml.
-
cenv_tool.utils.extract_dependencies_from_meta_yaml(meta_yaml_content)[source]¶ Extract the dependencies defined in the requirements-run-section.
If additional dev-requirements are defined in the extra-dev_requirements-section, these dependencies are added to the other dependencies.
Parameters: meta_yaml_content ( dict) – the content from ameta.yamlas a dict.Return type: List[str]Returns: the collected dependencies.
-
cenv_tool.utils.message(*, text, color, special=None, indent=1)[source]¶ Print passed
textin the passedcoloron terminal.Parameters: - text (
str) – the text to print colored on terminal. - color (
str) – the color of the text to print. - special (
Optional[str]) – special kind of message to print. Available are'row'and'end'. - indent (
int) – the indent to use for the text.
Return type: NoReturn- text (
-
cenv_tool.utils.read_config()[source]¶ Read the config file for cenv from the users-home path if it exists.
If there is no user-config-file the default one is used.
Returns: the content of the read config file.
-
cenv_tool.utils.read_meta_yaml(path)[source]¶ Read the meta.yaml file.
The file is read from relative path
conda-build/meta.yamlinside the current path, validate themeta.yamlusing the marshmallow-schema,SMetaYaml, extract the project-settings.Parameters: path ( Path) – the current working directory.Return type: dictReturns: the meta.yamlcontent as a dict.
Module contents¶
Conda environment creation and update from meta.yaml.