__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import absolute_import
  2. from __future__ import print_function
  3. from __future__ import unicode_literals
  4. import os
  5. import subprocess
  6. import sys
  7. # Attempt to detect https://github.com/docker/compose/issues/4344
  8. try:
  9. # We don't try importing pip because it messes with package imports
  10. # on some Linux distros (Ubuntu, Fedora)
  11. # https://github.com/docker/compose/issues/4425
  12. # https://github.com/docker/compose/issues/4481
  13. # https://github.com/pypa/pip/blob/master/pip/_vendor/__init__.py
  14. env = os.environ.copy()
  15. env[str('PIP_DISABLE_PIP_VERSION_CHECK')] = str('1')
  16. s_cmd = subprocess.Popen(
  17. ['pip', 'freeze'], stderr=subprocess.PIPE, stdout=subprocess.PIPE,
  18. env=env
  19. )
  20. packages = s_cmd.communicate()[0].splitlines()
  21. dockerpy_installed = len(
  22. list(filter(lambda p: p.startswith(b'docker-py=='), packages))
  23. ) > 0
  24. if dockerpy_installed:
  25. from .colors import yellow
  26. print(
  27. yellow('WARNING:'),
  28. "Dependency conflict: an older version of the 'docker-py' package "
  29. "may be polluting the namespace. "
  30. "If you're experiencing crashes, run the following command to remedy the issue:\n"
  31. "pip uninstall docker-py; pip uninstall docker; pip install docker",
  32. file=sys.stderr
  33. )
  34. except OSError:
  35. # pip command is not available, which indicates it's probably the binary
  36. # distribution of Compose which is not affected
  37. pass
  38. except UnicodeDecodeError:
  39. # ref: https://github.com/docker/compose/issues/4663
  40. # This could be caused by a number of things, but it seems to be a
  41. # python 2 + MacOS interaction. It's not ideal to ignore this, but at least
  42. # it doesn't make the program unusable.
  43. pass