Skip to content

No Rules

Most other build 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 this way, e.g., plan(), copy(), getenv() and call(). 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: docs/getting_started/no_rules/

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

Create the following plan.py:

#!/usr/bin/env python3
from stepup.core.api import run, shq, static


def upper(src, dst):
    run(f"tr '[:lower:]' '[:upper:]' < {shq(src)} > {shq(dst)}", shell=True, inp=src, out=dst)


for path in static("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
sb -j 1

This will show the following output:

DIRECTOR │ Listening on /tmp/stepup-########/director (StepUp Core 4.0.0)
 STARTUP │ (Re)initialized boot script
   PHASE │ build
   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
DIRECTOR │ Ran 3 job(s).
DIRECTOR │ Trying to remove 0 deletable file(s) and empty director(y|ies)
DIRECTOR │ See you!