-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add custom functions to the Jinja context #84
Comments
Uunnn... That looks interesting |
Can we get more use cases? The one mentioned as an example is not even necessary anymore. |
I have mixed feeling about this. It's understandable the motivation to allow users to add their own functions, but, on the other hand, Let's continue the discussion, but keeping in mind that opening the door to custom user code that can execute anything and import anything would open the possibility of creating extra-complicated workflows. |
Agree with @tadeu, we should ponder first what are the use cases before adding features that we might not even actually use, or use very little. Also the fact that it is just a small utility is attractive, in my view. |
I don't have a strong use case anymore (I guess the one I had before was not strong either 😄 ) , but I like @edisongustavo 's initiative because this could be helpful eventually (if this was already permitted, I would not have wasted all your time yesterday with those discussions!). I understand these are not strong arguments though for this additional feature. My main concern is that of @tadeu , in which we could open the doors to hell for users to write complicated What if we at least supported inline lambda functions in comments with the following tentative syntax: ## env = lambda name: os.environ.get(name)
## versionformat = lambda ver: '.'.join(ver)
{% set conda_py = env('CONDA_PY') or '35' %}
name: web-ui-py{{ conda_py }}
dependencies:
- python={{ versionformat(conda_py) }}
- boost
- cmake
- gcc # [linux]
- ccache # [not win]
- clcache # [win] |
@tadeu , That is why I suggested implementing that as plugin system, any plugin addition will be the programmer's risk. |
I'm afraid inventing our own mini-language, or parsing the file ourselves and generating Python code, is not a good direction. We now have to deal with scopes or supporting single-line functions, which limits its usability. We would be supporting "jinja + our own extension language". We would need to parse the file first, execute Python code to generate the lambda functions, and inject it later on the Jinja2 namespace. I'm afraid I'm a 👎 on this idea. If we want to extend what's available in the Jinja2 namespace, I think using plain Python modules is the way to go, with an But before we go down that route, I would like to see good use cases first, because we have been using |
It is a good idea for a general framework, but again I would like to see more use cases before we even phantom introducing a plugin system. |
By "plugin system" you mean the entry points (similar to how pytest do)? The inline option is interesting since all pieces are found in the same file. |
We could relly on jinja extensions (jinja docs)... but boy that looks complicated. |
Just a side note:
I don't consider that as wasted time at all :) |
Thanks, @tadeu ! Good to know.
I was already expecting a denial from you, @nicoddemus ! 😉 |
I agree with the points presented and I vote -1 on the idea as well. If we ever show a very valid use case, then we can reopen this. |
I've formed an opinion here. A templating language is good for when you can describe, in this case, an environment in what looks like more or less yaml. It's when you want to be more programmatic or just don't want to use yaml or jinja in yaml for what ever reason that this becomes a problem. Here's a (practical) example where jinja/yaml fails at expression.
A low-interfacing way here is to just have the user optionally provide a This keeps conda devenv 'simple'. While the user is responsible (completely) for 'complicated' setups. I feel like working within jinja to extend makes it more complicated. Just go all the way and use a general purpose programming language . |
Problem
Programming in Jinja is not much fun, so if we need to do more complicated functions, the code can be quite complicated (or impossible).
Take this example (which doesn't work and just frustrates the user):
Proposal
It would be great if I could have files (
*.conda-devenv.py
) with:Then in my
environment.devenv.yml
:Implementation details
__all__
.Questions
conda-devenv.py
) or all files in the current directory (*.conda-devenv.py
) ?load_functions("custom-functions-conda-devenv.py")
) ?Why???
This feature request is based on the discussion held in #83. If conda-devenv had this capability, then the user would never feel the need to open that PR, he would just write his custom functions.
The text was updated successfully, but these errors were encountered: