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

cenv_tool.init_cenv.main()[source]

Call the initialization function to install config and cenv.sh.

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: object

Contain 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.

__attrs_post_init__()[source]

Set the more complex attributes of the project class.

_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.yml file. Finally store the md5sum of the meta.yaml for the autoupdate feature.

Return type

NoReturn

write_new_md5sum()[source]

Write new md5sum of meta.yaml to conda-build/meta.md5.

cenv_tool.project._build_arguments()[source]

Create arguments for the cenv-tool.

Return type

ArgumentParser

Returns

the parsed arguments.

cenv_tool.project.main()[source]

Collect the required args, initialize and run the Project.

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: object

Contain 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: object

Contain 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.Schema

Contain the representable of a complete meta.yaml file.

Schema for a meta.yaml file to be used for cenv. Ensure the meta.yaml to load contains the relevant information about the package, source, build, requirements and extra. The test-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.Schema

Contain the build-section inside a meta.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.Schema

Contain the extra-section inside a meta.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 the meta.yaml file 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.Schema

Contain the package-section inside a meta.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.Schema

Contain requirements-section inside a meta.yaml.

The underlying build- and run-sections have to be valid!

opts = <marshmallow.schema.SchemaOpts object>
class cenv_tool.schemata.SNSource(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: marshmallow.schema.Schema

Contain the source-section inside a meta.yaml.

opts = <marshmallow.schema.SchemaOpts object>
class cenv_tool.schemata.SNTest(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]

Bases: marshmallow.schema.Schema

Contain tests-section inside a meta.yaml.

opts = <marshmallow.schema.SchemaOpts object>

cenv_tool.utils module

Contain utils required by cenv-tool.

exception cenv_tool.utils.CenvProcessError[source]

Bases: Exception

Represent 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.Undefined

Handle jinja2-variables with undefined content of meta.yaml.

__getattr__(attribute_name)[source]

Replace getattr dunder of this class.

__getitem__(attribute_name)[source]

Replace getitem dunder of this class.

__unicode__()[source]

Replace unicode dunder of this class.

class cenv_tool.utils._StrDict[source]

Bases: dict

Handle dictionaries for jinja2-variables of meta.yaml.

__getitem__(key, default='')[source]

Replace getitem dunder of this class.

Return type

str

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 a meta.yaml as a dict.

Return type

List[str]

Returns

the collected dependencies.

cenv_tool.utils.message(*, text, color, special=None, indent=1)[source]

Print passed text in the passed color on 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

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.yaml inside the current path, validate the meta.yaml using the marshmallow-schema, SMetaYaml, extract the project-settings.

Parameters

path (Path) – the current working directory.

Return type

dict

Returns

the meta.yaml content as a dict.

cenv_tool.utils.run_in_bash(cmd)[source]

Run passed cmd inside bash using subprocess.check_output().

Parameters

cmd (str) – the command to execute.

Return type

str

Returns

the output of the ran command.

Module contents

Conda environment creation and update from meta.yaml.