[英]What is the best way to use a custom fork of a python library in another python project?
I am developing a python application.我正在开发一个 python 应用程序。 This application relies on an open source library that I have forked and heavily modified.这个应用程序依赖于我已经分叉和大量修改的开源库。
If it matters, the (very much WIP) forked library is available on github it it helps.如果重要的话,(非常多的 WIP)分叉库在github上可用,它有帮助。
To import the forked library in my application, what I am currently doing is as follows:要在我的应用程序中导入分叉库,我目前正在做的事情如下:
sys.path.append(os.path.abspath(os.path.join(__file__, '..', '..', '..', '..', '..', 'couchdb')))
import couchdb
This works, but I'm not entirely happy with it for obvious reasons.这有效,但由于显而易见的原因,我并不完全满意。 It's far from elegant or flexible, and also seems to confuse my IDE.它远非优雅或灵活,而且似乎也让我的 IDE 感到困惑。 I feel like, especially in a language as elegant as Python, there ought to be a better way to simultaneously develop both an application and a library it depends on.我觉得,尤其是在像 Python 这样优雅的语言中,应该有更好的方法来同时开发应用程序和它所依赖的库。
Both the library and the application are currently located side-by-side in a folder on my machine, sharing a virtual environment but residing in two separate git repositories.库和应用程序目前并排位于我机器上的一个文件夹中,共享一个虚拟环境但驻留在两个单独的 git 存储库中。 It is important to me that they remain in different git repositories, so nesting the library within the application is out, but the rest I'm happy to change.对我来说,它们保留在不同的 git 存储库中很重要,因此在应用程序中嵌套库已经过时了,但我很乐意更改其余部分。
I'm certain someone else has been in this situation before, so I'm hoping someone knows a way of doing this which is more "officially sanctioned" by Python.我确定其他人以前也遇到过这种情况,所以我希望有人知道一种更“官方认可”的方法来做到这一点。
The fact that your code is based on couchdb
isn't really important, since it's not compatible with couchdb
anymore, presumably.您的代码基于couchdb
的事实并不重要,因为它可能不再与couchdb
兼容。 Just install it properly under its own unique name, then import it as you would any other module.只需以它自己的唯一名称正确安装它,然后像导入任何其他模块一样导入它。
import couchdbdmj
Don't make your scripts depend on your development environment: configure your development environment to provide your custom modules in a uniform matter.不要让你的脚本依赖于你的开发环境:配置你的开发环境,以统一的方式提供你的自定义模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.