diff --git a/CHANGES.txt b/CHANGES.txt index 81e865cc4e7a2c80bfdcafe03f95f5f3e317b0b9..e16e3ab1180b37d5c1b4ba6790deb0a7afc85637 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,13 @@ Change History 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. diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py index 7396bc73b363c6522d1e65d8971b63379617d963..134d1864e322522f9a6b79c46e03f6b9716438c0 100644 --- a/src/zc/buildout/buildout.py +++ b/src/zc/buildout/buildout.py @@ -1086,7 +1086,7 @@ class Options(UserDict.DictMixin): _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 @@ class Options(UserDict.DictMixin): "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('') diff --git a/src/zc/buildout/buildout.txt b/src/zc/buildout/buildout.txt index 8cc9060341df50f4ddaea6517ad39ced662d734d..04405c59e653226e120d84321b0e71c2ee3218f4 100644 --- a/src/zc/buildout/buildout.txt +++ b/src/zc/buildout/buildout.txt @@ -866,6 +866,37 @@ Section and option names in variable substitutions are only allowed to 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 @@ It will still be treated as a part: >>> 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