依赖于另一个子包的 Python 命名空间子包无法安装



我的目标是创建一个包含两个子包的命名空间包:foo和bar(依赖于foo(,并将命名空间包推送到git存储库(不将其发布到PyPI(,以便我可以安装带有存储库URL的子包。

我正在按照本教程创建命名空间结构:

root/
├ setup.py
└ microlibs/
├ foo/
│  ├ setup.py
│  ├ macrolib/
│     └ foo/
│        ├ __init__.py
│        ├ module1.py
│        ├ ...
│        └ moduleN.py
.
.
.
└ bar/
├ setup.py
├ macrolib/
└ bar/
├ __init__.py
├ module1.py
├ ...
└ moduleN.py

foo的 setup.py 文件没有依赖关系:

foo/setup.py

from setuptools import setup
microlib_name = 'macrolib.foo'
setup(
name=microlib_name,
version="0.1.0",
namespace_packages=['macrolib'],
packages=[microlib_name],
install_requires=[]
)

由于 bar 的依赖项包括 foo,因此 bar 的 setup.py 包括install_requires列表中的 macrolib.bar:

酒吧/设置.py

from setuptools import setup
microlib_name = 'macrolib.bar'
setup(
name=microlib_name,
version="0.1.0",
namespace_packages=['macrolib'],
packages=[microlib_name],
install_requires=[
'macrolib.foo'
]
)

推送到 bitbucket 存储库后,我可以安装 macrolib.foo,而不会出现问题存储库的子目录。

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=foo&egg=macrolib.foo"

安装 macrolib.foo 后,我还可以安装 macrolib.bar 存储库的子目录没有问题。

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

但是,如果我尝试安装 macrolib.bar 而不先安装 macrolib.foo,则安装失败。

$ pip install git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

错误:

Collecting macrolib.foo (from macrolib.bar==0.1.0)
Could not find a version that satisfies the requirement macrolib.foo (from macrolib.bar==0.1.0) (from versions: )
No matching distribution found for macrolib.foo (from macrolib.bar==0.1.0)

我猜这是因为在 bar/setup.py 中缺少dependency_links。所以我尝试了链接网址的不同组合,都失败了,出现相同的错误。

我尝试过的格式:

dependency_links=['http://path/to/repo.git@<branch name>#"subdirectory=foo&egg=macrolib.foo"']
dependency_links=['http://path/to/repo.git@<branch name>#subdirectory=foo&egg=macrolib.foo']
dependency_links=['http://path/to/repo/tarball/<branch name>#"subdirectory=foo&egg=macrolib.foo"']
dependency_links=['http://path/to/repo/tarball/<branch name>#subdirectory=foo&egg=macrolib.foo']
dependency_links=['http://path/to/repo/archive/<branch name>.zip#"subdirectory=foo&egg=macrolib.foo"']
dependency_links=['http://path/to/repo/archive/<branch name>.zip#subdirectory=foo&egg=macrolib.foo']

或者为上述所有网址添加前缀"git+"。

我的问题是,为了将 macrolib.foo 安装为依赖项,dependency_links的正确 url 格式是什么,或者还有其他方法可以使其工作吗?

这是正确的格式(添加"git+"和依赖版本(:

dependency_links=['git+http://path/to/repo.git@<branch name>#subdirectory=foo&egg=macrolib.foo-0.1.0']

您需要要求pip来处理它:

pip install --process-dependency-links git+http://path/to/repo.git@<branch name>#"subdirectory=bar&egg=macrolib.bar"

最新更新