tasks
In the previous section, we saw that tasks needs to have two parameters: tasks
, and hooks
:
# modules/hello_world.py
import prism.task
import prism.target
class HelloWorld(prism.task.PrismTask):
def run(self, tasks, hooks):
test_str = "Hello, world!"
return test_str
Both are critical for Prism to run, and Prism will throw an error if it finds a task without both of the parameters.
So what does tasks
do? Simply put, it allows users to reference and access other tasks' outputs via the ref(...)
function. This is the most important function in Prism. It is impossible to build even moderately complex workflows without it.
Let's say that you want to create a new task that builds off of the "Hello, world!"
string created in task HelloWorld
above. You could do that as follows:
# modules/second_task.py
import prism.task
import prism.target
class SecondTask(prism.task.PrismTask):
def run(self, tasks, hooks):
hello_world_str = tasks.ref("hello_world.py")
additional_details = "\n" + "This is a Prism project"!
return hello_world_str + additional_details
Under the hood, Prism does three things:
It parses each file and computes all
tasks.ref(...)
calls.Then, it builds a dependency graph based on which files reference others. In the above example, Prism knows that the task in
hello_world.py
should be run before the task insecond_task.py
.It keeps track of the return value for each task and spits out the desired task's return value for each
tasks.ref(...)
call.
Last updated