comparison lib/python3.8/site-packages/pip/_internal/cli/main.py @ 0:9e54283cc701 draft

"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author guerler
date Mon, 27 Jul 2020 03:47:31 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9e54283cc701
1 """Primary application entrypoint.
2 """
3 from __future__ import absolute_import
4
5 import locale
6 import logging
7 import os
8 import sys
9
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 from pip._internal.utils.typing import MYPY_CHECK_RUNNING
16
17 if MYPY_CHECK_RUNNING:
18 from typing import List, Optional
19
20 logger = logging.getLogger(__name__)
21
22
23 # Do not import and use main() directly! Using it directly is actively
24 # discouraged by pip's maintainers. The name, location and behavior of
25 # this function is subject to change, so calling it directly is not
26 # portable across different pip versions.
27
28 # In addition, running pip in-process is unsupported and unsafe. This is
29 # elaborated in detail at
30 # https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
31 # That document also provides suggestions that should work for nearly
32 # all users that are considering importing and using main() directly.
33
34 # However, we know that certain users will still want to invoke pip
35 # in-process. If you understand and accept the implications of using pip
36 # in an unsupported manner, the best approach is to use runpy to avoid
37 # depending on the exact location of this entry point.
38
39 # The following example shows how to use runpy to invoke pip in that
40 # case:
41 #
42 # sys.argv = ["pip", your, args, here]
43 # runpy.run_module("pip", run_name="__main__")
44 #
45 # Note that this will exit the process after running, unlike a direct
46 # call to main. As it is not safe to do any processing after calling
47 # main, this should not be an issue in practice.
48
49 def main(args=None):
50 # type: (Optional[List[str]]) -> int
51 if args is None:
52 args = sys.argv[1:]
53
54 # Configure our deprecation warnings to be sent through loggers
55 deprecation.install_warning_logger()
56
57 autocomplete()
58
59 try:
60 cmd_name, cmd_args = parse_command(args)
61 except PipError as exc:
62 sys.stderr.write("ERROR: %s" % exc)
63 sys.stderr.write(os.linesep)
64 sys.exit(1)
65
66 # Needed for locale.getpreferredencoding(False) to work
67 # in pip._internal.utils.encoding.auto_decode
68 try:
69 locale.setlocale(locale.LC_ALL, '')
70 except locale.Error as e:
71 # setlocale can apparently crash if locale are uninitialized
72 logger.debug("Ignoring error %s when setting locale", e)
73 command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
74
75 return command.main(cmd_args)