简体   繁体   English

在另一个 python 项目中使用 python 库的自定义分支的最佳方法是什么?

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

相关问题 在 Firebase 项目中使用 python 库的最佳方法 - Best way to use python library in Firebase project 在 Python 库上启动参数的最佳方法是什么? - What is the best way to initiate parameters on a Python library? 在 python 脚本中开发数据库并同时在另一个 python 脚本(Django 应用程序)中使用数据库的最佳方法是什么? - What is the best way to develop a database in a python script and use the database in another python script (Django app) at the same time? 在python正则表达式中使用OR的最佳方法是什么 - What is the best way to use OR in python regex 使用 Python 鼠兔库合并 RabbitMQ 队列的最佳方法是什么? - What is the best way to merge RabbitMQ queues using Python pika library? 在另一个 function (Python)中使用来自一个 function 的变量的最佳方法是什么? - What is the best way to use a variable from one function in another function (Python)? 从 python 的项目中检索模块路径的最佳方法是什么? - What's the best way to retrieve the module path from the project in python? 在Python中派生多个Shell命令/进程的最佳方法? - Best way to fork multiple shell commands/processes in Python? 在我的 python 项目中使用我自己的模块的最佳方式 - Best way to use my own module in my python project 分发使用自定义c模块扩展的python程序的最佳方法是什么? - What is the best way to distribute a python program extended with custom c modules?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM