Commit e65a7906 authored by Tres Seaver's avatar Tres Seaver

Merge w/ current master.

parents 87788f7b 33a44075
...@@ -4,6 +4,9 @@ Change History ...@@ -4,6 +4,9 @@ Change History
2.2.0dev (unreleased) 2.2.0dev (unreleased)
===================== =====================
- Handle both addition and subtraction of elements (+= and -=) on the same key
in the same section. Forward-ported from buildout 1.6.
- Suppress the useless ``Link to <URL> ***BLOCKED*** by --allow-hosts`` - Suppress the useless ``Link to <URL> ***BLOCKED*** by --allow-hosts``
error message being emitted by distribute / setuptools. error message being emitted by distribute / setuptools.
......
...@@ -1636,19 +1636,26 @@ def _dists_sig(dists): ...@@ -1636,19 +1636,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 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 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')
......
...@@ -1286,6 +1286,12 @@ This is illustrated below; first we define a base configuration. ...@@ -1286,6 +1286,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
...@@ -1308,8 +1314,14 @@ base configuration file. ...@@ -1308,8 +1314,14 @@ base configuration file.
... [part3] ... [part3]
... option+=c3 c4 c5 ... option+=c3 c4 c5
... ...
... # normal assignment ... # combining both adding and removing
... [part4] ... [part4]
... option += d1
... d4
... option -= d5
...
... # normal assignment
... [part5]
... option = h1 h2 ... option = h1 h2
... ...
... """) ... """)
...@@ -1379,7 +1391,7 @@ Verify option values. ...@@ -1379,7 +1391,7 @@ Verify option values.
... """) ... """)
>>> print_(system(os.path.join('bin', 'buildout')), end='') >>> print_(system(os.path.join('bin', 'buildout')), end='')
['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
...@@ -1419,6 +1431,17 @@ operations. ...@@ -1419,6 +1431,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
[versions] [versions]
......
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