Skip to content

Objects loaded from file cannot be indexed into later #1423

@vyasr

Description

@vyasr

When using the (experimental) load_from_file feature, it seems like the object data must be accessed immediately. The data cannot be stored into a context. I doubt that the issue is in load_from_file, it seems more likely to be a limitation of the Jinja subscripting support, but I wasn't sure of the best way to create an object inline that would represent this issue so it is likely that there is a simpler MWE available.

The problem can be demonstrated by copying these two files into a directory:

# pyproject.toml
[build-system]
build-backend = "setuptools.build_meta"
requires = [
    "setuptools",
]

[project]
name = "test"
version = "0.1.0"
# recipe.yaml
context:
  pyproject_data: ${{ load_from_file("pyproject.toml") }}
  # Uncomment these to test the different options below
  #name: ${{ pyproject_data.project.name }}
  #version: ${{ pyproject_data.project.version }}

package:
  # Does not work
  #name: ${{ pyproject_data.project.name }}
  #version: ${{ pyproject_data.project.version }}
  # Also does not work (assumes that the above
  #name: ${{ name }}
  #version: ${{ version }}
  # This works
  name: ${{ load_from_file("pyproject.toml").project.name }}
  version: ${{ load_from_file("pyproject.toml").project.version }}

source:
  path: .

build:
  number: 0
  script: |
    echo "The name is ${{ name }}"
    echo "The data is ${{ version }}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions