用于从构建创建源发布的实用脚本
项目描述
从构建创建源发布
zc.sourcerelease软件包提供了一个名为buildout-source-release的脚本,它可以从构建中生成源发布。源发布是以gzip压缩的tar存档的形式的[1]。生成的源发布可以用作RPM或configure-make-make-install发布等高级发布的基。
源发布包括通常安装在下载缓存中的数据,例如Python发行版,或由zc.recipe.cmmi食谱执行的下载。如果构建使用了一个下载数据但不将下载的数据存储在构建下载缓存中的食谱,则这些数据将不包括在源发布中,并且在安装源发布时将需要下载。
源发布包括一个Python安装脚本。它不是可执行的,必须使用想要的Python运行,并且必须与制作发布时使用的Python版本相同。安装脚本在原地运行构建。这意味着源发布需要提取到最终的安装位置,并且必须在该位置运行安装脚本[2]。虽然可以直接使用安装脚本,但它更常见地由系统打包(例如RPM)构建脚本或make文件使用。
安装
您可以使用easy install安装buildout-source-release脚本
easy_install zc.sourcerelease
或者您可以使用zc.buildout将其安装到构建中。
使用方法
要创建一个源发行版,只需运行buildout-source-release脚本,传入文件URL或子版本URL以及要使用的配置文件名称。[3] 文件URL对于测试很有用,可以与非子版本源代码控制系统一起使用。
让我们看一个例子。我们有一台服务器,上面有一些发行版。
>>> index_content = get(link_server) >>> if 'distribute' in index_content: ... lines = index_content.splitlines() ... distribute_line = lines.pop(1) ... lines.insert(4, distribute_line) ... index_content = '\n'.join(lines) >>> print index_content, <html><body> <a href="index/">index/</a><br> <a href="sample1-1.0.zip">sample1-1.0.zip</a><br> <a href="sample2-1.0.zip">sample2-1.0.zip</a><br> <a href="setuptools-0.6c7-py2.4.egg">setuptools-0.6-py2.4.egg</a><br> <a href="zc.buildout-1.0-py2.4.egg">zc.buildout-1.0-py2.4.egg</a><br> <a href="zc.buildout-99.99-pyN.N.egg">zc.buildout-99.99-pyN.N.egg</a><br> <a href="zc.recipe.egg-1.0-py2.4.egg">zc.recipe.egg-1.0-py2.4.egg</a><br> </body></html>
我们在本地bin目录中安装了buildout-source-release。我们将创建另一个buildout,用于我们的源发行版。
>>> mkdir('sample') >>> sample = join(sample_buildout, 'sample') >>> write(sample, 'buildout.cfg', ... ''' ... [buildout] ... parts = sample ... find-links = %(link_server)s ... ... [sample] ... recipe = zc.recipe.egg ... eggs = sample1 ... ''' % globals())
我们将对此示例目录运行发布脚本
>>> print system(join('bin', 'buildout-source-release') ... +' file://'+sample+' buildout.cfg'), ... # doctest: +ELLIPSIS Creating source release in sample.tgz ...
最终我们得到一个tar文件
>>> ls('.') - .installed.cfg d bin - buildout.cfg d develop-eggs d eggs d parts d sample - sample.tgz
如果我们想给文件一个自定义名称,在这个例子中是sample.tgz以外的名称,我们可以使用“-n”或“–name”选项来指定一个
>>> print system(join('bin', 'buildout-source-release') ... +' file://'+sample+' buildout.cfg -n custom_name_one'), ... # doctest: +ELLIPSIS Creating source release in custom_name_one.tgz ...>>> print system(join('bin', 'buildout-source-release') ... +' file://'+sample+' buildout.cfg --name custom_name_two'), ... # doctest: +ELLIPSIS Creating source release in custom_name_two.tgz ...>>> ls('.') - .installed.cfg d bin - buildout.cfg - custom_name_one.tgz - custom_name_two.tgz d develop-eggs d eggs d parts d sample - sample.tgz
让我们继续使用sample.tgz这个例子。将tar文件提取到临时目录中
>>> mkdir('test') >>> import tarfile >>> tf = tarfile.open('sample.tgz', 'r:gz') >>> for name in tf.getnames(): ... tf.extract(name, 'test') >>> tf.close()>>> ls('test') d sample>>> ls('test', 'sample') - buildout.cfg d eggs - install.py d release-distributions
提取的sample目录包含用于buildout和setuptools的egg文件
>>> ls('test', 'sample', 'eggs') - setuptools-0.6c7-py2.4.egg d zc.buildout-99.99-py2.4.egg
请注意,使用了zc.buildout的99.99版本,因为它是在链接服务器上最新的版本。这不同于源发布脚本中使用的buildout版本。
它有一个包含安装buildout所需的发行版的release-distributions目录
>>> ls('test', 'sample', 'release-distributions', 'dist') - sample1-1.0.zip - sample2-1.0.zip - zc.buildout-99.99-pyN.N.egg - zc.recipe.egg-1.0.0b6-py2.4.egg
(通常不会为buildout和setuptools等提供发行版,因为这些已经预安装在源发行版的egg目录中。在这种情况下,我们有一个来自链接服务器的zc.buildout发行版。我们下载的所有内容都包含在内。)
因此,现在我们已经提取了我们构建的源发行版,我们可以尝试安装它。为此,我们将运行安装程序。不过,在这样做之前,我们将移除链接服务器使用的数据
>>> import os >>> mkdir('sample_eggs_aside') >>> for p in os.listdir(sample_eggs): ... os.rename(join(sample_eggs, p), join('sample_eggs_aside', p)) >>> print get(link_server), <html><body> </body></html>
这样,我们知道当运行源发行版时,发行版将来自发行版,而不是来自链接服务器。现在,让我们运行安装程序
>>> import sys>>> print system(sys.executable+' '+join('test', 'sample', 'install.py')), ... # doctest: +ELLIPSIS Creating directory ...
运行安装程序只是构建保存的buildout,使用发行版-distribution作为可安装egg的源。在我们的情况下,我们得到了一个可以运行的示例脚本
>>> print system(join('test', 'sample', 'bin', 'sample1')), Hello. My name is sample1
请注意,sample bin目录不包含buildout脚本
>>> ls('test', 'sample', 'bin') - sample1
如果我们需要一个,我们可以再次运行安装脚本,并以“bootstrap”作为参数
>>> print system(sys.executable+ ... ' '+join('test', 'sample', 'install.py bootstrap')), Generated script '/sample-buildout/test/sample/bin/buildout'.>>> ls('test', 'sample', 'bin') - buildout - sample1
请注意,安装脚本是一个专业的buildout脚本,因此可以提供其他buildout选项,尽管通常不需要这样做。
通常,我们会使用文件URL进行测试,但将待发布的buildout存储在源代码仓库(如subversion)中。我们在subversion中创建了一个简单的示例。让我们尝试安装它
>>> print system(join('bin', 'buildout-source-release')+' '+ ... 'svn://svn.zope.org/repos/main/zc.sourcerelease/svnsample'+ ... ' release.cfg'), ... # doctest: +ELLIPSIS Creating source release in svnsample.tgz ... The referenced section, 'repos', was not defined.
svnsample配置,release.cfg包含以下内容
find-links = ${repos:svnsample}
在这里,预期值将由用户的default.cfg提供。我们将提供一个指向我们的链接服务器的值。首先,我们将sample eggs放回链接服务器上
>>> for p in os.listdir('sample_eggs_aside'): ... os.rename(join('sample_eggs_aside', p), join(sample_eggs, p)) >>> remove('sample_eggs_aside')>>> print system(join('bin', 'buildout-source-release')+' '+ ... 'svn://svn.zope.org/repos/main/zc.sourcerelease/svnsample'+ ... ' release.cfg'+ ... ' repos:svnsample='+link_server), ... # doctest: +ELLIPSIS Creating source release in svnsample.tgz ...>>> ls('.') - .installed.cfg d bin - buildout.cfg - custom_name_one.tgz - custom_name_two.tgz d develop-eggs d eggs d parts d sample - sample.tgz - svnsample.tgz d test>>> mkdir('svntest') >>> import tarfile >>> tf = tarfile.open('svnsample.tgz', 'r:gz') >>> for name in tf.getnames(): ... tf.extract(name, 'svntest') >>> tf.close()>>> print system(sys.executable ... +' '+join('svntest', 'svnsample', 'install.py')), ... # doctest: +ELLIPSIS Creating directory ...>>> print system(join('svntest', 'svnsample', 'bin', 'sample')), sample from svn called
当然,您可以指定不同的配置文件。让我们创建一个包含错误配置文件,因为它包含egg-directory的绝对路径。
>>> write(sample, 'wrong.cfg', ... ''' ... [buildout] ... parts = sample ... find-links = %(link_server)s ... eggs-directory = /somewhere/shared-eggs ... ... [sample] ... recipe = zc.recipe.egg ... eggs = sample1 ... ''' % globals())
我们将对此配置文件运行发布脚本
>>> print system(join('bin', 'buildout-source-release') ... +' file://'+sample+' wrong.cfg'), ... # doctest: +ELLIPSIS Creating source release in sample.tgz Invalid eggs directory (perhaps not a relative path) /somewhere/shared-eggs
发布历史
0.4.0 (2012-12-17)
添加了distribute支持。
项目中的符号链接被保留。
0.3.1 (2009-09-25)
修复了由zc.buildout最近更改暴露的潜在错误。
此错误导致源发行版中包含的安装脚本失败。
0.3.0 (2008-11-21)
新功能
现在您可以使用 -name(或 -n)选项来指定生成的发布版本的名称。
已修复的bug
在 buildout.cfg 中具有绝对 eggs-directory 现在将引发错误,而不是无限期地尝试查找相对路径。
0.2 (2007-10-25)
新功能
增加了在构建源时将 buildout 选项设置作为命令行选项传递的功能,以提供通常由 ~/.buildout/default.cfg 提供的值。
已修复的bug
未正确处理非标准 eggs-directory 设置。
0.1 (2007-10-24)
初始发布
下载
项目详情
zc.sourcerelease-0.4.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 13c9766c1d9d6276a4d5be0960a7c2a19a94693948ff860d45979485d5e32eea |
|
MD5 | 7d756a7d039afd2a7a2fe02817317330 |
|
BLAKE2b-256 | 041710c423c86ae7f71923c1bb7159e54660ab2e23bf0cdcf96bac1116a5fcc0 |