Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-rendering with conditionally defined Jinja variables fails under conda-build 24.7 #2011

Closed
jakirkham opened this issue Aug 3, 2024 · 4 comments

Comments

@jakirkham
Copy link
Member

jakirkham commented Aug 3, 2024

Recently have encountered the following bug when re-rendering with conda-smithy depending on the conda-build version used. This is very likely is a conda-build bug. However conda-build itself does not encounter the issue when building recipes. So it could be how conda-smithy and conda-build interact, which causes the issue

The core of the bug is involves Jinja variables that are conditionally defined (meaning there are cases where they are undefined). Previously if a Jinja variable would be undefined for a certain condition (like an OS), this was not an issue if that condition was skipped. However now the conditionally defined variable is a problem even in case where it is never used

Take this recipe (a boiled down example to show the core bug), version here is conditionally defined. It will only be defined on linux. Otherwise version is undefined. Previously the top-level skip, which limited the build to linux, would have been sufficient to ensure version was defined for the relevant condition. So the version would have been defined anywhere this recipe would build

{% set version = "1" %}  # [linux]

package:
  name: undef_jinja_tst
  # Fails with conda-build 24.7 (works for conda-build 24.5)
  version: {{ version }}
  # Passes with conda-build 24.7
  #version: {{ version }}  # [linux]

build:
  skip: true  # [not linux]

test:
  commands:
    - exit 0

Also when re-rendering this recipe using conda-build version 24.5, this would work ok. However starting with conda-build version 24.7, the following recipe fails to re-render

To workaround this with conda-build version 24.7, it seems one needs to do one of the following:

  1. Add more version definitions for other conditions until it passes (so osx, win, etc.)
  2. Define a fallback for version: Adding this to line 2 {% set version = version|default("") %}
  3. Add selectors to all lines that use version (shown above)

Ideally none of this would be needed. However it appears something has changed about how conda-build renders recipes and where conda-smithy interacts with that rendering functionality. As a result this now produces errors for conditions the recipe cannot actually be built for anyways (because of the skip)

Edit - Also surfaced this upstream: conda/conda#13995 (comment)

@jakirkham
Copy link
Member Author

Looks like this would be addressed in upstream PR: conda/conda-build#5458

@jakirkham
Copy link
Member Author

This was fixed with Michael's upstream PR ( conda/conda-build#5458 ), which was included in conda-build version 24.9.0

Closing as resolved

@minrk
Copy link
Member

minrk commented Oct 2, 2024

I'm still seeing this in a couple of cases with conda/conda-build@5f66f2b. For example, noarch_platform is undefined for osx-64 in jupyterhub, which causes a rerender error with:

conda_build.exceptions.CondaBuildUserError: Failed to render jinja template in /Users/minrk/dev/conda-forge/jupyterhub-feedstock/recipe/meta.yaml:
'noarch_platform' is undefined

when trying to render osx-64, which won't be built. I'm not really sure why it's trying to render platforms other than noarch platforms, but I assume there's a reason. I think the reason conda/conda-build#5458 didn't fix this is because the mac builds aren't skipped internally, they are skipped after render in the keep_noarch check.

@minrk
Copy link
Member

minrk commented Oct 2, 2024

This also accounts for at least one failure in the Python 3.13 migration:

jinja2.exceptions.UndefinedError: 'PYTHON' is undefined

in iris, which I believe is conda/conda-build#5424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants