Commit 5ccfe973 authored by Julien Muchembled's avatar Julien Muchembled Committed by Xavier Thompson

[feat] Ignore NameError in unused conditional configuration sections

Adding new names for expression is currently not possible because
buildout aborts before it tries to upgrade (in-place or bootstrap).
parent efff5582
...@@ -1542,7 +1542,9 @@ class Buildout(DictMixin): ...@@ -1542,7 +1542,9 @@ class Buildout(DictMixin):
data = self._raw[section] data = self._raw[section]
except KeyError: except KeyError:
raise MissingSection(section) raise MissingSection(section)
e = data.get('__unsupported_conditional_expression__')
if e:
raise e
options = self.Options(self, section, data) options = self.Options(self, section, data)
self._data[section] = options self._data[section] = options
options._initialize() options._initialize()
......
...@@ -203,7 +203,12 @@ def parse(fp, fpname, exp_globals=dict): ...@@ -203,7 +203,12 @@ def parse(fp, fpname, exp_globals=dict):
if not context: if not context:
context = exp_globals() context = exp_globals()
# evaluated expression is in list: get first element # evaluated expression is in list: get first element
try:
section_condition = eval(expr, context)[0] section_condition = eval(expr, context)[0]
except NameError as x:
sections.setdefault(sectname, {})[
'__unsupported_conditional_expression__'] = x
continue
# finally, ignore section when an expression # finally, ignore section when an expression
# evaluates to false # evaluates to false
if not section_condition: if not section_condition:
...@@ -257,6 +262,8 @@ def parse(fp, fpname, exp_globals=dict): ...@@ -257,6 +262,8 @@ def parse(fp, fpname, exp_globals=dict):
section = sections[sectname] section = sections[sectname]
for name in section: for name in section:
value = section[name] value = section[name]
if isinstance(value, NameError):
continue
if value[:1].isspace(): if value[:1].isspace():
section[name] = leading_blank_lines.sub( section[name] = leading_blank_lines.sub(
'', textwrap.dedent(value.rstrip())) '', textwrap.dedent(value.rstrip()))
......
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