跳转到主要内容

修补egg的配方

项目描述

详细文档

支持的选项

该配方支持以下选项

path

定义应应用补丁的目录。例如

path = src/some/directory/
egg

定义应修补哪个egg。您还可以锁定到特定版本。例如

egg = some.egg<=1.1.1
patches

补丁文件的路径。这些补丁按顺序应用。例如

patches = patches/my_very_sprecial.patch
          patches/another_loverly.patch

示例用法

我们将要修补的我们的示例包

>>> mkdir(sample_buildout, 'demo')
>>> write(sample_buildout, 'demo', 'README.txt', " ")
>>> write(sample_buildout, 'demo', 'demo.py',
... """# demo egg
... """)
>>> write(sample_buildout, 'demo', 'setup.py',
... """
... from setuptools import setup
...
... setup(
...     name = "demo",
...     version='1.0',
...     py_modules=['demo']
...     )
... """)
>>> print system(buildout+' setup demo bdist_egg'), # doctest: +ELLIPSIS
Running setup script 'demo/setup.py'.
...

创建我们的补丁

>>> write(sample_buildout, 'demo.patch',
... """diff --git demo.py demo.py
... --- demo.py
... +++ demo.py
... @@ -1 +1,2 @@
...  # demo egg
... +# patching
... """)

让我们写出buildout.cfg来修补我们的示例包

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-patch
... index = demo/dist/
...
... [demo-patch]
... recipe = collective.recipe.patch
... egg = demo==1.0
... patches = demo.patch
... """)

我们的最终egg名称取决于当前的Python版本

>>> import sys
>>> demoegg = 'demo-1.0-py%d.%d.egg' % sys.version_info[:2]

运行buildout给我们

>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-patch.
...
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../demo.patch
...
patch: successfully patched ...develop-eggs/demo-1.0-py...egg/demo.py
>>> ls(sample_buildout, 'develop-eggs', demoegg)
d  EGG-INFO
-  demo.py
-  demo.pyc
-  demo.pyo
>>> cat(sample_buildout, 'demo', 'demo.py')
# demo egg
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# demo egg
# patching

多个补丁

如果您要应用多个补丁

>>> write(sample_buildout, 'another.patch',
... """diff --git demo.py demo.py
... --- demo.py
... +++ demo.py
... @@ -1,2 +1 @@
... -# demo egg
...  # patching
... """)

更新您的buildout.cfg以列出新的补丁。在这种情况下,another.patch应在demo.patch之后应用

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-patch
... index = demo/dist/
...
... [demo-patch]
... recipe = collective.recipe.patch
... egg = demo==1.0
... patches = demo.patch
...           another.patch
... """)

运行buildout给我们

>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-patch.
...
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../demo.patch
...
patch: successfully patched ...develop-eggs/demo-1.0-py...egg/demo.py
patch: reading patch .../another.patch
...
patch: successfully patched ...develop-eggs/demo-1.0-py...egg/demo.py
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# patching

外部二进制文件

我们还可以设置用于修补的外部二进制文件

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-patch
... index = demo/dist/
...
... [demo-patch]
... recipe = collective.recipe.patch
... patch-binary = patch
... egg = demo==1.0
... patches = demo.patch
... """)

运行buildout给我们

>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-patch.
...
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../demo.patch
...
patch: patching file demo.py
>>> ls(sample_buildout, 'develop-eggs', demoegg)
d  EGG-INFO
-  demo.py
-  demo.pyc
-  demo.pyo
>>> cat(sample_buildout, 'demo', 'demo.py')
# demo egg
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# demo egg
# patching

修补安装在另一部分的egg

另一种可能是使用zc.recipe.egg(或可能任何其他配方)安装一个蛋,并在之后对其进行修补。但是,必须解压安装egg,蛋最终可能会出现在eggs文件夹而不是develop-eggs文件夹中。

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-egg demo-patch
... index = demo/dist/
...
... [demo-egg]
... recipe = zc.recipe.egg
... eggs = demo==1.0
... unzip = true
...
... [demo-patch]
... recipe = collective.recipe.patch
... egg = ${demo-egg:eggs}
... patches = demo.patch
... """)

运行buildout给我们

>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-egg.
...
Getting distribution for 'demo==1.0'.
Got demo 1.0.
Installing demo-patch.
...
patch: successfully patched ...eggs/demo-1.0-py...egg/demo.py
>>> ls(sample_buildout, 'eggs', demoegg)
d  EGG-INFO
-  demo.py
-  demo.pyc
-  demo.pyo
>>> cat(sample_buildout, 'demo', 'demo.py')
# demo egg
>>> cat(sample_buildout, 'eggs', demoegg, 'demo.py')
# demo egg
# patching

损坏的补丁

如果其中一个补丁损坏了

>>> write(sample_buildout, 'missing-file.patch',
... """diff --git missing-file.py missing-file.py
... --- missing-file.py
... +++ missing-file.py
... @@ -1,2 +0 @@
... -# BROKEN
... -# PATCH
... """)

当你尝试应用多个补丁时,它将无法应用后续的补丁,让你修复问题

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-patch
... index = demo/dist/
...
... [demo-patch]
... recipe = collective.recipe.patch
... egg = demo==1.0
... patches = missing-file.patch
...           demo.patch
... """)

运行buildout给我们

>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-patch.
...
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../missing-file.patch
...
patch: source/target file does not exist
--- .../missing-file.py
+++ .../missing-file.py
While:
  Installing demo-patch.
Error: could not apply .../missing-file.patch
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# demo egg

或者在使用外部二进制文件时

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo-patch
... index = demo/dist/
...
... [demo-patch]
... recipe = collective.recipe.patch
... patch-binary = patch
... egg = demo==1.0
... patches = missing-file.patch
...           demo.patch
... """)
>>> print system(buildout)
Not found: demo/dist/...
...
Installing demo-patch.
patch: reading patch .../missing-file.patch
...
patch: patch: **** malformed patch at line 6:
While:
  Installing demo-patch.
Error: could not apply .../missing-file.patch
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# demo egg

贡献者

  • Rok Garbas,作者

  • Dylan Jay

  • Gerhard Weis

  • Simon Law

变更历史

0.2.2 (2009-12-14)

  • 让测试再次通过 [garbas]

0.2.1 (2009-12-14)

  • 使测试不依赖于Python版本

  • 恢复Python 2.4兼容性

0.2 (2009-11-20)

  • 添加了使用外部补丁二进制文件而不是捆绑的python-patch的选项

  • 允许指定多个补丁。

  • 如果任何补丁已更改,则重新应用补丁。

  • 如果任何补丁损坏,则中止。

0.1 (2008-10-27)

  • 使用ZopeSkel创建配方 [garbas]

下载

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

collective.recipe.patch-0.2.2.tar.gz (10.7 kB 查看哈希值)

上传时间

由以下支持