gpt4 book ai didi

python - 如何解决Python Git子模块的依赖关系

转载 作者:行者123 更新时间:2023-12-01 00:46:08 24 4
gpt4 key购买 nike

我在单独的 git 存储库中拥有 Python 项目 A、B 和 C。他们在每个代码中都使用了一些类似的代码,因此我想将代码重构到一个单独的共享存储库中。此存储库中的 Python 代码实际上只是一些帮助程序类。我可以将这个新存储库中的文件作为 git 子模块包含在项目 A、B 和 C 中。

我现在遇到的问题是,如果 git 子模块中的代码具有外部 pip 依赖项,那么除了自己的依赖项之外,顶级项目如何解决这些依赖项?

也许 git-submodules 在这里不是正确的方法,但我真的想避免为 3-4 个轻量级模块/类设置私有(private) pypi 服务器。

最佳答案

The problem I have now though is that if the code in the git submodule has external pip dependencies, how do the top-level projects resolve those dependencies in addition to their own?

在您的子模块存储库中,像往常一样将您的依赖项包含在 requirements.txt 中。

然后在您的文档中,请务必在安装 A、B 或 C 之前包含有关安装子模块包的说明。

举个例子,假设包 A 是 foo,子模块是 bar。

tree
.
└── foo
├── bar
│   ├── bar
│   │   └── __init__.py
│   ├── requirements.txt # external pip dependencies
│   └── setup.py
├── foo
│   └── __init__.py
├── requirements.txt
└── setup.py # include

4 directories, 6 files

然后在您的文档中您可以包含这样的内容,

<小时/>

安装 Foo

# Initialize submodule(s)
git submodule update --init --recursive

# First install bar
cd bar

# Resolve any dependencies for bar
pip install -r requirements.txt

# Install bar
python setup.py install

# Now install foo
cd ..

# Resolve any other dependencies for foo
pip install -r requirements.txt

# Install foo
python setup.py install

注意:应对所有三个存储库(例如 A、B 和 C)执行此操作。

<小时/>

资源:

关于python - 如何解决Python Git子模块的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56959413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com