custom_log_stage¶
Simple demo for how to modify the ci_exec
defaults to suit user preferences.
Run this demo by cloning the repository:
$ git clone https://github.com/svenevs/ci_exec.git
$ cd ci_exec
$ python -m demos custom_log_stage
By default log_stage()
will log in bold green, using "="
as
a separator. This makes stages stick out / easy to spot during CI builds, but users may
not prefer this style. Instead of manually calling with explicit arguments each time:
from ci_exec import Colors, Styles, log_stage
# ... some time later ...
log_stage("CMake.Configure", color=Colors.Cyan, style=Styles.Regular, fill_char="-")
it is preferable to just create your own wrapper function. If you want a "-"
fill
character in regular cyan each time, why force yourself to type that out every time? It
is much cleaner to just define your own wrapper with your preferred defaults. The most
simple wrapper you can create:
import ci_exec
from ci_exec import Colors, Styles
def log_stage(stage: str):
ci_exec.log_stage(stage, color=Colors.Cyan, style=Styles.Regular, fill_char="-")
Chances are, this will satisfy 95% of use-cases. The code in this file demonstrates how
you can enable keyword arguments on your wrapper function so that if you have a scenario
where you want to override your custom log_stage
function defaults for just one or
two use cases you can.
You could of course just set ci_exec.log_stage.__kwdefaults__
, but changing this can
lead to some surprising behavior if you don’t know what you are doing. Additionally,
other readers will have a harder time following what your build script is doing.