简体   繁体   English

将Python与位于其他git repo中的灵活远程库一起使用?

[英]Using Python with a flexible remote library that resides in a different git repo?

I work on a project that uses a lot of different git repos. 我从事的项目使用很多不同的git仓库。 Some are open source and some are closed source. 有些是开源的,有些是封闭的。 Often times there is python code written that would be useful for both open and closed source sides of the project but it is not easy to share between the two. 通常,编写的python代码对项目的开放源代码和封闭源代码都有用,但在两者之间共享并不容易。

I am wondering if anyone has a slick general way to solve this problem with out the obvious answer of "install your library on every system you want to run the scripts on" There are a few reasons why that is not a viable answer for us. 我想知道是否有人能以一种巧妙的方式来解决此问题,而没有一个明显的答案:“在要运行脚本的每个系统上安装您的库”,这对于我们来说不是一个可行的答案。

We have kicked around a few ideas. 我们提出了一些想法。 The simplest would be to have an open source library repo that we require people to sync before running scripts in either repo that utilizes it. 最简单的方法是拥有一个开放源代码库存储库,我们需要人们在使用该存储库的任何一个存储库中运行脚本之前进行同步。 While this works it is quite manual and could lead to issues like people having out of date versions or forgetting to sync the library themselves. 尽管这样做有效,但它是完全手动的,可能会导致出现问题,例如人们的版本过旧或忘记自己同步库。

The other way I could see doing something like this would be to distribute a dummy python file that handles all the syncing and captures imports as they happen. 我可以看到的另一种方法是分发一个虚拟python文件,该文件处理所有同步并在导入发生时捕获它们。

For example if I ran: import favorite_lib 例如,如果我运行了:import favorite_lib

It would import the dummy favorite_lib.py I have in each repo that needs access to favorite lib that would then in turn git clone or git fetch the favorite_lib repo in the directory where the script lives. 它将导入我在每个存储库中需要访问收藏夹库的虚拟虚拟收藏夹.py,然后git clone或git会在脚本所在的目录中获取收藏夹库。

With that in mind I would also like to do something like: 考虑到这一点,我还想做些类似的事情:

from favorite_lib import commands 从favourite_lib导入命令

favorite_lib would be sync'd and the commands.py file from the directory would be imported. favorite_lib将被同步,并将导入目录中的commands.py文件。

I haven't tried implementing the above but I believe it is mostly possible. 我没有尝试实现上面的方法,但是我相信大多数情况下都是可能的。

Am I missing some precedence for this use case? 我是否缺少此用例的优先级? Does anyone else have a better idea? 还有其他人有更好的主意吗? I have searched around and asked a number of people with no real concrete answer. 我四处搜寻,并问了一些没有真正具体答案的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM