将 Python 与驻留在不同 git 存储库中的灵活远程库一起使用?
我从事的项目使用了很多不同的 git 存储库。有些是开源的,有些是闭源的。很多时候,编写的 Python 代码对项目的开源和闭源双方都有用,但在两者之间共享并不容易。
我想知道是否有人有一个巧妙的通用方法来解决这个问题,而不需要“在要运行脚本的每个系统上安装您的库”的明显答案。有几个原因导致这对我们来说不是一个可行的答案。
我们已经讨论了一些想法。最简单的方法是拥有一个开源库存储库,我们要求人们在使用它的存储库中运行脚本之前进行同步。虽然这种方法有效,但它是相当手动的,可能会导致问题,例如人们拥有过时的版本或忘记同步库本身。
我可以看到做这样的事情的另一种方法是分发一个虚拟的 python 文件,该文件处理所有同步并在导入发生时捕获它们。
例如,如果我跑: import favorite_lib
它将导入我在每个需要访问favorite lib的存储库中的虚拟favorite_lib.py,然后该库将依次 git clone 或 git 获取脚本所在目录中的favorite_lib存储库。
考虑到这一点,我还想做一些类似的事情:
from favorite_lib import Commands
最喜欢的lib 将被同步,并且目录中的commands.py 文件将被导入。
我还没有尝试实现上述内容,但我相信这是可能的。
我是否缺少此用例的一些优先级?还有其他人有更好的主意吗?我四处寻找并询问了很多人,但都没有真正具体的答案。
I work on a project that uses a lot of different git repos. 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.
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.
For example if I ran:
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.
With that in mind I would also like to do something like:
from favorite_lib import commands
favorite_lib would be sync'd and the commands.py file from the directory would be imported.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子模块
Submodules