-
Notifications
You must be signed in to change notification settings - Fork 423
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
metadata: Allow selectors in imported jinja templates #739
metadata: Allow selectors in imported jinja templates #739
Conversation
This is sort of duplication of functionality to me - I thought the point of jinja2 stuff was at least partially to obviate selectors and replace them with something more flexible. Why have both of these? Are selectors just easier sometimes that the equivalent template expression? |
In jinja is more powerful, but for historical reasons, I doubt selectors will be removed any time soon (right)? Since Consider this contrived example. Suppose the user wants to tag each package with the user name of the person who made it, using the {% set user_id = USER %} # [unix]
{% set user_id = "winuser" %} # [win]
package:
name: mypackage
version: 1.0
build:
number: 1
string: {{user_id}}_{{PKG_BUILDNUM}} OK, that works just fine. But if she wants to do this in several packages, perhaps she'll want to define # meta.yaml
{% from 'variables.jinja' import user_id %}
package:
name: mypackage
version: 1.0
build:
number: 1
string: {{user_id}}_{{PKG_BUILDNUM}} # variables.jinja
{% set user_id = USER %} # [unix]
{% set user_id = "winuser" %} # [win] If she naively copies-and-pastes the lines from If she notices that this happened -- and understands why it happened -- she can fix it using the appropriate jinja logic instead: # variables.jinja
{% if unix %}
{% set user_id = USER %}
{% else %}
{% set user_id = "winuser" %}
{% endif %} That's a little uglier, but still not terrible. I think the bigger problem is that copy-and-paste from |
Yes, I see your point. I thought jinja had nicer inline if statements. This is fine with me. @groutr @kalefranz, can either of you OK this? |
Isn't there a way to make the selectors available in the jinja context, similar to what now is done with |
I think you're referring to the fact that certain variables are allowed in selectors, e.g. build:
string: py{{py}}_npy{{np}} This PR doesn't change that, but it also respects the removal of code with a selector (e.g. |
24a1dd6
to
796175a
Compare
Seems like a simple and practical change. Any chance we can get this in? It seems to have sat here for awhile. Is there something blocking it that I don't understand? |
Thanks @stuarteberg |
Thanks @msarahan. |
As tangentially mentioned in #728, it would be nice if selectors (e.g.
# [not win]
) were respected in not justmeta.yaml
itself, but also in any jinja templates that it happens to import. This PR implements support for just that, with a simple test.