How to handle multiple major versions of dependency

余生长醉 提交于 2021-02-08 08:15:24

问题


I'm wondering how to handle multiple major versions of a dependency library.

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

  1. Switch to the new major version, potentially denying people on the old version.
  2. Keep going with the old version, potentially denying people on the new version.
  3. Have two different branches, updating both branches for all new features. Not sure how this works with PyPi. Wouldn't I have to release at different version numbers each time?
  4. Separate the repository into two parts. Don't really want to do this.

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.

Would much appreciate some pointers.


回答1:


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 ...).

You might also gain some insight from https://www.python.org/dev/peps/pep-0518/ for ways to control dependency installation.

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




回答2:


Have two different branches, updating both branches for all new features. Not sure how this works with PyPI. Wouldn't I have to release at different version numbers each time?

Yes, you could have a 1.x release (that supports the old version) and a 2.x release (that supports the new version) and release both simultaneously. This is a common pattern for packages that want to introduce a breaking change, but still want to continue maintaining the previous release as well.



来源:https://stackoverflow.com/questions/55519636/how-to-handle-multiple-major-versions-of-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!