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 glob, run
def upper(src, dst):
run("tr '[:lower:]' '[:upper:]' < ${inp} > ${out}", shell=True, 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:
This will show the following output:
DIRECTOR │ Listening on /tmp/stepup-########/director (StepUp Core 3.2.3.post54)
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 │ Trying to delete 0 outdated output(s)
DIRECTOR │ See you!