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