Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/deeuu/xontrib-conda-project

Auto activate/deactive conda environments residing in a project directory
https://github.com/deeuu/xontrib-conda-project

xonsh xontrib

Last synced: 20 days ago
JSON representation

Auto activate/deactive conda environments residing in a project directory

Awesome Lists containing this project

README

        

# Xontrib Conda Project

A [xonsh](https://xon.sh/) `xontrib` to automatically activate a [`conda`](https://docs.conda.io/projects/conda/en/latest/user-guide/) environment residing in a project directory, upon moving to that directory.

For example, lets create a `conda` environment for our new project located at `~/project`

```
mkdir ~/project
cd ~/project
conda create --prefix conda-env xonsh
```

With `conda-project` loaded, this environment will automatically activate when you navigate to the project

```
cd ~
which xonsh # /Users/deeuu/.local/share/virtualenvs/xonsh/bin/xonsh
cd ~/project
which xonsh # /Users/deeuu/project/conda-env/bin/xonsh
```

and deactivate when you leave

```
cd ..
which xonsh # /Users/deeuu/.local/share/virtualenvs/xonsh/bin/xonsh
```

By default, `conda-project` will decide to activate if a `conda-env` directory is found. You can change this by setting `$CONDA_PROJECT_DIR_NAME`.

Two useful aliases are also provided:

- `create-conda-project`: creates a `conda` environment in the current (project) directory, using an `env*.yaml` file if found. This is just a wrapper around `conda create`, so you can pass any valid arguments to this subcommand.
- `export-conda-project`: exports the `conda` environment located in the current (project) directory to `environment.yaml` (the environment does not need to be active to call this alias). This is just a wrapper around `conda env export`, so you can pass any valid arguments to this subcommand.

To deactivate the service, set `$CONDA_PROJECT = False` (or remove the `xontrib`).

## Install

```
xpip install xontrib-conda-project
```

Then load it by adding

```
xontrib load xontrib-conda-project
```

to your `.xonshrc`.

## Links

- See the [xonsh](https://xon.sh/) website for more information about this shell, or visit the [github repo](https://github.com/xonsh/xonsh).
- You can find more xontribs and related documentation on the [project website](https://xon.sh/xontribs.html#).