Search code examples
pythonpipdependencieswrapperpypi

How to handle multiple major versions of dependency


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.


Solution

  • 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