-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
pip._internal:main
to its own module
Moving content out of `__init__` is preferred in general because it avoids conflicts with module names and unnecessary imports.
- Loading branch information
Showing
6 changed files
with
51 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Primary application entrypoint. | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import locale | ||
import logging | ||
import os | ||
import sys | ||
|
||
from pip._internal.cli.autocompletion import autocomplete | ||
from pip._internal.cli.main_parser import parse_command | ||
from pip._internal.commands import create_command | ||
from pip._internal.exceptions import PipError | ||
from pip._internal.utils import deprecation | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def main(args=None): | ||
if args is None: | ||
args = sys.argv[1:] | ||
|
||
# Configure our deprecation warnings to be sent through loggers | ||
deprecation.install_warning_logger() | ||
|
||
autocomplete() | ||
|
||
try: | ||
cmd_name, cmd_args = parse_command(args) | ||
except PipError as exc: | ||
sys.stderr.write("ERROR: %s" % exc) | ||
sys.stderr.write(os.linesep) | ||
sys.exit(1) | ||
|
||
# Needed for locale.getpreferredencoding(False) to work | ||
# in pip._internal.utils.encoding.auto_decode | ||
try: | ||
locale.setlocale(locale.LC_ALL, '') | ||
except locale.Error as e: | ||
# setlocale can apparently crash if locale are uninitialized | ||
logger.debug("Ignoring error %s when setting locale", e) | ||
command = create_command(cmd_name, isolated=("--isolated" in cmd_args)) | ||
|
||
return command.main(cmd_args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
09fd200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, this breaks
ensurepip
on current 3.6, 3.7, and 3.8. Affects those who patch in new wheels when building/packaging, and whomever from pip does the hand-off to cpython next per 9c0a1da. Also, be aware of the possibilities of https://bugs.python.org/issue36608.09fd200
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. In python/cpython#16782 @pradyunsg left a comment suggesting we switch to runpy in ensurepip, which would help avoid this kind of breakage going forward and should avoid issues related to that bpo.