跳转到主要内容

导出buildout选择的版本。

项目描述

buildout.dumppickedversions

问题:什么是buildout扩展?

答案:http://pypi.python.org/pypi/zc.buildout#extensions

问题

在使用基于zc.buildout的部署系统时,您希望能够在一个月后使用相同的一组egg版本重现相同的设置。如果没有固定所有egg,则任务不可能完成。

解决方案

buildout.dumppickedversions 是一个Buildout扩展,它正是为此而设计的。它可以打印或生成一个包含所有未固定egg的versions.cfg文件。

它还在每个由zc.buildout选中的egg之前添加了一个注释,作为其他包含所需egg列表的egg的需求。

buildout.dumppickedversions 需要 zc.buildout 1.5 或更高版本。

buildout.dumppickedversions 选项

dump-picked-versions-file

您希望 buildout.dumppickedversions 写入的文件名。如果没有提供,buildout.dumppickedversions 将将版本输出到屏幕。

overwrite-picked-versions-file

如果设置为 true,则当 buildout.dumppickedversions 存在时,它将覆盖 dump-picked-versions-file 中定义的文件。默认为 True。

详细文档

让我们创建一个egg,以便在测试中使用它。

>>> mkdir('myegg')
>>> write('myegg', 'setup.py',
... '''
... from setuptools import setup
... setup(name='myegg', version='1.0',)
... ''')
>>> write('myegg', 'README', '')
>>> print system(buildout+' setup myegg bdist_egg'), # doctest: +ELLIPSIS
Running setup script 'myegg/setup.py'.
...

现在让我们创建一个 buildout 来安装 egg 并使用 buildout.dumppickedversions。

>>> write('buildout.cfg',
... '''
... [buildout]
... extensions = buildout.dumppickedversions
... parts = foo
... find-links = %s
... index = http://pypi.python.org/simple
... [foo]
... recipe = zc.recipe.egg
... eggs = myegg
... ''' % join('myegg', 'dist'))

运行 buildout 将打印有关选中版本的信息。

>>> print system(buildout), # doctest: +ELLIPSIS
Getting distribution for 'buildout.dumppickedversions'.
...
*************** PICKED VERSIONS ****************
[versions]
myegg = N.N
setuptools = N.N
zc.buildout = N.N
zc.recipe.egg = N.N
<BLANKLINE>
*************** /PICKED VERSIONS ***************

要将选中版本输出到文件,我们只需添加一个 dump-picked-versions-file 选项并给出一个文件名。

>>> write('buildout.cfg',
... '''
... [buildout]
... extensions = buildout.dumppickedversions
... dump-picked-versions-file = versions.cfg
... parts = foo
... find-links =
...     %s
... index = http://pypi.python.org/simple
... [foo]
... recipe = zc.recipe.egg
... eggs =
...     myegg
... ''' % join('myegg', 'dist'))

>>> print system(buildout), # doctest: +ELLIPSIS
Uninstalling foo.
Installing foo.
*********************************************
Writing picked versions to versions.cfg
*********************************************

以下是版本.cfg 文件的内容

>>> cat('versions.cfg')
[versions]
myegg = N.N
setuptools = N.N
zc.buildout = N.N
zc.recipe.egg = N.N
<BLANKLINE>

下次我们运行 buildout 时,该文件将被覆盖。

>>> print system(buildout), # doctest: +ELLIPSIS
Updating foo.
*********************************************
Overwriting versions.cfg
*********************************************

当不想覆盖文件时,我们只需添加一个 overwrite-picked-versions-file 并将其设置为 false。

>>> write('buildout.cfg',
... '''
... [buildout]
... extensions = buildout.dumppickedversions
... dump-picked-versions-file = versions.cfg
... overwrite-picked-versions-file = false
... parts = foo
... find-links =
...     %s
... index = http://pypi.python.org/simple
... [foo]
... recipe = zc.recipe.egg
... eggs =
...     myegg
... ''' % join('myegg', 'dist'))

>>> print system(buildout), # doctest: +ELLIPSIS
Updating foo.
*********************************************
Skipped: File versions.cfg already exists.
*********************************************

如果 eggA 被安装为其他egg的需求,您将在 eggA 前得到一条注释行,其中包含所需egg的列表。

让我们举一个例子。我们将安装 zope.component。

>>> write('buildout.cfg',
... '''
... [buildout]
... extensions = buildout.dumppickedversions
... dump-picked-versions-file = versions.cfg
... parts = foo
... index = http://pypi.python.org/simple
... [foo]
... recipe = zc.recipe.egg
... eggs = zope.component
... ''')

>>> print system(buildout), # doctest: +ELLIPSIS
Uninstalling foo.
Installing foo.
Getting distribution for 'zope.component'.
...
*********************************************
Overwriting versions.cfg
*********************************************

然后让我们查看版本.cfg 文件的内容。

>>> cat('versions.cfg')
[versions]
zc.buildout = N.N
zc.recipe.egg = N.N
zope.component = N.N
zope.interface = N.N
<BLANKLINE>
#Required by:
#zope.event N.N
#zope.interface N.N
#zope.component N.N
setuptools = N.N
<BLANKLINE>
#Required by:
#zope.component N.N
zope.event = N.N

变更历史

0.5 (2012-01-23)

0.4 (2009-05-03)

  • 删除了重复的注释行 [mustapha]

0.3 (2009-05-03)

  • 在生成的版本文件中添加了注释,说明了如果有的话,哪个 egg 需要选中的 egg。[mustapha]

0.2 (2009-03-15)

  • 从转储文件中删除了 buildout 标头 [mustapha]

  • 添加了 overwrite-picked-versions-file 选项 [mustapha]

0.1 (2009-02-07)

  • 使用 ZopeSkel 创建了配方 [mustapha]

贡献者

  • Mustapha Benali,作者

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面