]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/cli/main.py
1 """Primary application entrypoint.
8 from typing
import List
, Optional
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
16 logger
= logging
.getLogger(__name__
)
19 # Do not import and use main() directly! Using it directly is actively
20 # discouraged by pip's maintainers. The name, location and behavior of
21 # this function is subject to change, so calling it directly is not
22 # portable across different pip versions.
24 # In addition, running pip in-process is unsupported and unsafe. This is
25 # elaborated in detail at
26 # https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
27 # That document also provides suggestions that should work for nearly
28 # all users that are considering importing and using main() directly.
30 # However, we know that certain users will still want to invoke pip
31 # in-process. If you understand and accept the implications of using pip
32 # in an unsupported manner, the best approach is to use runpy to avoid
33 # depending on the exact location of this entry point.
35 # The following example shows how to use runpy to invoke pip in that
38 # sys.argv = ["pip", your, args, here]
39 # runpy.run_module("pip", run_name="__main__")
41 # Note that this will exit the process after running, unlike a direct
42 # call to main. As it is not safe to do any processing after calling
43 # main, this should not be an issue in practice.
46 def main(args
: Optional
[List
[str]] = None) -> int:
50 # Suppress the pkg_resources deprecation warning
51 # Note - we use a module of .*pkg_resources to cover
52 # the normal case (pip._vendor.pkg_resources) and the
53 # devendored case (a bare pkg_resources)
54 warnings
.filterwarnings(
55 action
="ignore", category
=DeprecationWarning, module
=".*pkg_resources"
58 # Configure our deprecation warnings to be sent through loggers
59 deprecation
.install_warning_logger()
64 cmd_name
, cmd_args
= parse_command(args
)
65 except PipError
as exc
:
66 sys
.stderr
.write(f
"ERROR: {exc}")
67 sys
.stderr
.write(os
.linesep
)
70 # Needed for locale.getpreferredencoding(False) to work
71 # in pip._internal.utils.encoding.auto_decode
73 locale
.setlocale(locale
.LC_ALL
, "")
74 except locale
.Error
as e
:
75 # setlocale can apparently crash if locale are uninitialized
76 logger
.debug("Ignoring error %s when setting locale", e
)
77 command
= create_command(cmd_name
, isolated
=("--isolated" in cmd_args
))
79 return command
.main(cmd_args
)