与您自己的依赖项共享第三方依赖项的最佳实践
Best practices for sharing third party dependencies with your own dependencies
我的项目依赖于另一个项目,我在 setup.py
文件中使用 git 依赖性如下:
setup(
name="cake",
version="0.1",
install_requires=[
"flan @ git+ssh://git@github.com/terrymcguire/flan.git#egg=flan"
]
)
假设他们都依赖于pyyaml
。最好的做法是在两个项目的 setup.py
、install_requires: ...
(或您喜欢的 requirements.txt
)中包含一个 "pyyaml==5.1.2"
,并确保版本相同,或者是它建议只将 pyyaml
列为 flan
项目中的依赖项,然后在父项目中继承该版本,即使那时不太清楚 pyyaml
是父项目,如果有一天我不再依赖 flan
,我可能不会注意到我破坏了其他代码?
1.
Is it best practice to include a "pyyaml==5.1.2
" inside both projects' setup.py
, install_requires: ...
(or requirements.txt
as you prefer) [...]?
只有应用程序应该(可能)pin特定版本的要求。图书馆应限制在一系列已知的兼容版本(尽可能准确)。
总的来说,我认为将依赖项的版本固定在 setup.py
(或 pyproject.toml
)中是一个坏主意,因为最终用户不能(轻易)否决这些依赖项,最终用户安装项目(无论是应用程序还是库都无关紧要)以及应该对安装的内容拥有最终决定权的人。另一方面,最好以最终用户可能选择的 requirements.txt
文件的形式推荐已知运行良好(因为它已经过测试)的固定版本的依赖项组合使用或不使用(对于应用程序,这对库没有多大意义)。
阅读例如Donald Stufft's article "setup.py vs requirements.txt"。
2.
is it recommended to only have pyyaml listed as a dependency in the flan project, and then inherit the version in the parent project, even though it's then less clear that pyyaml is a dependency of the parent project [...]?
一般(显而易见的)规则是所有项目都应该列出它们自己的所有依赖项,并且只列出它们自己的依赖项。其他任何东西都没有任何意义(当然可能一如既往地有例外)。
我的项目依赖于另一个项目,我在 setup.py
文件中使用 git 依赖性如下:
setup(
name="cake",
version="0.1",
install_requires=[
"flan @ git+ssh://git@github.com/terrymcguire/flan.git#egg=flan"
]
)
假设他们都依赖于pyyaml
。最好的做法是在两个项目的 setup.py
、install_requires: ...
(或您喜欢的 requirements.txt
)中包含一个 "pyyaml==5.1.2"
,并确保版本相同,或者是它建议只将 pyyaml
列为 flan
项目中的依赖项,然后在父项目中继承该版本,即使那时不太清楚 pyyaml
是父项目,如果有一天我不再依赖 flan
,我可能不会注意到我破坏了其他代码?
1.
Is it best practice to include a "
pyyaml==5.1.2
" inside both projects'setup.py
,install_requires: ...
(orrequirements.txt
as you prefer) [...]?
只有应用程序应该(可能)pin特定版本的要求。图书馆应限制在一系列已知的兼容版本(尽可能准确)。
总的来说,我认为将依赖项的版本固定在 setup.py
(或 pyproject.toml
)中是一个坏主意,因为最终用户不能(轻易)否决这些依赖项,最终用户安装项目(无论是应用程序还是库都无关紧要)以及应该对安装的内容拥有最终决定权的人。另一方面,最好以最终用户可能选择的 requirements.txt
文件的形式推荐已知运行良好(因为它已经过测试)的固定版本的依赖项组合使用或不使用(对于应用程序,这对库没有多大意义)。
阅读例如Donald Stufft's article "setup.py vs requirements.txt"。
2.
is it recommended to only have pyyaml listed as a dependency in the flan project, and then inherit the version in the parent project, even though it's then less clear that pyyaml is a dependency of the parent project [...]?
一般(显而易见的)规则是所有项目都应该列出它们自己的所有依赖项,并且只列出它们自己的依赖项。其他任何东西都没有任何意义(当然可能一如既往地有例外)。