Commit 4c556756 authored by mj's avatar mj

Handle addition and subtraction in the same section correctly

git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@127336 62d5b8a3-27da-0310-9561-8e5933582275
parent 1a2d9c89
...@@ -36,6 +36,9 @@ Bugs fixed: ...@@ -36,6 +36,9 @@ Bugs fixed:
- https://bugs.launchpad.net/bugs/697913 : Buildout doesn't honor exit code - https://bugs.launchpad.net/bugs/697913 : Buildout doesn't honor exit code
from scripts. Fixed. from scripts. Fixed.
- Handle both addition and subtraction of elements (+= and -=) on the same key
in the same section.
1.5.2 (2010-10-11) 1.5.2 (2010-10-11)
================== ==================
......
...@@ -1527,19 +1527,26 @@ def _dists_sig(dists): ...@@ -1527,19 +1527,26 @@ def _dists_sig(dists):
return result return result
def _update_section(s1, s2): def _update_section(s1, s2):
# Base section 2 on section 1; section 1 is copied, with key-value pairs
# in section 2 overriding those in section 1. If there are += or -=
# operators in section 2, process these to add or substract items (delimited
# by newlines) from the preexisting values.
s2 = s2.copy() # avoid mutating the second argument, which is unexpected s2 = s2.copy() # avoid mutating the second argument, which is unexpected
for k, v in s2.items(): # Sort on key, then on the addition or substraction operator (+ comes first)
for k, v in sorted(s2.items(), key=lambda x: (x[0].rstrip(' +'), x[0][-1])):
v2, note2 = v v2, note2 = v
if k.endswith('+'): if k.endswith('+'):
key = k.rstrip(' +') key = k.rstrip(' +')
v1, note1 = s1.get(key, ("", "")) # Find v1 in s2 first; it may have been defined locally too.
v1, note1 = s2.get(key, s1.get(key, ("", "")))
newnote = ' [+] '.join((note1, note2)).strip() newnote = ' [+] '.join((note1, note2)).strip()
s2[key] = "\n".join((v1).split('\n') + s2[key] = "\n".join((v1).split('\n') +
v2.split('\n')), newnote v2.split('\n')), newnote
del s2[k] del s2[k]
elif k.endswith('-'): elif k.endswith('-'):
key = k.rstrip(' -') key = k.rstrip(' -')
v1, note1 = s1.get(key, ("", "")) # Find v1 in s2 first; it may have been set by a += operation first
v1, note1 = s2.get(key, s1.get(key, ("", "")))
newnote = ' [-] '.join((note1, note2)).strip() newnote = ' [-] '.join((note1, note2)).strip()
s2[key] = ("\n".join( s2[key] = ("\n".join(
[v for v in v1.split('\n') [v for v in v1.split('\n')
......
...@@ -1091,6 +1091,12 @@ This is illustrated below; first we define a base configuration. ...@@ -1091,6 +1091,12 @@ This is illustrated below; first we define a base configuration.
... recipe = ... recipe =
... option = c1 c2 ... option = c1 c2
... ...
... [part4]
... recipe =
... option = d2
... d3
... d5
...
... """) ... """)
Extending this configuration, we can "adjust" the values set in the Extending this configuration, we can "adjust" the values set in the
...@@ -1113,10 +1119,15 @@ base configuration file. ...@@ -1113,10 +1119,15 @@ base configuration file.
... [part3] ... [part3]
... option+=c3 c4 c5 ... option+=c3 c4 c5
... ...
... # normal assignment ... # combining both adding and removing
... [part4] ... [part4]
... option = h1 h2 ... option += d1
... d4
... option -= d5
... ...
... # normal assignment
... [part5]
... option = h1 h2
... """) ... """)
An additional extension. An additional extension.
...@@ -1186,7 +1197,7 @@ Verify option values. ...@@ -1186,7 +1197,7 @@ Verify option values.
... """) ... """)
>>> print system(os.path.join('bin', 'buildout')), >>> print system(os.path.join('bin', 'buildout')),
['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'h1 h2'] ['a1 a2/na3 a4/na5', 'b1 b2 b3 b4', 'c1 c2/nc3 c4 c5', 'd2/nd3/nd1/nd4', 'h1 h2']
Develop: '/sample-buildout/demo' Develop: '/sample-buildout/demo'
Annotated sections output shows which files are responsible for which Annotated sections output shows which files are responsible for which
...@@ -1226,6 +1237,17 @@ operations. ...@@ -1226,6 +1237,17 @@ operations.
/sample-buildout/base.cfg /sample-buildout/base.cfg
<BLANKLINE> <BLANKLINE>
[part4] [part4]
option= d2
d3
d1
d4
/sample-buildout/base.cfg
+= /sample-buildout/extension1.cfg
-= /sample-buildout/extension1.cfg
recipe=
/sample-buildout/base.cfg
<BLANKLINE>
[part5]
option= h1 h2 option= h1 h2
/sample-buildout/extension1.cfg /sample-buildout/extension1.cfg
......
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