简体   繁体   English

黑客攻击第三方python模块的最佳实践

[英]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.

相关问题 使用 SWIG 使用 3rd-Party 驱动程序构建 Python 模块 - Using SWIG to build Python Module using 3rd-Party Drivers 文件夹名称遮蔽 3rd-party package 名称或 Python 模块名称是反模式吗? - Is folder name shadowing 3rd-party package name or Python module name is an anti-pattern? Django:迁移依赖于删除的第三方模块 - Django: Migrations depend on removed 3rd-party module 您如何正确模拟 Django 中的第 3 方模块 - How do you correctly mock a 3rd-party module in Django 如何在 VS Code 中调试第三方 Python package - How to debug a 3rd-party Python package in VS Code 如果删除不需要的 Python3 核心模块,未来的第 3 方软件包可能会出现什么问题 - What issues with future 3rd-party packages could be expected if removing unneeded Python3 core modules 是否可以在Jupyter笔记本单元中调试第三方python文件? - Is it possible to debug a 3rd-party python file inside a Jupyter notebook cell? 如何允许嵌入式Python解释器中调用的脚本导入第三方库? - How to allow 3rd-party libraries to be imported by scripts called in embedded Python interpreter? 如何在Python中安装第三方模块? - How to install a 3rd party module in Python? 如何包装第三方Django应用的视图 - How do you wrap the view of a 3rd-party Django app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM