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

Support for conditional sections using expressions in sections names as in [section:expression] #51

Closed
wants to merge 13 commits into from

Conversation

Projects
None yet
2 participants
@pombredanne
Copy link
Contributor

commented Jan 28, 2013

@jimfulton : Here is a working version, with tests and with all tests passing:

https://travis-ci.org/pombredanne/buildout/builds/4435026

You can cherry pick in particular do not take my travis config

Cordially
Philippe

r'\s*]' # optional spaces then closing bracket '['
r'\s*([#;].*)?$' # optional comments at end of line, marked by '#' or ';', ignored
).match

This comment has been minimized.

Copy link
@jimfulton

jimfulton Feb 1, 2013

Member

This is incorrect. You either need to disallow ']'s in expressions, or have more complicated parsing logic that matches opened and closed square braces.

>>> section_header('[ a ]  # ]').group('expression')
']  # '
>>> section_header('[ a : True]  # ]').group('expression')
'True]  # '
>>> section_header('[ a : True]  # []').group('expression')
'True]  # ['
>>> section_header('[ a ]  # []').group('expression')
']  # ['
>>> section_header('[ a ]').group('expression')
''

This comment has been minimized.

Copy link
@pombredanne

pombredanne Feb 1, 2013

Author Contributor

@jimfulton let me add new tests first as listed in your comment and a few more corner case and amend the parsing accordingly afterwards

@@ -88,8 +98,18 @@ def parse(fp, fpname):
Continuations are represented by an embedded newline then
leading whitespace. Blank lines, lines beginning with a '#',
and just about everything else are ignored.
The title line is in the form [title:expression] where expression is an
arbitrary Python expression. Sections with an expression that evaluates to

This comment has been minimized.

Copy link
@jimfulton

jimfulton Feb 1, 2013

Member

No, the title line is of the form [name] or [name:expression].

This comment has been minimized.

Copy link
@pombredanne

pombredanne Feb 1, 2013

Author Contributor

@jimfulton let me fix this one

@jimfulton

This comment has been minimized.

Copy link
Member

commented Feb 1, 2013

Note that this will be in 2.1, so don't rush to try to fix things for 2.0.

I expect 2.1 to follow close on the heels of 2.0.

@pombredanne

This comment has been minimized.

Copy link
Contributor Author

commented Feb 1, 2013

@jimfulton I am using it now, so I want it neat and tidy and working well

pombredanne added some commits Feb 15, 2013

Support [] brackets in title line trailing comment.
Section with conditional expression can only use # Python style trailing
comment.
@pombredanne

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2013

@jimfulton the latest commit deals with various corner cases of [] in comments with a twist. When using a conditional expression, only # Python style comments are supported. Section titles without expression can use both semicolon and # expression separators

@pombredanne

This comment has been minimized.

Copy link
Contributor Author

commented Feb 15, 2013

Let me close this and open a new one with a clean commit lineage, merged from the latest master HEAD: See #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.