我们可以在 Buildout 的配置文件的选项部分有一个变量吗?

Can we have a variable in the option part of Buildout's config file?

Python 的 Buildout configuration file allows us to avoid repetition of values by allowing a special syntax known as variable substitution 的形式为 ${SECTION:OPTION}

这个例子可以让我们避免重复单词 experiment:

[context]
name = experiment

[db]
server = ${context:name}

是否可以对 选项 本身使用替换?

例如:

[soures]
${context:name} = https://git.com/${context:name}.git

不,不支持键中的变量扩展;该功能实际上被命名为 value substitions,以明确语法仅适用于值:

When supplying values in a configuration, you can include values from other options using the syntax:

${SECTION:OPTION}

options syntax 还明确排除了进行替换所需的字符:

Options are specified with an option name followed by an equal sign and a value:

parts = py 

Option names may have any characters other than whitespace, square braces, curly braces, equal signs, or colons

short-hand <part-dependencies> syntax 例外。

所以,最后,当 variable substitutions are applied in buildout 时,代码仅在值中查找语法的 ${ 部分:

# force substitutions
for k, v in sorted(self._raw.items()):
    if '${' in v:
        self._dosub(k, v)