Adding Bash Dependencies to an Electron
Bash dependencies can be passed to an electron as an argument to the electron decorator. The dependencies can take one of two forms:
- A Covalent DepsBash object.
- A list of commands represented as strings.
Both forms are illustrated below.
Prerequisites
Import covalent
.
import covalent as ct
Procedure
Using a Covalent DepsBash object
- Pass a comma-separated list of Bash commands to the constructor of a
DepsBash()
object, then assign the object to thedeps_bash
keyword argument:
@ct.electron(
deps_bash=ct.DepsBash(["echo `whereis cpp` > /tmp/path.txt"]),
)
def get_bash_result():
with open('/tmp/path.txt','r') as f:
return f.read()
- Use the electron in a lattice and dispatch the lattice as usual:
@ct.lattice
def workflow():
return get_bash_result()
dispatch_id = ct.dispatch(workflow)()
r = ct.get_result(dispatch_id, wait=True)
print(r.result)
cpp: /usr/bin/cpp
Using a List
- Pass a list of commands – represented as strings – directly to the
deps_bash
named argument:
@ct.electron(
deps_bash=["echo `whereis cpp` /tmp/path.txt"],
)
def get_bash_result():
with open('/tmp/path.txt','r') as f:
return f.read()
- Dispatch the elctron in a lattice as usual:
@ct.lattice
def workflow():
return get_bash_result()
dispatch_id = ct.dispatch(workflow)()
r = ct.get_result(dispatch_id, wait=True)
print(r.result)
cpp: /usr/bin/cpp