custom_log_stage

Simple demo for how to modify the ci_exec defaults to suit user preferences.


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.

demos.custom_log_stage.log_stage(stage, **kwargs)[source]

Sample wrapper #1: provide custom behavior of log_stage.

demos.custom_log_stage.log_sub_stage(sub_stage, **kwargs)[source]

Sample wrapper #2: enable sub-stages to be printed (e.g., for big scripts).

demos.custom_log_stage.bold_green(msg)[source]

Sample wrapper #3: return msg in bold green text.

demos.custom_log_stage.do_work(n, width = 80)[source]

Ignore this function, pretend this is the real work you need to do.

demos.custom_log_stage.main()[source]

Execute all build stages and log progress.