Skip to content

Jinja variables from main recipe not available in outputs #5773

@jpfeuffer

Description

@jpfeuffer

Checklist

  • I added a descriptive title
  • I searched open reports and couldn't find a duplicate

What happened?

My meta.yaml:

{% set name = "bar" %}
{% set version = "1.0.0" %}

package:
  name: {{ name|lower  }}-meta
  version: {{ version  }}

source:
  url: https://github.com/foo/bar/releases/download/release%2F{{ version }}/bar-{{ version }}.tar.gz
  md5: 8d0b4d1d333f069959f7d5ff1c77a90f

build:
  number: 0

{% set deps = [
    "eigen >=3.4.0",
    "xerces-c",
    "libsvm"
]
+ (["libgomp", "sysroot_linux-64 =2.17"] if linux else [])
+ (["llvm-openmp"] if osx else [])
%}

requirements:
    
    build:
      - {{ compiler('cxx') }}
      - cmake
      - ninja
    
    host:
    {% for dep in deps %}
      - {{ dep }}
    {% endfor %}

outputs:
  - name: libfoo
    version: {{ version }}
    # just install the lib parts with cmake
    #script: package_libfoo.sh
    requirements:
        build:
          - cmake
        host:
        {% for dep in deps %}
          - {{ dep }}
        {% endfor %}
    build:
        run_exports:
          # we need to duplicate dependencies of the main package in host
          #  to get the correct pinnings
          - {{ pin_compatible('xerces-c', max_pin='x.x') }}
          - {{ pin_compatible('eigen', max_pin='x.x') }}

# Many other outputs

about:
  home: "https://github.com/foo/bar"

conda render meta.yaml

Result:

