Skip to content

Unpacking list templates outside cmd #8171

Open
@abhmul

Description

@abhmul

For one project, I am running a foreach stage, where each step may have a different list of dependencies. I wanted to use templating to fill in the list of dependencies, but it seems for whatever I tried, the syntax was not supported. Below is a simple example that doesn't include the foreach:

# params.yaml
those:
  - script.py
  - script2.py

I first tried

# dvc.yaml
stages:
  hello_world:
    cmd: python script.py
    deps: 
      - ${those}
    outs:
      - hello.txt

Running dvc repro I get

>>> dvc repro
ERROR: failed to parse 'stages.hello_world.deps' in 'dvc.yaml':
Cannot interpolate data of type 'list'

This wouldn't have made that much sense to me anyways since it reads like I'm expanding a list within an entry of another list.

I also tried

stages:
  hello_world:
    cmd: python script.py
    deps: ${those}
    outs:
      - hello.txt

and got

>>> dvc repro
'./dvc.yaml' validation failed.

expected a list, in stages -> hello_world -> deps, line 3, 
column 5
  2   hello_world:                                          
  3 │   cmd: python script.py                               
  4 │   deps: ${those} 

This one makes more sense since it reads similar to how the expansion in foreach stages works.

Please let me know

  1. Is what I'm trying to achieve already supported? In that case the templating documentation should be updated, since this behavior is not described anywhere.
  2. If this is not currently supported, can this be supported in the future? The latter syntax would be a natural extension of the syntax for templating in foreach stages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A: templatingRelated to the templating feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions