Skip to content

No Rules

Most other built tools introduce the concept of a build rule, to specify how a common build step can be applied to different inputs. StepUp does not need to introduce the concept of a build rule because Python functions and loops already provide similar facilities.

StepUp already comes with a few built-in rules defined int this way: plan(), copy(), mkdir(), getenv() and script(). Some of these were already discussed in the previous tutorials, and their source code offers some inspiration for writing your own.

Example

Example source files: getting_started/no_rules/

Here, we show a simple example of a custom rule to convert a text file to upper case with the tr command.

Create the following plan.py:

#!/usr/bin/env python
from stepup.core.api import glob, step


def upper(src, dst):
    step("tr '[:lower:]' '[:upper:]' < ${inp} > ${out}", inp=src, out=dst)


for path in glob("lower*.txt"):
    upper(path, "upper" + path[5:])

In addition, make two text files lower1.txt and lower2.txt with some random contents. Then make the plan executable and launch StepUp:

chmod +x plan.py
stepup -n -w1

This will show the following output:

  DIRECTOR │ Listening on /tmp/stepup-########/director
  DIRECTOR │ Launched worker 0
     PHASE │ run
     START │ ./plan.py
   SUCCESS │ ./plan.py
     START │ tr '[:lower:]' '[:upper:]' < lower1.txt > upper1.txt
   SUCCESS │ tr '[:lower:]' '[:upper:]' < lower1.txt > upper1.txt
     START │ tr '[:lower:]' '[:upper:]' < lower2.txt > upper2.txt
   SUCCESS │ tr '[:lower:]' '[:upper:]' < lower2.txt > upper2.txt
  WORKFLOW │ Dumped to .stepup/workflow.mpk.xz
  DIRECTOR │ Stopping workers.
  DIRECTOR │ See you!