补蛋食谱
cykooz.recipe.patch的Python项目详细描述
这是emencia.recipe.patch的叉。主要区别是:
- 添加了Python3支持。
链接:
- https://pypi.python.org/pypi/cykooz.recipe.patch-下载
- https://github.com/cykooz/cykooz.recipe.patch-源代码
支持的选项
配方支持以下选项:
- 路径
定义应用修补程序的目录。为了 示例:
path = src/some/directory/
- 鸡蛋
定义应该修补的鸡蛋。您还可以固定到特定的 版本。例如:
egg = some.egg<=1.1.1
- 补丁
修补程序文件的路径。这些补丁是按顺序应用的。为了 示例:
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]
运行构建会给我们带来:
>>> 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 ... """)
运行构建会给我们带来:
>>> 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
修补安装在另一部分的鸡蛋
另一种可能是安装一个带有zc.recipe.egg(或 可能还有其他配方)然后补上。然而,它是 必须将鸡蛋拉开拉链,鸡蛋可能会在 鸡蛋文件夹代替发展鸡蛋文件夹。
>>> 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 ... """)
运行构建会给我们带来:
>>> 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 ... """)
运行构建会给我们带来:
>>> 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