我将Python项目A、B和C放在单独的git repos中。它们在每个库中都使用一些类似的代码,因此我希望将代码重构为一个单独的、共享的repository.The代码,在这个存储库中实际上只是几个助手类。我可以把这个新的回购项目A,B和C中的文件作为一个git子模块。
不过,我现在遇到的问题是,如果git子模块中的代码具有外部pip依赖关系,那么顶级项目除了自己的依赖之外,如何解决这些依赖关系呢?
也许git子模块不是这里的正确方法,但我真的想避免为相当于3-4个轻量级模块/类的私有pypi服务器设置。
发布于 2019-07-09 19:46:34
不过,我现在遇到的问题是,如果git子模块中的代码具有外部pip依赖关系,那么顶级项目除了自己的依赖之外,如何解决这些依赖关系呢?
在您的子模块存储库中,一如既往地在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,都应该这样做。
资源:
https://stackoverflow.com/questions/56959413
复制相似问题