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

Jinja line statements and comments #42930

Merged
merged 17 commits into from
Nov 13, 2017
Merged

Conversation

CorvinM
Copy link
Contributor

@CorvinM CorvinM commented Aug 15, 2017

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

@ghost
Copy link

ghost commented Aug 15, 2017

@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.

@@ -1578,6 +1586,8 @@ def _gather_buffer_space():
'winrepo_passphrase': '',
'winrepo_refspecs': _DFLT_REFSPECS,
'syndic_wait': 5,
'jinja_line_statement_prefix': None,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@cachedout
Copy link
Contributor

I would like @whiteinge and @terminalmage to both take a look here for any additional feedback but I'm good with this at present.

@lorengordon
Copy link
Contributor

May want to compare to #41538

Copy link
Contributor

@whiteinge whiteinge left a 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.

@epcim
Copy link
Contributor

epcim commented Aug 16, 2017

@lorengordon commented on Aug 15, 2017, 9:47 PM GMT+2:

May want to compare to #41538

#41538 - the ambition is the same as this PR +

  • test coverage
  • possibility to enable that feature only to .sls files (but not, in general, any jinja, ... templates)
  • possibility to configure even the other jinja options found in salt config.
  • and hopefully we already fine tuned all the wording in doc strings

@CorvinM
Copy link
Contributor Author

CorvinM commented Aug 17, 2017

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:

  • Supports all the current options for the jinja environment plus any added in the future (without any code changes to salt)
  • Avoids fighting the yaml parser for default options (because the default is being not present in the dict)
  • Easily expandable to support jinja_env on a per template basis from something like file.managed
  • Fixes several bugs found in Extend Jinja options support (line statements) #41538

If there is any question about why I chose to do something one way over the other please ask.

@whiteinge @epcim @cachedout @terminalmage thoughts?

@epcim
Copy link
Contributor

epcim commented Aug 17, 2017

@CorvinM commented on Aug 17, 2017, 3:19 AM GMT+2:

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:

  • Supports all the current options for the jinja environment plus any added in the future (without any code changes to salt)
  • Avoids fighting the yaml parser for default options (because the default is being not present in the dict)
  • Easily expandable to support jinja_env on a per template basis from something like file.managed
  • Fixes several bugs found in #41538

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
Copy link
Contributor Author

CorvinM commented Aug 17, 2017

All the test failures appear to be unrelated (most of which are network errors)

@CorvinM
Copy link
Contributor Author

CorvinM commented Aug 17, 2017

Go Go Jenkins!

Copy link
Contributor

@terminalmage terminalmage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, and I feel like the configuration is simpler than @epcim's PR. That said, I tend to agree that you should open a PR against @epcim's fork, since both of you have done a bunch of work on this, and you've reworked your PR to incorporate some of the code from @epcim's PR.

@cachedout
Copy link
Contributor

@CorvinM We'd love to find a way forward on this. Did you see the above proposal from @terminalmage ?

@CorvinM
Copy link
Contributor Author

CorvinM commented Aug 29, 2017

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.
As for the part about submitting a PR against #41538 I feel is out of place and is unfair to me for the amount of effort and time spent in this PR, especially since the only code that is @epcim's in this PR is the test case and is clearly marked as his.

Copy link
Contributor

@epcim epcim left a 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.


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
Copy link
Contributor

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.

Copy link
Contributor Author

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: '#'
Copy link
Contributor

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: '#'
Copy link
Contributor

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...

Copy link
Contributor Author

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: '#'
Copy link
Contributor

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


.. code-block:: yaml

jinja_line_statement_prefix: ''
Copy link
Contributor

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)

@epcim
Copy link
Contributor

epcim commented Aug 29, 2017

@terminalmage @cachedout @CorvinM

  • I added some comments.
  • Once I read the latest version, sure I like this PR (current) more than mine - mine was mostly (minimal change / make it possible / I blindly followed current master/conf syntax approach (kind of key: value rather then key/dict).
  • This PR is the sophisticated approach. I want to say I don't care whether it will be merged instead of mine PR, (yes would be better if you send patch to my PR; but at the end of the day - who cares). Important is make it merged.
  • We should instead speak about:
    • make some options enable by default and what way highlight them for the community then speak.
    • do we want document default line_statement_preffix to be '' or # or %? ( I like the last one, # is not a good idea as it will trigger at any comment)
    • line_statement_preffix for SLS files I suggest to be enabled by default (assuming, it don't break most of the existing formulas - can be easily tested)
  • Some documentation + examples should go to release notes - so people will know how to finally use it.

@epcim
Copy link
Contributor

epcim commented Aug 30, 2017 via email

@cachedout
Copy link
Contributor

I've assigned this over to @terminalmage to have a look. He'll have a follow-up reply here shortly. Apologies for the delay.

.. conf_master:: jinja_line_comment_prefix

``jinja_line_comment_prefix``
---------------------
Copy link
Contributor

@terminalmage terminalmage Sep 26, 2017

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.

.. conf_master:: jinja_line_statement_prefix

``jinja_line_statement_prefix``
---------------------
Copy link
Contributor

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.

Copy link
Contributor

@terminalmage terminalmage left a 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.

@cachedout
Copy link
Contributor

@CorvinM Did you see the request for changes here from @terminalmage ?

@CorvinM
Copy link
Contributor Author

CorvinM commented Oct 1, 2017

@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.

@epcim
Copy link
Contributor

epcim commented Nov 2, 2017

So folks where we are today? Can we merge @cachedout @terminalmage

@epcim
Copy link
Contributor

epcim commented Nov 10, 2017

@cachedout
Quite sure you were busy with SaltConf17 recently, but can we move this to successful merge. I quite believe all requests were satisfied.

Test's were already passing, is the signing of the commit a must or you can merge anyway?

@rallytime
Copy link
Contributor

@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!

Copy link
Contributor

@terminalmage terminalmage left a 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!

@terminalmage terminalmage merged commit df972db into saltstack:develop Nov 13, 2017
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

Successfully merging this pull request may close these issues.

Add Support for Jinja2 Line Statements in SLS files
8 participants