跳转到主要内容

用于修复egg的recipe

项目描述

这是emencia.recipe.patch的分支。主要区别是

  • 增加了Python 3支持。

链接

支持选项

该recipe支持以下选项

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 = cykooz.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))
Installing demo-patch.
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../demo.patch
...
patch: patching file demo.py
patch: successfully patched .../demo-1.0...
...
>>> 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以列出新的补丁。在这种情况下,另一个.patch应在demo.patch之后应用

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

运行buildout会给我们

>>> rmdir(sample_buildout, 'develop-eggs', demoegg)
>>> remove(sample_buildout, '.installed.cfg')
>>> _ = system(buildout + ' setup demo bdist_egg')
>>> print_(system(buildout))
Installing demo-patch.
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../demo.patch
...
patch: patching file demo.py
patch: successfully patched .../demo-1.0...
patch: reading patch .../another.patch
...
patch: patching file demo.py
patch: successfully patched .../demo-1.0...
...
>>> cat(sample_buildout, 'develop-eggs', demoegg, 'demo.py')
# patching

修复安装在其他部分的egg

另一种可能性是使用zc.recipe.egg(或可能任何其他recipe)安装egg,然后对其进行修复。但是,必须解压缩安装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
...
... [demo-patch]
... recipe = cykooz.recipe.patch
... egg = ${demo-egg:eggs}
... patches = demo.patch
... """)

运行buildout会给我们

>>> rmdir(sample_buildout, 'develop-eggs', demoegg)
>>> remove(sample_buildout, '.installed.cfg')
>>> _ = system(buildout + ' setup demo bdist_egg')
>>> print_(system(buildout))
Installing demo-egg.
Getting distribution for 'demo==1.0'.
Got demo 1.0.
Installing demo-patch.
patch: reading patch .../demo.patch
...
patch: patching file demo.py
patch: successfully patched .../demo-1.0...
>>> 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 = cykooz.recipe.patch
... egg = demo==1.0
... patches = missing-file.patch
...           demo.patch
... """)

运行buildout会给我们

>>> rmdir(sample_buildout, 'eggs', demoegg)
>>> remove(sample_buildout, '.installed.cfg')
>>> _ = system(buildout + ' setup demo bdist_egg')
>>> print_(system(buildout))
Installing demo-patch.
Getting distribution for 'demo==1.0'.
Got demo 1.0.
patch: reading patch .../missing-file.patch
...
patch: The next patch would delete the file missing-file.py,
patch: which does not exist!  Skipping 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

下载

项目详情


下载文件

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

源分发

cykooz.recipe.patch-0.1.tar.gz (14.6 kB 查看哈希值)

上传时间

由以下支持