Skip to content

Commit

Permalink
minor bugfixes, replaced mkdocs documentation with sphinx, additional…
Browse files Browse the repository at this point in the history
… docstrings and documentation added.
  • Loading branch information
skallfass committed Sep 11, 2019
1 parent 4ebe390 commit 135cbe6
Show file tree
Hide file tree
Showing 35 changed files with 730 additions and 386 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -22,3 +22,5 @@ dist
*.egg-info
.coverage
htmlcov
.dephell_report
docs/build
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -65,7 +65,7 @@ repos:
- id: coverage-badge
name: coverage-badge
description: create the coverage badge
entry: bash -c "$VIRTUAL_ENV/bin/coverage-badge -f -o docs/img/coverage.svg"
entry: bash -c "$VIRTUAL_ENV/bin/coverage-badge -f -o docs/_static/coverage.svg"
language: system
types: [python]
pass_filenames: false
Expand Down
2 changes: 1 addition & 1 deletion .python-version
@@ -1 +1 @@
3.7.3
3.7.4
38 changes: 29 additions & 9 deletions README.md
@@ -1,11 +1,13 @@
# conda-env-manager: cenv

![coverage](docs/img/coverage.svg)
![coverage](https://github.com/skallfass/cenv_tool/blob/master/docs/img/coverage.svg)
[![PyPI version fury.io](https://badge.fury.io/py/cenv-tool.svg)](https://pypi.python.org/pypi/cenv-tool/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/cenv-tool.svg)](https://pypi.python.org/pypi/cenv-tool/)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)
[![Documentation Status](https://readthedocs.org/projects/cenv-tool/badge/?version=latest)](https://cenv-tool.readthedocs.io/en/latest/?badge=latest)
[![Powered by DepHell](https://github.com/dephell/dephell/blob/master/assets/badge.svg)](https://github.com/dephell/dephell)

![logo](docs/img/logo.png)
![logo](https://github.com/skallfass/cenv_tool/blob/master/docs/img/logo.png)

Due to the redundant dependency information inside the `meta.yaml` (required
to create the conda-package) and the `environment.yml` (as definition file
Expand Down Expand Up @@ -40,14 +42,14 @@ The usage of cenv reduces the conda commands to use to the following:

## Documentation
For complete documentation see
[cenv documentation](https://cenv.ouroboros.info/).
[readthedocs](https://cenv-tool.readthedocs.io/en/latest/).


## Installation

Install `cenv` using pip:
```bash
pip3 install cenv_tool
pip install cenv_tool
```

Now run `init_cenv` to create the relevant config-files and add the
Expand Down Expand Up @@ -187,12 +189,30 @@ If you want to turn this functionality on you need to modify your

Example for the output of the `cenv` command:

On create:
```bash
┣━━ Cloning existing env as backup ...
┣━━ Removing existing env ...
┣━━ Creating env ...
┣━━ Removing backup ...
┗━━ Exporting env to environment.yml ...
Creating cenv_dev
├── Create environment
│  └── Created
├── write md5sum of meta.yaml
│  └── updated
└── Done
```

On update:
```bash
Updating cenv_dev
├── Create backup
│  └── Created
├── Remove existing env
│  └── Removed
├── Create environment
│  ├── Clear backup
│  │  └── Cleared
│  └── Created
├── write md5sum of meta.yaml
│  └── updated
└── Done
```

# Development of cenv
Expand Down
52 changes: 41 additions & 11 deletions README.rst
Expand Up @@ -3,8 +3,8 @@ conda-env-manager: cenv
=======================


.. image:: docs/img/coverage.svg
:target: docs/img/coverage.svg
.. image:: https://github.com/skallfass/cenv_tool/blob/master/docs/img/coverage.svg
:target: https://github.com/skallfass/cenv_tool/blob/master/docs/img/coverage.svg
:alt: coverage


Expand All @@ -23,9 +23,19 @@ conda-env-manager: cenv
:alt: MIT license


.. image:: https://readthedocs.org/projects/cenv-tool/badge/?version=latest
:target: https://cenv-tool.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: docs/img/logo.png
:target: docs/img/logo.png

.. image:: https://github.com/dephell/dephell/blob/master/assets/badge.svg
:target: https://github.com/dephell/dephell
:alt: Powered by DepHell



.. image:: https://github.com/skallfass/cenv_tool/blob/master/docs/img/logo.png
:target: https://github.com/skallfass/cenv_tool/blob/master/docs/img/logo.png
:alt: logo


Expand Down Expand Up @@ -64,7 +74,7 @@ Documentation
-------------

For complete documentation see
`cenv documentation <https://cenv.ouroboros.info/>`_.
`readthedocs <https://cenv-tool.readthedocs.io/en/latest/>`_.

Installation
------------
Expand All @@ -73,7 +83,7 @@ Install ``cenv`` using pip:

.. code-block:: bash
pip3 install cenv_tool
pip install cenv_tool
Now run ``init_cenv`` to create the relevant config-files and add the
autoactivate- and autoupdate-shell-function to your ``.bashrc`` / ``.zshrc``.
Expand Down Expand Up @@ -229,13 +239,33 @@ If you want to turn this functionality on you need to modify your

Example for the output of the ``cenv`` command:

On create:

.. code-block:: bash
Creating cenv_dev
├── Create environment
│  └── Created
├── write md5sum of meta.yaml
│  └── updated
└── Done
On update:

.. code-block:: bash
┣━━ Cloning existing env as backup ...
┣━━ Removing existing env ...
┣━━ Creating env ...
┣━━ Removing backup ...
┗━━ Exporting env to environment.yml ...
Updating cenv_dev
├── Create backup
│  └── Created
├── Remove existing env
│  └── Removed
├── Create environment
│  ├── Clear backup
│  │  └── Cleared
│  └── Created
├── write md5sum of meta.yaml
│  └── updated
└── Done
Development of cenv
===================
Expand Down
3 changes: 2 additions & 1 deletion cenv_tool/__init__.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
"""Conda environment creation and update from meta.yaml."""
from pkg_resources import get_distribution
from pkg_resources import DistributionNotFound

try:
__version__ = get_distribution('cenv_tool').version
except AttributeError:
except (AttributeError, DistributionNotFound):
__version__ = ''
6 changes: 3 additions & 3 deletions cenv_tool/init_cenv.py
Expand Up @@ -42,13 +42,13 @@ def initialize_cenv(
zshrc: Path,
bashrc: Path,
) -> NoReturn:
"""Install user-config and cenv.sh for autoactivate and autoupdate.
"""
Install user-config and cenv.sh for autoactivate and autoupdate.
Parameters:
config_path: the path for cenv config-stuff.
autoenv_script_path: the path to install the cenv.sh script to.
autoenv_script_source_path: the path where to get the cenv.sh script
from
autoenv_script_source_path: the path where to get the cenv.sh script from
config_file: the path to install the user-config into.
config_file_source: the path where to get the config file from.
zshrc: the path to the users .zshrc
Expand Down
76 changes: 38 additions & 38 deletions cenv_tool/project.py
@@ -1,19 +1,20 @@
# -*- coding: utf-8 -*-
"""Contain the processing for creating conda environments from the meta.yaml.
"""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.
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
* 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.
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-file.
from the ``meta.yaml``.
The collected information is used to create / update the projects conda
environment.
Expand Down Expand Up @@ -41,11 +42,11 @@

@attr.s(slots=True, auto_attribs=True)
class Project:
"""Contain a python-project using conda-environments.
"""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 file.
projects ``meta.yaml``.
"""

rules: Rules
Expand Down Expand Up @@ -85,13 +86,13 @@ def __attrs_post_init__(self):
}

def collect_available_envs(self) -> List[str]:
"""Collect the names of the conda-environments currently installed.
"""Collect the names of the conda environments currently installed.
Parameters:
conda_folder: the path where conda is installed.
Returns:
List of currently installed conda-environments
list of currently installed conda-environments
"""
return run_in_bash(
Expand All @@ -100,7 +101,7 @@ def collect_available_envs(self) -> List[str]:
).split('\n')

def write_new_md5sum(self):
"""Write the new md5sum of the meta.yaml to conda-build/meta.md5."""
"""Write new md5sum of ``meta.yaml`` to ``conda-build/meta.md5``."""
message(text='write md5sum of meta.yaml', color='bold', special='row')
command = (
'echo "$(md5sum $PWD/conda-build/meta.yaml)" | '
Expand All @@ -110,13 +111,13 @@ def write_new_md5sum(self):
message(text='updated', color='green', special='end', indent=2)

def export_environment_definition(self) -> NoReturn:
"""Export the projects environment definition to an environment.yml."""
"""Export projects environment definition to an ``environment.yml``."""
message(text='Export environment.yml ...', color='bold', special='row')
run_in_bash(cmd=self.cmds.export.format(**self.cmd_kwargs))
message(text='Exported', color='green', special='end', indent=2)

def remove_backup_environment(self) -> NoReturn:
"""Remove backup cloned from original environment."""
"""Remove backup environment cloned from original environment."""
run_in_bash(cmd=self.cmds.clean.format(**self.cmd_kwargs))

def restore_environment_from_backup(self, cloned: bool) -> NoReturn:
Expand Down Expand Up @@ -185,10 +186,10 @@ def create_environment(self, cloned: bool) -> NoReturn:
"""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 occurs, the backup
environment is restored.
If everything worked correctly the backup (if made) is finally
removed.
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: indicates if the environment already existed and a backup
Expand All @@ -201,7 +202,7 @@ def create_environment(self, cloned: bool) -> NoReturn:
run_in_bash(cmd=self.cmds.create.format(**self.cmd_kwargs))
except CenvProcessError:
self.restore_environment_from_backup(cloned=cloned)
raise
exit(1)

if cloned:
message(text='Clear backup', color='bold', special='row', indent=2)
Expand All @@ -211,18 +212,17 @@ def create_environment(self, cloned: bool) -> NoReturn:
message(text='Created', color='green', special='end', indent=2)

def update(self) -> NoReturn:
"""Create / recreate the conda-environment of the current project.
"""Create / recreate the conda environment of the current project.
If the conda-environment already exists the user is aked for
confirmation to continue. Then the environment will be cloned as a
backup and the original environment will be removed. Now the new
conda-environment will be created. If a backup was created it is
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 the old environment will be recreated from backup and
then the backup will be removed. If activated in the config-file, the
environment-definition of the created environment is exported to an
environment.yml file. Finally the md5sum of the meta.yaml is stored
for the autoupdate feature.
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.
"""
if self.is_env:
message(text=f'Updating {self.env_name}', color='cyan')
Expand All @@ -241,11 +241,11 @@ def update(self) -> NoReturn:
message(text='Done', color='green', special='end')


def build_arguments() -> Namespace:
def build_arguments() -> ArgumentParser:
"""Create arguments for the cenv-tool.
Returns:
The parsed arguments
the parsed arguments.
"""
parser = ArgumentParser(
Expand All @@ -260,14 +260,14 @@ def build_arguments() -> Namespace:
default=False,
help='Show current version of cenv and exit.',
)
args = parser.parse_args()
return args
return parser


def main() -> NoReturn:
"""Collect the required args, initializing and running the Project."""
args = build_arguments()
if args.version:
"""Collect the required args, initialize and run the Project."""
parser = build_arguments()
options = parser.parse_args()
if options.version:
print(__version__)
else:
Project(rules=RULES).update()
Expand Down

0 comments on commit 135cbe6

Please sign in to comment.