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