__init__.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from __future__ import absolute_import
  2. from __future__ import print_function
  3. from __future__ import unicode_literals
  4. import subprocess
  5. import sys
  6. # Attempt to detect https://github.com/docker/compose/issues/4344
  7. try:
  8. # We don't try importing pip because it messes with package imports
  9. # on some Linux distros (Ubuntu, Fedora)
  10. # https://github.com/docker/compose/issues/4425
  11. # https://github.com/docker/compose/issues/4481
  12. # https://github.com/pypa/pip/blob/master/pip/_vendor/__init__.py
  13. s_cmd = subprocess.Popen(
  14. ['pip', 'freeze'], stderr=subprocess.PIPE, stdout=subprocess.PIPE
  15. )
  16. packages = s_cmd.communicate()[0].splitlines()
  17. dockerpy_installed = len(
  18. list(filter(lambda p: p.startswith(b'docker-py=='), packages))
  19. ) > 0
  20. if dockerpy_installed:
  21. from .colors import red
  22. print(
  23. red('ERROR:'),
  24. "Dependency conflict: an older version of the 'docker-py' package "
  25. "is polluting the namespace. "
  26. "Run the following command to remedy the issue:\n"
  27. "pip uninstall docker docker-py; pip install docker",
  28. file=sys.stderr
  29. )
  30. sys.exit(1)
  31. except OSError:
  32. # pip command is not available, which indicates it's probably the binary
  33. # distribution of Compose which is not affected
  34. pass