You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. from __future__ import absolute_import
  3. import locale
  4. import logging
  5. import os
  6. import warnings
  7. import sys
  8. # 2016-06-17 barry@debian.org: urllib3 1.14 added optional support for socks,
  9. # but if invoked (i.e. imported), it will issue a warning to stderr if socks
  10. # isn't available. requests unconditionally imports urllib3's socks contrib
  11. # module, triggering this warning. The warning breaks DEP-8 tests (because of
  12. # the stderr output) and is just plain annoying in normal usage. I don't want
  13. # to add socks as yet another dependency for pip, nor do I want to allow-stder
  14. # in the DEP-8 tests, so just suppress the warning. pdb tells me this has to
  15. # be done before the import of pip.vcs.
  16. from pip._vendor.urllib3.exceptions import DependencyWarning
  17. warnings.filterwarnings("ignore", category=DependencyWarning) # noqa
  18. # We want to inject the use of SecureTransport as early as possible so that any
  19. # references or sessions or what have you are ensured to have it, however we
  20. # only want to do this in the case that we're running on macOS and the linked
  21. # OpenSSL is too old to handle TLSv1.2
  22. try:
  23. import ssl
  24. except ImportError:
  25. pass
  26. else:
  27. # Checks for OpenSSL 1.0.1 on MacOS
  28. if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
  29. try:
  30. from pip._vendor.urllib3.contrib import securetransport
  31. except (ImportError, OSError):
  32. pass
  33. else:
  34. securetransport.inject_into_urllib3()
  35. from pip._internal.cli.autocompletion import autocomplete
  36. from pip._internal.cli.main_parser import parse_command
  37. from pip._internal.commands import commands_dict
  38. from pip._internal.exceptions import PipError
  39. from pip._internal.utils import deprecation
  40. from pip._internal.vcs import git, mercurial, subversion, bazaar # noqa
  41. from pip._vendor.urllib3.exceptions import InsecureRequestWarning
  42. logger = logging.getLogger(__name__)
  43. # Hide the InsecureRequestWarning from urllib3
  44. warnings.filterwarnings("ignore", category=InsecureRequestWarning)
  45. def main(args=None):
  46. if args is None:
  47. args = sys.argv[1:]
  48. # Configure our deprecation warnings to be sent through loggers
  49. deprecation.install_warning_logger()
  50. autocomplete()
  51. try:
  52. cmd_name, cmd_args = parse_command(args)
  53. except PipError as exc:
  54. sys.stderr.write("ERROR: %s" % exc)
  55. sys.stderr.write(os.linesep)
  56. sys.exit(1)
  57. # Needed for locale.getpreferredencoding(False) to work
  58. # in pip._internal.utils.encoding.auto_decode
  59. try:
  60. locale.setlocale(locale.LC_ALL, '')
  61. except locale.Error as e:
  62. # setlocale can apparently crash if locale are uninitialized
  63. logger.debug("Ignoring error %s when setting locale", e)
  64. command = commands_dict[cmd_name](isolated=("--isolated" in cmd_args))
  65. return command.main(cmd_args)