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.set
    comment: set some arb values to use in 
             next steps.
    in:
      set:
        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

only run step if variable exists permalink

You can use a py string expression only to run a step if a key exists in context.

- name: pypyr.steps.echo
  run: !py "'myvar' in locals()" 
  in:
    echoMe: You'll only see me if myvar exists in context.

- name: pypyr.steps.echo
  run: !py "'myvar' not in locals()" 
  in:
    echoMe: You'll only see me if myvar does NOT exist in context.

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 .