run permalink

selectively run step permalink

Runs this step if True, skips step if False.

Default is True. The means by default pypyr will run a step unless you tell it otherwise.

You’ll almost always use run with substitutions, so you set the value at run-time from context.

set run with substitution expressions permalink

You can use truthy expressions with run, skip and swallow. This means you can selectively run a step depending on if an object is not null and evaluates truthy.

# ./run-decorator.yaml
steps:
  - name: pypyr.steps.echo
    comment: run is True by default
    in:
      echoMe: begin
  - name: pypyr.steps.echo
    run: False
    in:
      echoMe: this won't run coz run is False.
  - name: pypyr.steps.echo
    run: 0
    in:
      echoMe: 0 in a boolean context means False.
  - name: pypyr.steps.contextsetf
    comment: set some arb values to use in 
             next steps.
    in:
      contextSetf:
        isAnotherThing: 1 # int 1 evals true.
        isThing: False
        arbObj: [] # empty list
  - name: pypyr.steps.echo
    run: '{arbObj}'
    in:
      echoMe: won't run because truthy empty list is False
  - name: pypyr.steps.echo
    run: '{isAnotherThing}'
    in:
      echoMe: you'll see me.
  - name: pypyr.steps.echo
    in:
      echoMe: end

This pipeline will run like this:

$ pypyr run-decorator
begin
you'll see me.
end

combine run & skip permalink

You can combine run and skip on the same step, only to run the step in certain conditions and to skip it on other conditions. Remember that skip supersedes run where run=True. If run=False, skip won’t have any impact, the step will never run.

# ./run-and-skip.yaml
steps:
  - name: pypyr.steps.echo
    in:
      echoMe: begin
  - name: pypyr.steps.echo
    run: True
    skip: True
    in:
      echoMe: this won't run, because skip supersedes run.
  - name: pypyr.steps.echo
    comment: run evaluates first. 
             if run is False, skip won't have any influence,
             the step will never run.
    run: False
    skip: False
    in:
      echoMe: this won't run, because run evaluates before skip.
  - name: pypyr.steps.echo
    run: True
    skip: False
    in:
      echoMe: you'll see me.
  - name: pypyr.steps.echo
    in:
      echoMe: end

This will result in:

$ pypyr run-and-skip
begin
you'll see me.
end

see also

last updated on .