__init__.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 yellow
  22. print(
  23. yellow('WARNING:'),
  24. "Dependency conflict: an older version of the 'docker-py' package "
  25. "may be polluting the namespace. "
  26. "If you're experiencing crashes, run the following command to remedy the issue:\n"
  27. "pip uninstall docker-py; pip uninstall docker; pip install docker",
  28. file=sys.stderr
  29. )
  30. except OSError:
  31. # pip command is not available, which indicates it's probably the binary
  32. # distribution of Compose which is not affected
  33. pass
  34. except UnicodeDecodeError:
  35. # ref: https://github.com/docker/compose/issues/4663
  36. # This could be caused by a number of things, but it seems to be a
  37. # python 2 + MacOS interaction. It's not ideal to ignore this, but at least
  38. # it doesn't make the program unusable.
  39. pass