[英]How to resolve dependencies of Python Git Submodule
I have Python projects A, B, and C in separate git repos.我在单独的 git 存储库中有 Python 项目 A、B 和 C。 They're using some similar code in each so I want to refactor the code into a separate, shared repository.The Python code in this repository is really just a few helper classes.
他们在每一个中都使用了一些类似的代码,所以我想将代码重构到一个单独的共享存储库中。这个存储库中的 Python 代码实际上只是一些帮助类。 I can include the files in this new repo in projects A, B, and C as a git-submodule.
我可以将这个新 repo 中的文件作为 git-submodule 包含在项目 A、B 和 C 中。
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?我现在遇到的问题是,如果 git 子模块中的代码具有外部 pip 依赖项,那么顶级项目除了自己的依赖项之外如何解决这些依赖项?
Perhaps git-submodules are not the right approach here, but I really want to avoid setting up a private pypi server for what amounts to 3-4 lightweight modules/classes.也许 git-submodules 在这里不是正确的方法,但我真的想避免为 3-4 个轻量级模块/类设置私有 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?
我现在遇到的问题是,如果 git 子模块中的代码具有外部 pip 依赖项,那么顶级项目除了自己的依赖项之外如何解决这些依赖项?
In your sub-module repository, include your dependencies in requirements.txt
as usual.在您的子模块存储库中,像往常一样在
requirements.txt
包含您的依赖项。
Then in your documentation, be sure to include instructions on installing the sub-module package before installing A, B, or C.然后在您的文档中,确保在安装 A、B 或 C 之前包含有关安装子模块包的说明。
For an example, lets say that package A is foo, and the sub-module is bar.例如,假设包 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
Then in your documentation you can include something like this,然后在您的文档中,您可以包含这样的内容,
# 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
Note: This should be done for all three repositories, eg, A, B, and C.注意:这应该对所有三个存储库执行,例如,A、B 和 C。
Resources:资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.