[Checkins] SVN: zc.buildout/branches/2/ Merge r127336 and r127337 from trunk; fix += and -= handling.
Martijn Pieters
cvs-admin at zope.org
Thu Jul 12 09:28:46 UTC 2012
Log message for revision 127338:
Merge r127336 and r127337 from trunk; fix += and -= handling.
Changed:
U zc.buildout/branches/2/CHANGES.txt
U zc.buildout/branches/2/src/zc/buildout/buildout.py
U zc.buildout/branches/2/src/zc/buildout/buildout.txt
-=-
Modified: zc.buildout/branches/2/CHANGES.txt
===================================================================
--- zc.buildout/branches/2/CHANGES.txt 2012-07-12 08:59:04 UTC (rev 127337)
+++ zc.buildout/branches/2/CHANGES.txt 2012-07-12 09:28:43 UTC (rev 127338)
@@ -32,6 +32,9 @@
-Work around distribute's way of dealing with setuptools.
+- Handle both addition and subtraction of elements (+= and -=) on the same key
+ in the same section.
+
1.5.2 (2010-10-11)
==================
Modified: zc.buildout/branches/2/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/2/src/zc/buildout/buildout.py 2012-07-12 08:59:04 UTC (rev 127337)
+++ zc.buildout/branches/2/src/zc/buildout/buildout.py 2012-07-12 09:28:43 UTC (rev 127338)
@@ -1492,19 +1492,26 @@
return result
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
- for k, v in list(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
if k.endswith('+'):
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()
s2[key] = "\n".join((v1).split('\n') +
v2.split('\n')), newnote
del s2[k]
elif k.endswith('-'):
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()
s2[key] = ("\n".join(
[v for v in v1.split('\n')
Modified: zc.buildout/branches/2/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/branches/2/src/zc/buildout/buildout.txt 2012-07-12 08:59:04 UTC (rev 127337)
+++ zc.buildout/branches/2/src/zc/buildout/buildout.txt 2012-07-12 09:28:43 UTC (rev 127338)
@@ -1084,12 +1084,21 @@
...
... [part2]
... recipe =
- ... option = b1 b2 b3 b4
+ ... option = b1
+ ... b2
+ ... b3
+ ... b4
...
... [part3]
... recipe =
... option = c1 c2
...
+ ... [part4]
+ ... recipe =
+ ... option = d2
+ ... d3
+ ... d5
+ ...
... """)
Extending this configuration, we can "adjust" the values set in the
@@ -1106,16 +1115,22 @@
...
... # removing values
... [part2]
- ... option -= b1 b2
+ ... option -= b1
+ ... b2
...
... # alt. spelling
... [part3]
... option+=c3 c4 c5
...
+ ... # combining both adding and removing
+ ... [part4]
+ ... option += d1
+ ... d4
+ ... option -= d5
+ ...
... # normal assignment
- ... [part4]
+ ... [part5]
... option = h1 h2
- ...
... """)
An additional extension.
@@ -1131,7 +1146,9 @@
...
... # removing values
... [part2]
- ... option -= b1 b2 b3
+ ... option -= b1
+ ... b2
+ ... b3
...
... """)
@@ -1185,7 +1202,7 @@
... """)
>>> run(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', 'b4', 'c1 c2/nc3 c4 c5', 'd2/nd3/nd1/nd4', 'h1 h2']
Develop: '/sample-buildout/demo'
Annotated sections output shows which files are responsible for which
@@ -1209,7 +1226,7 @@
/sample-buildout/base.cfg
<BLANKLINE>
[part2]
- option= b1 b2 b3 b4
+ option= b4
/sample-buildout/base.cfg
-= /sample-buildout/extension1.cfg
-= /sample-buildout/extension2.cfg
@@ -1225,6 +1242,17 @@
/sample-buildout/base.cfg
<BLANKLINE>
[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
/sample-buildout/extension1.cfg
More information about the checkins
mailing list