在 python 中使用 git 子模块 [英] Using git submodules with python
问题描述
我在这个网站上阅读了很多关于 git 子模块使用的博客文章和问题,但仍然不知道如何更好地将它们与 python 一起使用.
I've read a lot of blog posts and questions on this site about the usage of git submodules and still have no idea how to better use them with python.
我的意思是,如果我有这样的包,管理依赖项的更简单方法是什么:
I mean, what is the easier way to manage dependencies if I have such a package:
├── mypkg
│ └── __init__.py
├── setup.py
└── submodules
├── subm1
└── subm2
那么,如果我需要使用mypkg"怎么办?作为top_level_pkg"的子模块:
Then, what if I need to use "mypkg" as a submodule for "top_level_pkg":
├── setup.py
├── submodules
│ └── mypkg
└── top_level_package
└── __init__.py
,我想运行 pip install .
并正确解析(按正确顺序将每个子模块安装到 VENV).
, I want to run pip install .
and have all resolved correctly (have each submodule installed to the VENV in correct order).
我尝试过的:
- 使用pip"安装每个子模块在子进程中运行.但这似乎是一种hacky方式并且难以管理(GIT 子模块的意外安装)
- 使用install_requires"使用setuptools.find_packages()";但没有成功
- 为每个子模块使用 requirements.txt 文件,但我找不到如何自动执行它的方法,因此pip"可以自动安装所有子模块的所有要求.
理想情况下,我想为每个带有 install_requires=['submodules/subm1', 'submodules/submn']
的子模块创建一个单独的 setup.py 文件,但 setuptools 不支持它.
Ideally, I imagine a separate setup.py file for each submodule with install_requires=['submodules/subm1', 'submodules/submn']
, but setuptools does not support it.
推荐答案
感谢 Gijs Wobben 和 sinoroc 我想出了适合我的情况的解决方案:>
Thankfully to Gijs Wobben and sinoroc I came up with solution that works for my case:
install_requires=['subm1 @ file://localhost/<CURENT_DIR>/path/to/subm1']
这篇关于在 python 中使用 git 子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!