如何在setup.py中指定递归依赖?
How to specify recursive dependencies in setup.py?
我在理解和实施 Python 使用 pip
and setuptools
打包的一些细节时遇到困难。
假设我有三个项目,A
、B
和 C
,每个项目都是自己的包并托管在自己的代码库中。它们也相互依赖,即 A
由 B
导入,B
由 C
导入。每个包都有一组 direct 依赖(即直接导入其他包)和一组 indirect 依赖(即直接依赖包导入的包).这些依赖关系是一个图,而不是一棵树。
对于包 A
,setup.py 是否应该只包含直接依赖的包?包裹 B
也一样吗?然后 pip install C
我注意到安装了 B
,但没有安装 A
。我想那是因为 A
是 C
.
的间接依赖
我不太喜欢存储 pip freeze
in each package (inflexible and conflicts loom), but it seems that pip
does not resolve the dependency graph recursively (see here). The snakebasket
project attempted to address that problem, but is stale now; the dependency-links 选项的想法已被弃用。
处理此问题的正确和推荐方法是什么?
附录 我忘了提到包的 none (A
, B
, C
) 可通过官方 PyPi 存储库获得,但存在于私人 Github 存储库中。因此,例如 B
的 setup.py 包含
install_requires=(
…,
A==1.0.0,
…,
)
dependency_links=[
f"https://{github_token}@github.com/repo/A/archive/v1.0.0.tar.gz#egg=A-1.0.0",
],
和 C
包含包 B
的类似设置。
For package A, should setup.py
contain only the directly dependent packages?
是的。关注点分离:每个包都应该列出它需要的依赖项。分包应该自理。
When I then pip install C
I noticed that B gets installed, but not A.
你能举个例子吗?我有不一样的体验。
it seems that pip does not resolve the dependency graph recursively (see here).
2015 年的答案已过时。 pip install
和 pip download
递归安装和下载依赖项。
How to specify recursive dependencies in setup.py
?
不要。
What is the proper and recommended way of handling this?
setup.py
应该在 install_requires=[...]
下列出 direct 依赖项。不要列出传递依赖项。并且不要在此处固定依赖项(尽管在某些情况下,您可能需要指定上限或下限以确保收集到兼容版本)。
When I then pip install C
I noticed that B
gets installed, but not A
.
那么 B
没有正确指定对 A
的依赖。再次检查 B
.
的元数据
是是的,pip 有时无法正确解析依赖树,并且自 2013 年以来就有 open issue about that,但您不会在简单的 C -> B -> A 依赖图,仅在一些更病态的情况下。
查看我的项目 johnnydep
以呈现 dep 树并指出包元数据中缺少 "branch" 的地方。
我在理解和实施 Python 使用 pip
and setuptools
打包的一些细节时遇到困难。
假设我有三个项目,A
、B
和 C
,每个项目都是自己的包并托管在自己的代码库中。它们也相互依赖,即 A
由 B
导入,B
由 C
导入。每个包都有一组 direct 依赖(即直接导入其他包)和一组 indirect 依赖(即直接依赖包导入的包).这些依赖关系是一个图,而不是一棵树。
对于包 A
,setup.py 是否应该只包含直接依赖的包?包裹 B
也一样吗?然后 pip install C
我注意到安装了 B
,但没有安装 A
。我想那是因为 A
是 C
.
我不太喜欢存储 pip freeze
in each package (inflexible and conflicts loom), but it seems that pip
does not resolve the dependency graph recursively (see here). The snakebasket
project attempted to address that problem, but is stale now; the dependency-links 选项的想法已被弃用。
处理此问题的正确和推荐方法是什么?
附录 我忘了提到包的 none (A
, B
, C
) 可通过官方 PyPi 存储库获得,但存在于私人 Github 存储库中。因此,例如 B
的 setup.py 包含
install_requires=(
…,
A==1.0.0,
…,
)
dependency_links=[
f"https://{github_token}@github.com/repo/A/archive/v1.0.0.tar.gz#egg=A-1.0.0",
],
和 C
包含包 B
的类似设置。
For package A, should
setup.py
contain only the directly dependent packages?
是的。关注点分离:每个包都应该列出它需要的依赖项。分包应该自理。
When I then
pip install C
I noticed that B gets installed, but not A.
你能举个例子吗?我有不一样的体验。
it seems that pip does not resolve the dependency graph recursively (see here).
2015 年的答案已过时。 pip install
和 pip download
递归安装和下载依赖项。
How to specify recursive dependencies in
setup.py
?
不要。
What is the proper and recommended way of handling this?
setup.py
应该在 install_requires=[...]
下列出 direct 依赖项。不要列出传递依赖项。并且不要在此处固定依赖项(尽管在某些情况下,您可能需要指定上限或下限以确保收集到兼容版本)。
When I then
pip install C
I noticed thatB
gets installed, but notA
.
那么 B
没有正确指定对 A
的依赖。再次检查 B
.
是是的,pip 有时无法正确解析依赖树,并且自 2013 年以来就有 open issue about that,但您不会在简单的 C -> B -> A 依赖图,仅在一些更病态的情况下。
查看我的项目 johnnydep
以呈现 dep 树并指出包元数据中缺少 "branch" 的地方。