Traceback (most recent call last):
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 2097, in _get_contents
    rendered = template.render(environment=env)
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 12, in top-level template code
jinja2.exceptions.UndefinedError: 'deps' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/miniforge3/envs/foo/bin/conda-render", line 11, in <module>
    sys.exit(execute())
             ~~~~~~~^^
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/cli/main_render.py", line 221, in execute
    metadata_tuples = api.render(
        parsed.recipe,
    ...<2 lines>...
        variants=parsed.variants,
    )
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/api.py", line 68, in render
    return render_metadata_tuples(
        metadata_tuples,
    ...<3 lines>...
        bypass_env_check=bypass_env_check,
    )
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/render.py", line 1097, in render_metadata_tuples
    for od, om in meta.get_output_metadata_set(
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        permit_unsatisfiable_variants=permit_unsatisfiable_variants,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        permit_undefined_jinja=not finalize,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        bypass_env_check=bypass_env_check,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 2781, in get_output_metadata_set
    conda_packages = finalize_outputs_pass(
        ref_metadata,
    ...<3 lines>...
        bypass_env_check=bypass_env_check,
    )
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 1063, in finalize_outputs_pass
    output_d = om.get_rendered_output(metadata.name()) or {
               ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 2867, in get_rendered_output
    for output_ in self.get_rendered_outputs_section(
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        permit_undefined_jinja=permit_undefined_jinja, variant=variant
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/miniforge3/envs/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 2849, in get_rendered_outputs_section
    self._get_contents(
    ~~~~~~~~~~~~~~~~~~^
        permit_undefined_jinja=permit_undefined_jinja,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        variant=variant,
        ^^^^^^^^^^^^^^^^
    )
    ^
  File "/miniforge3/env/foo/lib/python3.13/site-packages/conda_build/metadata.py", line 2107, in _get_contents
    raise CondaBuildUserError(
        f"Failed to render jinja template in {self.meta_path}:\n{str(ex)}"
    )
conda_build.exceptions.CondaBuildUserError: Failed to render jinja template in /src/meta.yaml:
'deps' is undefined

Conda Info

active environment : foo
    active env location : /Users/jpfeuffer/miniforge3/envs/foo
            shell level : 2
       user config file : /Users/jpfeuffer/.condarc
 populated config files : /Users/jpfeuffer/miniforge3/.condarc
                          /Users/jspfeuffer/.condarc
          conda version : 23.3.1
    conda-build version : not installed
         python version : 3.10.14.final.0
       virtual packages : __archspec=1=arm64
                          __osx=15.5=0
                          __unix=0=0
       base environment : /Users/jpfeuffer/miniforge3  (writable)
      conda av data dir : /Users/jpfeuffer/miniforge3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/jpfeuffer/miniforge3/pkgs
                          /Users/jpfeuffer/.conda/pkgs
       envs directories : /Users/jpfeuffer/miniforge3/envs
                          /Users/jpfeuffer/.conda/envs
               platform : osx-arm64
             user-agent : conda/23.3.1 requests/2.32.3 CPython/3.10.14 Darwin/24.5.0 OSX/15.5
                UID:GID : 501:20
             netrc file : None
           offline mode : False

Conda Config

==> /Users/julianuspfeuffer/miniforge3/.condarc <==
channels:
  - conda-forge

==> /Users/julianuspfeuffer/.condarc <==
auto_activate_base: False
channels:
  - conda-forge

Conda list

# Name                    Version                   Build  Channel
archspec                  0.2.5              pyhd8ed1ab_0    conda-forge
attrs                     25.3.0             pyh71513ae_0    conda-forge
beautifulsoup4            4.13.4             pyha770c72_0    conda-forge
boltons                   25.0.0             pyhd8ed1ab_0    conda-forge
brotli-python             1.1.0           py313h928ef07_3    conda-forge
bzip2                     1.0.8                h99b78c6_7    conda-forge
c-ares                    1.34.5               h5505292_0    conda-forge
ca-certificates           2025.8.3             hbd8a1cb_0    conda-forge
cctools                   1021.4               h617d6d1_1    conda-forge
cctools_osx-arm64         1021.4               h356c9db_1    conda-forge
certifi                   2025.8.3           pyhd8ed1ab_0    conda-forge
cffi                      1.17.1          py313hc845a76_0    conda-forge
chardet                   5.2.0              pyhd8ed1ab_3    conda-forge
charset-normalizer        3.4.3              pyhd8ed1ab_0    conda-forge
click                     8.2.1              pyh707e725_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_1    conda-forge
conda                     25.7.0          py313h8f79df9_0    conda-forge
conda-build               25.7.0          py313h8f79df9_0    conda-forge
conda-index               0.6.1              pyhd8ed1ab_0    conda-forge
conda-libmamba-solver     25.4.0             pyhd8ed1ab_0    conda-forge
conda-package-handling    2.4.0              pyh7900ff3_2    conda-forge
conda-package-streaming   0.12.0             pyhd8ed1ab_0    conda-forge
cpp-expected              1.1.0                h177bc72_1    conda-forge
distro                    1.9.0              pyhd8ed1ab_1    conda-forge
evalidate                 2.0.5              pyhe01879c_0    conda-forge
filelock                  3.18.0             pyhd8ed1ab_0    conda-forge
fmt                       11.2.0               h440487c_0    conda-forge
frozendict                2.4.6           py313h63a2874_0    conda-forge
h2                        4.2.0              pyhd8ed1ab_0    conda-forge
hpack                     4.1.0              pyhd8ed1ab_0    conda-forge
hyperframe                6.1.0              pyhd8ed1ab_0    conda-forge
idna                      3.10               pyhd8ed1ab_1    conda-forge
jinja2                    3.1.6              pyhd8ed1ab_0    conda-forge
jsonpatch                 1.33               pyhd8ed1ab_1    conda-forge
jsonpointer               3.0.0           py313h8f79df9_1    conda-forge
jsonschema                4.25.0             pyhe01879c_0    conda-forge
jsonschema-specifications 2025.4.1           pyh29332c3_0    conda-forge
krb5                      1.21.3               h237132a_0    conda-forge
ld64                      954.16               hb625feb_1    conda-forge
ld64_osx-arm64            954.16               hc3387fa_1    conda-forge
libarchive                3.8.1           gpl_h46e8061_100    conda-forge
libcurl                   8.14.1               h73640d1_0    conda-forge
libcxx                    20.1.8               hf598326_1    conda-forge
libedit                   3.1.20250104    pl5321hafb1f1b_0    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.7.1                hec049ff_0    conda-forge
libffi                    3.4.6                h1da3d7d_1    conda-forge
libiconv                  1.18                 h23cfdf5_2    conda-forge
liblief                   0.16.6               h286801f_0    conda-forge
libllvm20                 20.1.8               h846d351_0    conda-forge
liblzma                   5.8.1                h39f12f2_2    conda-forge
libmamba                  2.3.1                he5fc5d6_1    conda-forge
libmambapy                2.3.1           py313h3a3527f_1    conda-forge
libmpdec                  4.0.0                h5505292_0    conda-forge
libnghttp2                1.64.0               h6d7220d_0    conda-forge
libsolv                   0.7.35               h5f525b2_0    conda-forge
libsqlite                 3.50.4               hf8de324_0    conda-forge
libssh2                   1.11.1               h1590b86_0    conda-forge
libxml2                   2.13.8               h226d0e7_1    conda-forge
libzlib                   1.3.1                h8359307_2    conda-forge
llvm-tools                20.1.8               hc7d33da_0    conda-forge
llvm-tools-20             20.1.8               hb8bff50_0    conda-forge
lz4-c                     1.10.0               h286801f_1    conda-forge
lzo                       2.10              h925e9cb_1002    conda-forge
markupsafe                3.0.2           py313ha9b7d5b_1    conda-forge
mbedtls                   3.6.3.1              h286801f_0    conda-forge
menuinst                  2.3.1           py313h8f79df9_0    conda-forge
msgpack-python            1.1.1           py313h0ebd0e5_0    conda-forge
ncurses                   6.5                  h5e97a16_3    conda-forge
nlohmann_json             3.11.3               h00cdb27_1    conda-forge
openssl                   3.5.2                he92f556_0    conda-forge
packaging                 25.0               pyh29332c3_1    conda-forge
patch                     2.7.6             h27ca646_1002    conda-forge
pip                       25.2               pyh145f28c_0    conda-forge
pkginfo                   1.12.1.2           pyhd8ed1ab_0    conda-forge
platformdirs              4.3.8              pyhe01879c_0    conda-forge
pluggy                    1.6.0              pyhd8ed1ab_0    conda-forge
psutil                    7.0.0           py313h90d716c_0    conda-forge
py-lief                   0.16.6          py313h928ef07_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.6           py313h90d716c_2    conda-forge
pycparser                 2.22               pyh29332c3_1    conda-forge
pysocks                   1.7.1              pyha55dd90_7    conda-forge
python                    3.13.5          hf3f3da0_102_cp313    conda-forge
python-libarchive-c       5.3                pyhe01879c_1    conda-forge
python_abi                3.13                    8_cp313    conda-forge
pytz                      2025.2             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.2           py313ha9b7d5b_2    conda-forge
readline                  8.2                  h1d1bf99_2    conda-forge
referencing               0.36.2             pyh29332c3_0    conda-forge
reproc                    14.2.5.post0         h5505292_0    conda-forge
reproc-cpp                14.2.5.post0         h286801f_0    conda-forge
requests                  2.32.4             pyhd8ed1ab_0    conda-forge
ripgrep                   14.1.1               h0ef69ab_1    conda-forge
rpds-py                   0.27.0          py313h80e0809_0    conda-forge
ruamel.yaml               0.18.14         py313h90d716c_0    conda-forge
ruamel.yaml.clib          0.2.8           py313h63a2874_1    conda-forge
setuptools                80.9.0             pyhff2d567_0    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
simdjson                  3.13.0               ha393de7_0    conda-forge
soupsieve                 2.7                pyhd8ed1ab_0    conda-forge
tapi                      1300.6.5             h03f4b80_0    conda-forge
tk                        8.6.13               h892fb3f_2    conda-forge
tqdm                      4.67.1             pyhd8ed1ab_1    conda-forge
truststore                0.10.3             pyhe01879c_0    conda-forge
typing-extensions         4.14.1               h4440ef1_0    conda-forge
typing_extensions         4.14.1             pyhe01879c_0    conda-forge
tzdata                    2025b                h78e105d_0    conda-forge
urllib3                   2.5.0              pyhd8ed1ab_0    conda-forge
yaml                      0.2.5                h925e9cb_3    conda-forge
yaml-cpp                  0.8.0                ha1acc90_0    conda-forge
zstandard                 0.23.0          py313h90d716c_2    conda-forge
zstd                      1.5.7                h6491c7d_2    conda-forge

Additional Context

As you can see, due to #3478 I have to specify my dependencies of the main meta-package in all of my outputs again and again to keep the underlying dependencies for specifying run_exports (different for every output) in-sync. I wanted to work around this by using a jinja list that I just paste in every output but was hit by this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type::bugdescribes erroneous operation, use severity::* to classify the type

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions