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

cannot parse recipe with jinja {% if branches #258

Open
minrk opened this issue Nov 26, 2024 · 2 comments
Open

cannot parse recipe with jinja {% if branches #258

minrk opened this issue Nov 26, 2024 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@minrk
Copy link

minrk commented Nov 26, 2024

What happened?

cannot parse recipe with jinja conditional branches, meaning it cannot be used for conda-smithy recipe-lint on conda-forge.

To Reproduce

Sample recipe:

{% set variable = 10 %}
package:
  name: test-pkg
  version: 1.0.0

source:
  url: https://doesntmatter.horse

build:
  number: 1

requirements:
  host:
    {% if variable >= 10 %}
    - libblas
    {% endif %}

extra:
  recipe-maintainers:
    - minrk
  • OS: mac m1
  • Conda Recipe Manager version 0.3.4
from conda_recipe_manager.parser.recipe_parser import RecipeParser

with open("recipe/meta.yaml") as f:
    RecipeParser(f.read())

gives:

File ~/conda/lib/python3.11/site-packages/conda_recipe_manager/parser/recipe_reader.py:480, in RecipeReader.__init__(self, content)
    478     depth_to_pop = (cur_indent - new_indent) // TAB_SPACE_COUNT
    479     for _ in range(depth_to_pop):
--> 480         node_stack.pop()
    481 cur_indent = new_indent
    482 # Look at the stack to determine the parent Node and then append the current node to the new parent.

IndexError: pop from empty list
@minrk minrk added bug Something isn't working to sort Needs additional investigation labels Nov 26, 2024
@schuylermartin45
Copy link
Collaborator

I have known about this for a while, I just have never written it down publicly. So thanks for creating this issue! JINJA conditionals and for loops are not currently supported.

The integration test data set indicates that these JINJA template constructs are not commonly used. I'm not sure when we will find time to address this given the limited number of recipes that utilize that feature set. It is a fairly large ask, especially if we are all moving to the V1 recipe format.

If you are looking to use this library in conda-smithy, I would suggest a dual method approach as a stop-gap. If the parser fails to parse something, fall back to a known/existing approach.

@schuylermartin45
Copy link
Collaborator

As mentioned in the discussion of #273 it might not be worth adding full parse support for these macros given the transition to the V1 recipe format.

However, it might be worth it to attempt to upgrade the ifdef macros to selectors using some hacky/nasty regular expressions in crm convert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants