I have a package that depends on docker-py and I want to upgrade the dependency to docker. Unfortunately those two packages don't play along with each other very well.
A safe way to do things would be to first uninstall docker-py and then install my package, which will install docker in its place (I already changed the requirements from docker-py to docker).
Is there a way for this to happen in setup.py when I upgrade my package (via pip or any other way) without messing up the python environment?
The first thing that came to my mind was to check, in setup.py, if docker-py is already installed and run pip uninstall
like so:
from setuptools import setup
...
if 'docker-py' in [x.project_name for x in pip.get_installed_distributions()]:
submodule.check_call("pip uninstall -y docker-py".split())
setup(
...
)
Setup will then install the new dependecy and everything will work fine.
Is this safe? Any better alternatives?