[英]Best practice for hacking on a 3rd-party python module
I often find myself wanting to use a 3rd party python module in my own project, but I know that I will also need to make changes to the 3rd party module that I want to push upstream. 我经常发现自己想在我自己的项目中使用第三方python模块,但我知道我还需要对我想要向上游推送的第三方模块进行更改。 What is the best practice of file layout/installation to achieve this? 实现此目的的文件布局/安装的最佳实践是什么?
Most python modules are laid out with root dir containing a "setup.py" to compile/install the module. 大多数python模块都使用root目录进行布局,其中包含一个“setup.py”来编译/安装模块。 The problem is, every time I make changes to the module source I need to re-run the full install step in order to use those changes in my project. 问题是,每次我对模块源进行更改时,我都需要重新运行完整安装步骤才能在项目中使用这些更改。 For large modules, like scipy this can take some time. 对于像scipy这样的大型模块,这可能需要一些时间。
Alternatively, I can hack on the installed version of the python module, but then I have to manually move those changes back to the source version of the module in order to generate patches etc. 或者,我可以破解已安装的python模块版本,但是我必须手动将这些更改移回模块的源版本以生成补丁等。
I know about virtualenv and PYTHONPATH but they are ways of installing a module to a different location. 我知道virtualenv和PYTHONPATH,但它们是将模块安装到不同位置的方法。
So far, I have manually created symlinks, but that is messy. 到目前为止,我已经手动创建了符号链接,但这很麻烦。
If the 3rd party project is using setuptools or distribute, you can do python setup.py develop
instead of install
. 如果第三方项目使用setuptools或分发,你可以进行python setup.py develop
而不是install
。 This will create the appropriate sym-links in the site-packages dir for you. 这将在site-packages目录中为您创建适当的sym-links。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.