Angreal provides some basic utilities to define and activate python virtual environments for your tasks.
This may be useful in instances where you have a command that requires specific libraries to be available to it to function properly.
wrap a function in a virtual environment before execution. When called, if the virtual environment does not exist - an attempt will be made to create and activate it first.
from angreal.integrations.venv import venv_required
@venv_required("~/.venv", requirements=["pandas","numpy"])
@angreal.command(...)
def command_to_run:
import pandas as pd
pd.read_csv(...)
...
return
Interactions with virtual environments from within a currently running script.
from angreal.integrations.venv import VirtualEnv
this_venv = "__test_venv"
requirements = ["numpy","pandas"]
my_venv = VirtualEnv(path=this_venv, requirements=requirements,
now=True)
a property to test whether or not the environment exists in the filesystem
from angreal.integrations.venv import VirtualEnv
my_venv = VirtualEnv(path=this_venv, requirements=requirements,
now=True)
if my_venv.exists :
print("the path {} exists and appears to be a virtual environment.", my_venv.path)
Install the requirements that are set within the VirtualEnv object
from angreal.integrations.venv import VirtualEnv
my_venv = VirtualEnv(path=this_venv, requirements=requirements,
now=True)
if my_venv.exists :
my_venv.install_requirements()
Create the described environment
from angreal.integrations.venv import VirtualEnv
my_venv = VirtualEnv(path=this_venv, requirements=requirements,
now=True)
if not my_venv.exists :
my_venv._create()
my_venv.install_requirements()
Activate the described environment
from angreal.integrations.venv import VirtualEnv
my_venv = VirtualEnv(path=this_venv, requirements=requirements,
now=True)
if not my_venv.exists :
my_venv._create()
my_venv.install_requirements()
my_venv._activate()