Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ steps:
let:
- work_dir = Session.WorkingDirectory / 'output'
- frame_file = Param.OutputDir / string(Task.Param.Frame)
- data_file = Task.File.Data
embeddedFiles:
- name: Data
type: TEXT
filename: data.txt
data: "hello"
actions:
onRun:
command: echo
args: ["{{work_dir}}", "{{frame_file}}"]
args: ["{{work_dir}}", "{{frame_file}}", "{{data_file}}"]

- name: SimpleActionLet
parameterSpace:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
template:
specificationVersion: jobtemplate-2023-09
extensions:
- EXPR
name: TestJob
parameterDefinitions:
- name: Greeting
type: STRING
default: hello
steps:
- name: Step1
script:
embeddedFiles:
- name: config
type: TEXT
data: "greeting={{Param.Greeting}}"
let:
- "cfg = Task.File.config"
- "has_parent = len(string(cfg.parent)) > 0"
actions:
onRun:
command: python
args:
- -c
- |
import os
path = {{ repr_py(cfg) }}
exists = os.path.isfile(path)
content = open(path).read() if exists else ''
print(f'EXISTS:{exists}')
print(f'CONTENT:{content}')
print(r'HAS_PARENT:{{ has_parent }}')
expected:
output:
- "EXISTS:True"
- "CONTENT:greeting=hello"
- "HAS_PARENT:true"
7 changes: 5 additions & 2 deletions rfcs/0005-expression-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -1964,8 +1964,11 @@ steps:
##### ScriptTemplate Extension

When `let` appears in a `ScriptTemplate`, bindings are evaluated once per task (or once
per environment action). The bound names are available in `actions` and can reference
`Task.Param`:
per environment action). The bound names are available in `actions` and `embeddedFiles`,
and can reference `Task.Param.*` as well as the embedded file path symbols of the same
script (`Task.File.*` in a step script, `Env.File.*` in an environment script) — the
file path is determined before the bindings are evaluated, even though the file content
is evaluated separately:

```yaml
script:
Expand Down
9 changes: 5 additions & 4 deletions wiki/2023-09-Template-Schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -1458,16 +1458,17 @@ and where the bound names are available:
| Location | Can Reference | Bound Names Available In |
|----------|---------------|--------------------------|
| `<StepTemplate>.let` | `Param.*`, `RawParam.*`, `Job.Name`, `Step.Name`, earlier bindings in same `let` | *stepEnvironments*, *hostRequirements*, *parameterSpace*, *script* (including nested `<StepScript>.let` or `<SimpleAction>.let`) |
| `<StepScript>.let` | `Param.*`, `RawParam.*`, `Task.Param.*`, `Task.RawParam.*`, `Session.*`, `Job.Name`, `Step.Name`, step-level bindings, earlier bindings in same `let` | *actions*, *embeddedFiles* |
| `<StepScript>.let` | `Param.*`, `RawParam.*`, `Task.Param.*`, `Task.RawParam.*`, `Session.*`, `Task.File.*`, `Job.Name`, `Step.Name`, step-level bindings, earlier bindings in same `let` | *actions*, *embeddedFiles* |
| `<SimpleAction>.let` | `Param.*`, `RawParam.*`, `Task.Param.*`, `Task.RawParam.*`, `Session.*`, `Job.Name`, `Step.Name`, step-level bindings, earlier bindings in same `let` | *script*, *args* |
| `<EnvironmentScript>.let` | `Param.*`, `RawParam.*`, `Session.*`, `Env.File.*`, `Job.Name`, earlier bindings in same `let` | *actions*, *embeddedFiles* |

Note: `Task.Param.*` and `Task.RawParam.*` are only available in `<StepScript>` and `<SimpleAction>` contexts because task parameter
values are not known until task execution time.

Note: `Env.File.*` symbols in `<EnvironmentScript>.let` refer to embedded files defined in the same `<EnvironmentScript>`.
The file path is determined before evaluation, so `let` bindings can reference the path where the file will be written,
even though the file content (which may also contain format strings) is evaluated separately.
Note: `Task.File.*` symbols in `<StepScript>.let` and `Env.File.*` symbols in `<EnvironmentScript>.let` refer to
embedded files defined in the same script. The file path is determined before evaluation, so `let` bindings can
reference the path where the file will be written, even though the file content (which may also contain format
strings) is evaluated separately.

Note: `Job.Name` is concrete at job creation, so it is available in every `let` scope. `Step.Name` is scoped to the
Step Template (see [7.3.1](#731-value-references)), so it is available in the Step-side `let` scopes but not in
Expand Down
Loading