yaml_workflow.tasks.shell_tasks¶
yaml_workflow.tasks.shell_tasks
¶
Shell operation tasks for executing commands and managing processes.
Classes¶
Functions¶
check_command(command: Union[str, List[str]], cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None, shell: bool = False, timeout: Optional[float] = None) -> str
¶
Run a command and raise an error if it fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
Command to run (string or list of arguments) |
required |
cwd
|
Optional[str]
|
Working directory for the command |
None
|
env
|
Optional[Dict[str, str]]
|
Environment variables to set |
None
|
shell
|
bool
|
Whether to run command through shell |
False
|
timeout
|
Optional[float]
|
Timeout in seconds |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Command output (stdout) |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If command returns non-zero exit code |
Source code in src/yaml_workflow/tasks/shell_tasks.py
get_environment() -> Dict[str, str]
¶
Get current environment variables.
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict[str, str]: Dictionary of environment variables |
process_command(command: str, context: Dict[str, Any]) -> str
¶
Process a shell command template with the given context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
Shell command template |
required |
context
|
Dict[str, Any]
|
Template context |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Processed shell command |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If template resolution fails (via handle_task_error) |
Source code in src/yaml_workflow/tasks/shell_tasks.py
resolve_platform_command(command: Any) -> str
¶
Resolve a platform-specific command dict to the appropriate string.
When command is a :class:dict with unix and/or windows keys
the correct variant is chosen based on :func:platform.system. Any other
value is returned unchanged (callers are expected to validate the type).
Example workflow YAML::
- name: list_files
task: shell
inputs:
command:
unix: "ls -la"
windows: "dir /W"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Any
|
A command string, list, or a dict with |
required |
Returns:
| Type | Description |
|---|---|
str
|
The resolved command string or list (unchanged if not a platform dict). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/yaml_workflow/tasks/shell_tasks.py
run_command(command: Union[str, List[str]], cwd: Optional[str] = None, env: Optional[Dict[str, str]] = None, shell: bool = False, timeout: Optional[float] = None) -> Tuple[int, str, str]
¶
Run a shell command and return its output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Union[str, List[str]]
|
Command to run (string or list of arguments) |
required |
cwd
|
Optional[str]
|
Working directory for the command |
None
|
env
|
Optional[Dict[str, str]]
|
Environment variables to set |
None
|
shell
|
bool
|
Whether to run command through shell |
False
|
timeout
|
Optional[float]
|
Timeout in seconds |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[int, str, str]
|
Tuple[int, str, str]: Return code, stdout, and stderr |
Source code in src/yaml_workflow/tasks/shell_tasks.py
set_environment(env_vars: Dict[str, str]) -> Dict[str, str]
¶
Set environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_vars
|
Dict[str, str]
|
Dictionary of environment variables to set |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict[str, str]: Updated environment variables |
Source code in src/yaml_workflow/tasks/shell_tasks.py
shell_task(config: TaskConfig) -> Dict[str, Any]
¶
Run a shell command with namespace support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
TaskConfig
|
Task configuration with namespace support |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Command execution results |
Raises:
| Type | Description |
|---|---|
TaskExecutionError
|
If command execution fails or template resolution fails |
Source code in src/yaml_workflow/tasks/shell_tasks.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |