Skip to content

skallfass/cenv_tool

Repository files navigation

conda-env-manager: cenv

coverage

PyPI version fury.io

PyPI pyversions

MIT license

Documentation Status

Powered by DepHell

logo

Due to the redundant dependency information inside the meta.yaml (required to create the conda-package) and the environment.yml (as definition file for the conda-environment during development and for production), cenv (short form for conda-env-manager) was created to make the meta.yaml the only relevant file and to create and update conda-environment from the definition inside this meta.yaml. The name of the conda-environment to create / update is defined in the section extra:cenv and the variable env_name inside the meta.yaml. The python version must be defined in extra:cenv inside the key python.

The steps run by cenv:

  • creation of a backup if the environment already exists followed by the removal of the previous environment.
  • creation of the environment as defined in the meta.yaml. If any failures occurred during creation and the backup was created, the command to reset the backup-version can be used.
  • if enabled in the config file the environment.yml is exported after creation / update of the environment.

The usage of cenv reduces the conda commands to use to the following:

  • conda activate ... to activate the environment
  • conda deactivate to deactivate an environment
  • conda info to show information about the currently activated environment
  • conda search ... to search for availability of a package in the conda channels.
  • conda remove -n ... --all to remove an environment
  • cenv to create / update an environment

Documentation

For complete documentation see readthedocs.

Installation

Install cenv using pip:

Now run init_cenv to create the relevant config-files and add the autoactivate- and autoupdate-shell-function to your .bashrc / .zshrc.

autoactivate and autoupdate

Per default these features are deactivated, even if added to your shell by running init_cenv.

autoactivate-feature

The autoactivate-feature activates the conda-environment as named extra-section in the meta.yaml located at conda-build/meta.yaml, if the environment exists. To activate the autoactivate-features run:

autoupdate-feature

The autoupdate checks if the content of the meta.yaml changed. The current state is stored as a md5sum in conda-build/meta.md5. If it changed the cenv-process is called.

For the autoupdate-feature run:

Usage

All steps required to create or update the projects conda environment are run automatically running:

ATTENTION:

  • new dependency required => add it in meta.yaml and run cenv.
  • dependency not needed anymore => remove it from meta.yaml and run cenv.
  • need of another version of dependency => change the version of dependency in meta.yaml and run cenv.

The required information about the projects conda environment are extracted from the meta.yaml. This meta.yaml should be located inside the project folder at ./conda-build/meta.yaml. The project-configuration is defined in the extra:cenv section of the meta.yaml. There you can define the name of the projects conda-environment at env_name. The python version has to be defined here at python, too. Also you can define requirements only needed during development but not to be included into the resulting conda package. These requirements have to be defined in the dev_requirements -section.

All other parts of the meta.yaml have to be defined as default.

A meta.yaml valid for cenv should look like the following:

ATTENTION:

If cenv is run the environment is created / updated from the definition inside this meta.yaml. The creation of the backup of the previous environment ensures to undo changes if any error occurs during recreation of the environment.

ATTENTION:

Per default exporting the conda environment definition into an environment.yml is turned off. If you want to turn this functionality on you need to modify your ~/.config/cenv.yml as described in the configuration-part.

Example for the output of the cenv command:

On create:

On update:

Development of cenv

Develop cenv

To create / update the dev environment to develop cenv run the pre-commit hooks manually:

Running tests

To create / update the test environment run:

To run all tests run the following command:

Updating the docs

To create / update the docs environment run:

To create / update the docs first run the tests as described above. Then run: