-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Jinja line statements and comments #42930
Conversation
The jinja_line_statement_prefix and jinja_line_comment_prefix options allow salt users to use an alternative syntax for their states and other jinja templates. See http://jinja.pocoo.org/docs/templates/#line-statements fixes saltstack#36942
@CorvinM, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terminalmage, @thatch45 and @rallytime to be potential reviewers. |
salt/config/__init__.py
Outdated
@@ -1578,6 +1586,8 @@ def _gather_buffer_space(): | |||
'winrepo_passphrase': '', | |||
'winrepo_refspecs': _DFLT_REFSPECS, | |||
'syndic_wait': 5, | |||
'jinja_line_statement_prefix': None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a mismatch with the str
type defined above in L845. Would it be better to have ''
be the default for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, I went for the str & None combo because it seemed to make more sense logically to me but also because there were plenty of other options also using str & None in the same way. For example:
- environment L229 & L1399
- state_top_saltenv L240 & L1512
- log_level_logfile L373 & L1530
- etc..
But I do agree that ''
should fit these two options better, plus I can remove the (hackish?) explicit check for 'none'
.
Thanks, will update with ''
as the default.
I would like @whiteinge and @terminalmage to both take a look here for any additional feedback but I'm good with this at present. |
May want to compare to #41538 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting Jinja feature. (New to me.) Makes the syntax less verbose, though might be tricky to maintain alongside YAML.
In any case, this looks sufficiently opt-in so 👍 . The PR that Loren pointed out has a nearly identical approach plus it also has unit tests. Both PRs should be combined IMO.
@lorengordon commented on Aug 15, 2017, 9:47 PM GMT+2:
#41538 - the ambition is the same as this PR +
|
Made somewhat of a merge with #41538 Note: I've ignored the documentation (to avoid having to keep rewriting it) until we come to a conclusion on implementation (or very close to a conclusion). This commit should meet and exceed the ambitions of #41538 plus have some advantages:
If there is any question about why I chose to do something one way over the other please ask. @whiteinge @epcim @cachedout @terminalmage thoughts? |
@CorvinM commented on Aug 17, 2017, 3:19 AM GMT+2:
|
All the test failures appear to be unrelated (most of which are network errors) |
Go Go Jenkins! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CorvinM We'd love to find a way forward on this. Did you see the above proposal from @terminalmage ? |
Apologies for the slow response time, I haven't had much time to spare. @cachedout Yes, I did see @terminalmage's proposal. I don't agree with merging @epcim 's fork but if you all want it merged (which it looks like you do) I will do it anyways. I can see the motivation even if I don't agree with it. By merge I assume the goal is to include the commits from #41538 but not the actual changes? Because, I don't really see any changes that I can merge from #41538 that would be compatible or make sense with this PR besides the test case which I already "merged" with @epcim marked as author for the commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are mine comments.
doc/ref/configuration/master.rst
Outdated
|
||
If this is set to a string that is not empty, any line starting with this prefix | ||
will be interpreted as a line statement by the jinja renderer. | ||
Defaults to ``''`` and corresponds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
''
dont corespond with and commented variant above "#"
also I don't find ''
anyway usefull thant "#". Instead of I would suggest %
as the char. is there anything agains %
or %%
? I think it would be more close to today practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the documentation (including this file) is outdated with the code and I will likely have to rewrite most of it. The #
and ##
suggestions were just pulled from the example in the jinja documentation but I agree that %
and %%
would be much better for sls files. The only conflict I see is that %
is used for yaml directives but I don't think they are used often (if at all) in salt's sls files. Will change the suggestions to use %
and %%
.
conf/suse/master
Outdated
# Default jinja environment options for everything but | ||
# salt sls files | ||
#jinja_env: | ||
# line_statement_prefix: '#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this synced with the documentation below.
I vote for %
rather than #
or ''
conf/suse/master
Outdated
|
||
# Jinja environment options for salt sls files | ||
#jinja_sls_env: | ||
# line_statement_prefix: '#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@terminalmage for SLS files I would like to see the line_statemet_prefix enabled by default. I know you wrote few months ago - now way. But I still think it would be nice new "standard" that improves SLS readability.
I quite belive it should not affect old setups. But probably we should still check, test how frequent is (ie: %) in SLS of current formulas and that for example line_statement_prefix: '%'
dont affect lines if it's not the first char on the line, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this would be nice to have enabled just for salt's sls files by default if possible. As far as my reading and testing has found there are extremely limited situations in yaml where %
is allowed at the beginning of a line. But if extremely limited is still too much we could use something like %%
instead, I've been unable to find any conflicts at all with %%
.
conf/master
Outdated
# Default jinja environment options for everything but | ||
# salt sls files | ||
#jinja_env: | ||
# line_statement_prefix: '#' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the comments I added to conf/suse/master
doc/ref/configuration/master.rst
Outdated
|
||
.. code-block:: yaml | ||
|
||
jinja_line_statement_prefix: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see here example from my PR.
(it took me some time to find what really works - not not everything works)
@terminalmage @cachedout @CorvinM
|
thanks for clarification. minor update: for comments i have mean ## is the best. as its usually already formated in editors as comment than %% which would need an syntax style update.On 30 Aug 2017 00:57, Corvin Mcpherson <notifications@github.com> wrote:@CorvinM commented on this pull request.
In doc/ref/configuration/master.rst:
@@ -1925,6 +1925,42 @@ the cloud profile or master config file, no templating will be performed.
userdata_template: jinja
+.. conf_master:: jinja_line_statement_prefix
+
+``jinja_line_statement_prefix``
+---------------------
+
+.. versionadded:: Oxygen
+
+Default: ``''``
+
+If this is set to a string that is not empty, any line starting with this prefix
+will be interpreted as a line statement by the jinja renderer.
+Defaults to ``''`` and corresponds
Most of the documentation (including this file) is outdated with the code and I will likely have to rewrite most of it. The # and ## suggestions were just pulled from the example in the jinja documentation but I agree that % and %% would be much better for sls files. The only conflict I see is that % is used for yaml directives but I don't think they are used often (if at all) in salt's sls files. Will change the suggestions to use % and %%.
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.
|
I've assigned this over to @terminalmage to have a look. He'll have a follow-up reply here shortly. Apologies for the delay. |
doc/ref/configuration/master.rst
Outdated
.. conf_master:: jinja_line_comment_prefix | ||
|
||
``jinja_line_comment_prefix`` | ||
--------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the dashed line.
doc/ref/configuration/master.rst
Outdated
.. conf_master:: jinja_line_statement_prefix | ||
|
||
``jinja_line_statement_prefix`` | ||
--------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extend the dashed line to match the length of the line above. Using different lengths won't make docs builds fail, but it will muddy the output with a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor changes.
@CorvinM Did you see the request for changes here from @terminalmage ? |
@cachedout Yes, I did. Again, apologies to all for how long it has taken to get the documentation out. @terminalmage thanks for the review, the issues should be fixed in the new docs. @epcim I combined the two examples demonstrating the line statements and comments in your documentation into one and used it in the jinja_sls_env documentation. |
So folks where we are today? Can we merge @cachedout @terminalmage |
@cachedout Test's were already passing, is the signing of the commit a must or you can merge anyway? |
@CorvinM GPG commit signing is not currently required, but it is encouraged for future contributions. I've requested a re-review from @terminalmage. We can get this in, pending his review. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. This looks good!
What does this PR do?
The jinja_line_statement_prefix and jinja_line_comment_prefix options
allow salt users to use an alternative syntax for their states and other
jinja templates.
See http://jinja.pocoo.org/docs/templates/#line-statements
What issues does this PR fix or reference?
Fixes #36942
Tests written?
No