如何处理依赖关系的多个主要版本 [英] How to handle multiple major versions of dependency
问题描述
我想知道如何处理依赖库的多个主要版本.
I'm wondering how to handle multiple major versions of a dependency library.
在早期发布阶段,我有一个开源库 Foo
.该库是另一个开源库 Bar
的包装. Bar
刚刚推出了一个新的主要版本. Foo
当前仅支持以前的版本.由于我猜想很多人从 Bar
的以前的主要版本转换到新的主要版本会非常缓慢,我不愿意自己切换到新版本.
I have an open source library, Foo
, at an early release stage. The library is a wrapper around another open source library, Bar
. Bar
has just launched a new major version. Foo
currently only supports the previous version. As I'm guessing that a lot of people will be very slow to convert from the previous major version of Bar
to the new major version, I'm reluctant to switch to the new version myself.
如何最好地处理?在我看来,我有这些选择
How is this best handled? As I see it I have these options
- 切换到新的主要版本,可能会导致人们拒绝使用旧版本.
- 继续使用旧版本,可能会拒绝人们使用新版本.
- 具有两个不同的分支,为所有新功能更新两个分支.不确定如何与PyPi一起使用.每次都不必以不同的版本号发布吗?
- 将存储库分为两部分.真的不想这样做.
对我来说,理想的解决方案是使用相同的代码库,其中可以使用某种类似于C/C ++宏的内容,如果版本为 new
,则使用 new_bar_function
,否则请使用 old_bar_function
.从PyPi安装库时,主要版本的已安装版本指示使用哪个版本.如果未安装任何版本,请安装最新版本.
The ideal solution for me would be to have the same code base, where I could have some sort of C/C++ macro-like thing where if the version is new
, use new_bar_function
, else use old_bar_function
. When installing the library from PyPi, the already installed version of the major version dictates which version is used. If no version is installed, install the newest.
非常感谢一些提示.
推荐答案
通常,在使用 package .__ version __
导入后,可以使用Package版本信息.您可以从 Bar
中解析该信息,并据此决定要做什么(选择适当的函数调用或暂停程序或引发错误或...).
Normally the Package version information is available after import with package.__version__
. You could parse that information from Bar
and decide based on this what to do (chose the appropriate function calls or halt the program or raise an error or ...).
您还可以从> https://www.python.org中获得一些见识./dev/peps/pep-0518/了解控制依赖项安装的方法.
You might also gain some insight from https://www.python.org/dev/peps/pep-0518/ for ways to control dependency installation.
似乎如果某人已经安装了 Bar
,则在 Foo
明确要求时,安装 Foo
只会更新 Bar
新版本.参见 https://github.com/pypa/pip/pull/4500 answer
It seems that if someone already has Bar
installed, installing Foo
only updates Bar
if Foo
explicitly requires the new version. See https://github.com/pypa/pip/pull/4500 and this answer
这篇关于如何处理依赖关系的多个主要版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!