Skip to content

task

Tasks are commands to run while rendering a composition.

Classes

Task pydantic-model

Bases: BaseModel

A task to run while rendering a composition.

Show JSON schema:
{
  "description": "A task to run while rendering a composition.",
  "properties": {
    "command": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      ],
      "description": "The command to run.",
      "title": "Command"
    },
    "use_shell": {
      "default": false,
      "description": "Whether to run the command in a shell.\n\nIf `command` is a str, this is always `True`.",
      "title": "Use Shell",
      "type": "boolean"
    },
    "env": {
      "anyOf": [
        {
          "additionalProperties": {
            "type": "string"
          },
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Environment variables to set when running the command.\n\nEach environment variable value may be a template string rendered using the context so far.",
      "title": "Env"
    },
    "when": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "A template string that will render as `True` if the task should run.",
      "title": "When"
    },
    "context_variable_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "The name of a context variable that will be set to the command's stdout. If not provided, the the output is not saved to the context.",
      "title": "Context Variable Name"
    }
  },
  "required": [
    "command"
  ],
  "title": "Task",
  "type": "object"
}

Fields:

Validators:

Attributes

command pydantic-field
command: str | List[str]

The command to run.

context_variable_name pydantic-field
context_variable_name: Optional[str] = None

The name of a context variable that will be set to the command’s stdout. If not provided, the the output is not saved to the context.

env pydantic-field
env: Optional[EnvDict] = None

Environment variables to set when running the command.

Each environment variable value may be a template string rendered using the context so far.

use_shell pydantic-field
use_shell: bool = False

Whether to run the command in a shell.

If command is a str, this is always True.

when pydantic-field
when: Optional[str] = None

A template string that will render as True if the task should run.

Functions

validate_use_shell pydantic-validator
validate_use_shell() -> Task

Set use_shell to True if command is a str.

Functions

execute_task

execute_task(task: Task, context: dict) -> dict

Execute a task.

PARAMETER DESCRIPTION
task

The task to execute

TYPE: Task

context

The current context

TYPE: dict

RETURNS DESCRIPTION
dict

The updated context.