Step inputs

Automation steps without inputs are not very useful. So let's add some!
First, create a new Python module called helloyou.py with the following content:

from freyja import Step, Automation, Input, Output
 
 
class HelloYou(Step):
    first_name = Input(str, description="Your first name")
    last_name = Input(str, description="Your last name", default="Doe")
    full_name = Output(str)
 
    def execute(self):
        self.full_name = self.first_name + " " + self.last_name
        print(f"Hello {self.full_name}!")
 
 
if __name__ == "__main__":
    Automation(HelloYou).run()

This new automation step has two inputs of type string, first_name and last_name. Optional input descriptions can be provided too and are printed in the command synopsis when running the script with the '--help' argument.

The second input last_name has a default value and thus becomes an optional input. The execute function simply concatenates both strings, assigns the result to step output full_name, and prints the full name to the console.

Let's execute this new script:

$ python helloyou.py run
usage:
python my_automation.py run [args]
run: error: missing input --first_name

As you can see, the automation script complains that we did not specify the first_name input. In other words, the automation script knows which inputs are required and does not allow us to run it without specifying them. Let's try again with both inputs specified:

$ python helloyou.py run --first_name Rosalind --last_name Franklin
2019-03-18 14:06:21,713    INFO [  freyja.log:  68]: (MainThread  ) Logging configured
2019-03-18 14:06:21,713    INFO [freyja.graph: 362]: (MainThread  ) Process: 11210
2019-03-18 14:06:21,714    INFO [freyja.graph: 489]: (MainThread  ) Instantiating Step <HelloYou "main">
2019-03-18 14:06:21,714    INFO [freyja.graph: 217]: (MainThread  ) Step <HelloYou ("main")> queued for execution
2019-03-18 14:06:21,715    INFO [freyja.graph: 648]: (main        ) Initiating execution for for: Step <HelloYou ("main")>
2019-03-18 14:06:21,715    INFO [freyja.graph: 658]: (main        ) Execution started for: Step <HelloYou ("main")>
2019-03-18 14:06:21,716    INFO [freyja.graph: 664]: (main        ) RUNNING: main
Hello Rosalind Franklin!
2019-03-18 14:06:21,716    INFO [freyja.graph: 690]: (main        ) Execution finished for: Step <HelloYou ("main")>
2019-03-18 14:06:21,717    INFO [freyja.graph: 114]: (Executor-main) Executor done
2019-03-18 14:06:21,717    INFO [freyja.graph: 406]: (MainThread  )
-----------------------------------------------------------------------
Execution summary:
    Steps instantiated: 1
    Steps incomplete:   0
    Steps executed:     1
    Steps failed:       0
-----------------------------------------------------------------------

This time the script executes successfully and we see the expected output 'Hello Rosalind Franklin!'.