Commit d32669a0 authored by Jim Fulton's avatar Jim Fulton

Formatting and minor refactoring of defau;t globals arg.

parent c39cdf2a
...@@ -111,7 +111,7 @@ option_start = re.compile( ...@@ -111,7 +111,7 @@ option_start = re.compile(
leading_blank_lines = re.compile(r"^(\s*\n)+") leading_blank_lines = re.compile(r"^(\s*\n)+")
def parse(fp, fpname, exp_globals=None): def parse(fp, fpname, exp_globals=dict):
"""Parse a sectioned setup file. """Parse a sectioned setup file.
The sections in setup files contain a title line at the top, The sections in setup files contain a title line at the top,
...@@ -176,18 +176,22 @@ def parse(fp, fpname, exp_globals=None): ...@@ -176,18 +176,22 @@ def parse(fp, fpname, exp_globals=None):
if expression: if expression:
# normalize tail comments to Python style # normalize tail comments to Python style
tail = tail.replace(';', '#') if tail else '' tail = tail.replace(';', '#') if tail else ''
# un-escape literal # and ; . Do not use a string-escape decode # un-escape literal # and ; . Do not use a
# string-escape decode
expr = expression.replace(r'\x23','#').replace(r'x3b', ';') expr = expression.replace(r'\x23','#').replace(r'x3b', ';')
# rebuild a valid Python expression wrapped in a list # rebuild a valid Python expression wrapped in a list
expr = head + expr + tail expr = head + expr + tail
# lazily populate context only expression # lazily populate context only expression
if not context: if not context:
context = exp_globals() if exp_globals else {} context = exp_globals()
# evaluated expression is in list: get first element # evaluated expression is in list: get first element
section_condition = eval(expr, context)[0] section_condition = eval(expr, context)[0]
# finally, ignore section when an expression evaluates to false # finally, ignore section when an expression
# evaluates to false
if not section_condition: if not section_condition:
logger.debug('Ignoring section %(sectname)r with [expression]: %(expression)r' % locals()) logger.debug(
'Ignoring section %(sectname)r with [expression]:'
' %(expression)r' % locals())
continue continue
if sectname in sections: if sectname in sections:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment