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.

main.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Primary application entrypoint.
  2. """
  3. # The following comment should be removed at some point in the future.
  4. # mypy: disallow-untyped-defs=False
  5. from __future__ import absolute_import
  6. import locale
  7. import logging
  8. import os
  9. import sys
  10. from pip._internal.cli.autocompletion import autocomplete
  11. from pip._internal.cli.main_parser import parse_command
  12. from pip._internal.commands import create_command
  13. from pip._internal.exceptions import PipError
  14. from pip._internal.utils import deprecation
  15. logger = logging.getLogger(__name__)
  16. def main(args=None):
  17. if args is None:
  18. args = sys.argv[1:]
  19. # Configure our deprecation warnings to be sent through loggers
  20. deprecation.install_warning_logger()
  21. autocomplete()
  22. try:
  23. cmd_name, cmd_args = parse_command(args)
  24. except PipError as exc:
  25. sys.stderr.write("ERROR: %s" % exc)
  26. sys.stderr.write(os.linesep)
  27. sys.exit(1)
  28. # Needed for locale.getpreferredencoding(False) to work
  29. # in pip._internal.utils.encoding.auto_decode
  30. try:
  31. locale.setlocale(locale.LC_ALL, '')
  32. except locale.Error as e:
  33. # setlocale can apparently crash if locale are uninitialized
  34. logger.debug("Ignoring error %s when setting locale", e)
  35. command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  36. return command.main(cmd_args)