__init__.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. # DO NOT replace this call with a `sys.executable` call. It breaks the binary
  18. # distribution (with the binary calling itself recursively over and over).
  19. ['pip', 'freeze'], stderr=subprocess.PIPE, stdout=subprocess.PIPE,
  20. env=env
  21. )
  22. packages = s_cmd.communicate()[0].splitlines()
  23. dockerpy_installed = len(
  24. list(filter(lambda p: p.startswith(b'docker-py=='), packages))
  25. ) > 0
  26. if dockerpy_installed:
  27. from .colors import yellow
  28. print(
  29. yellow('WARNING:'),
  30. "Dependency conflict: an older version of the 'docker-py' package "
  31. "may be polluting the namespace. "
  32. "If you're experiencing crashes, run the following command to remedy the issue:\n"
  33. "pip uninstall docker-py; pip uninstall docker; pip install docker",
  34. file=sys.stderr
  35. )
  36. except OSError:
  37. # pip command is not available, which indicates it's probably the binary
  38. # distribution of Compose which is not affected
  39. pass
  40. except UnicodeDecodeError:
  41. # ref: https://github.com/docker/compose/issues/4663
  42. # This could be caused by a number of things, but it seems to be a
  43. # python 2 + MacOS interaction. It's not ideal to ignore this, but at least
  44. # it doesn't make the program unusable.
  45. pass