[Checkins] SVN: zc.buildout/trunk/ When doing variable substitutions, you can omit the section name to

Jim Fulton jim at zope.com
Wed Aug 26 10:22:06 EDT 2009


Log message for revision 103234:
  When doing variable substitutions, you can omit the section name to
  refer to a variable in the same section (e.g. ${:foo}).
  
  When doing variable substitution, you can use the special option,
  ``_buildout_section_name_`` to get the section name.  This is most handy
  for getting the current section name (e.g. ${:_buildout_section_name_}.
  

Changed:
  U   zc.buildout/trunk/CHANGES.txt
  U   zc.buildout/trunk/src/zc/buildout/buildout.py
  U   zc.buildout/trunk/src/zc/buildout/buildout.txt

-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt	2009-08-26 14:09:27 UTC (rev 103233)
+++ zc.buildout/trunk/CHANGES.txt	2009-08-26 14:22:05 UTC (rev 103234)
@@ -4,6 +4,13 @@
 1.4.0 (2009-08-26)
 ==================
 
+- When doing variable substitutions, you can omit the section name to
+  refer to a variable in the same section (e.g. ${:foo}).
+
+- When doing variable substitution, you can use the special option,
+  ``_buildout_section_name_`` to get the section name.  This is most handy
+  for getting the current section name (e.g. ${:_buildout_section_name_}.
+
 - Added annotate command for annotated sections. Displays sections
   key-value pairs along with the value origin.
 

Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2009-08-26 14:09:27 UTC (rev 103233)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2009-08-26 14:22:05 UTC (rev 103234)
@@ -1086,7 +1086,7 @@
 
     _template_split = re.compile('([$]{[^}]*})').split
     _simple = re.compile('[-a-zA-Z0-9 ._]+$').match
-    _valid = re.compile('\${[-a-zA-Z0-9 ._]+:[-a-zA-Z0-9 ._]+}$').match
+    _valid = re.compile('\${[-a-zA-Z0-9 ._]*:[-a-zA-Z0-9 ._]+}$').match
     def _sub(self, template, seen):
         value = self._template_split(template)
         subs = []
@@ -1112,9 +1112,16 @@
                         "has invalid characters."
                         % ref)
 
-            v = self.buildout[s[0]].get(s[1], None, seen)
+            section, option = s
+            if not section:
+                section = self.name
+            v = self.buildout[section].get(option, None, seen)
             if v is None:
-                raise MissingOption("Referenced option does not exist:", *s)
+                if option == '_buildout_section_name_':
+                    v = self.name
+                else:
+                    raise MissingOption("Referenced option does not exist:",
+                                        section, option)
             subs.append(v)
         subs.append('')
 

Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt	2009-08-26 14:09:27 UTC (rev 103233)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt	2009-08-26 14:22:05 UTC (rev 103234)
@@ -866,7 +866,38 @@
 contain alphanumeric characters, hyphens, periods and spaces. This
 restriction might be relaxed in future releases.
 
+We can ommit the section name in a variable substitution to refer to
+the current section.  We can also use the special option,
+_buildout_section_name_ to get the current section name.
 
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... """
+    ... [buildout]
+    ... develop = recipes
+    ... parts = data-dir debug
+    ... log-level = INFO
+    ...
+    ... [debug]
+    ... recipe = recipes:debug
+    ... File 1 = ${data-dir:path}/file
+    ... File 2 = ${:File 1}/log
+    ... my_name = ${:_buildout_section_name_}
+    ...
+    ... [data-dir]
+    ... recipe = recipes:mkdir
+    ... path = mydata
+    ... """)
+
+    >>> print system(buildout),
+    Develop: '/sample-buildout/recipes'
+    Uninstalling debug.
+    Updating data-dir.
+    Installing debug.
+    File 1 /sample-buildout/mydata/file
+    File 2 /sample-buildout/mydata/file/log
+    my_name debug
+    recipe recipes:debug
+
 Automatic part selection and ordering
 -------------------------------------
 
@@ -897,8 +928,9 @@
 
     >>> print system(buildout),
     Develop: '/sample-buildout/recipes'
+    Uninstalling debug.
     Updating data-dir.
-    Updating debug.
+    Installing debug.
     File 1 /sample-buildout/mydata/file
     File 2 /sample-buildout/mydata/file/log
     recipe recipes:debug



More information about the Checkins mailing list