Metadata-Version: 2.5
Name: run_in_env
Version: 1.0.1
Summary: Run python functions inside separate conda environments
Author-email: Jeremie Gobeil <jgobeil@nikhef.nl>
License-Expression: AGPL-3.0-only
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: cloudpickle>=3.0
Description-Content-Type: text/markdown

# run_in_env

Run python functions inside another environment with the returns brought 
back into your own python process.

The typical use case is comparing computation across environments, for 
example to compare the results from two different version of a software
from a single analysis notebook.


## Install

```
pip install run_in_env
```

Requirements: a `mamba` or `conda` executable: `mamba` is preferred when
found, `conda` otherwise. Any conda-compatible executable can also be
passed explicitly:

```python
env = CondaEnv(..., conda="conda")
```


## Usage

```python
from run_in_env import CondaEnv

env = CondaEnv(
    "finesse-3.0.2",
    conda_deps=["finesse=3.0.2"],
    pip_deps=["matplotlib-inline"],
)
env.create()                                # idempotent - skipped if env exists
out = env.run(my_function, arg, kw=value)   # host function, env result
proc = env.run("finesse --version")         # a str runs as a command
```


## How it works

`CondaEnv.run()` serializes the function and its arguments with
[cloudpickle](https://github.com/cloudpipe/cloudpickle), executes them inside
the environment with `conda run`, and returns the deserialized result. A
function defined in a notebook cell can be sent to the environment as is.
Passing a `str` instead executes it as a command inside the environment
(split with shlex, no shell) and returns the `subprocess.CompletedProcess`.

## Environments

Environments are created with the python version of the calling process
to prevent any serialisation/deserialisation problem.


## Licence

`run_in_env` is distributed under the terms of the **GNU Affero General
Public License v3.0** (`AGPL-3.0-only`). See [LICENSE](LICENSE) for the
full text.
