Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code out of pip._internal.__init__ #7061

Merged
merged 3 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def find_version(*file_paths):
},
entry_points={
"console_scripts": [
"pip=pip._internal:main",
"pip%s=pip._internal:main" % sys.version_info[:1],
"pip%s.%s=pip._internal:main" % sys.version_info[:2],
"pip=pip._internal.main:main",
"pip%s=pip._internal.main:main" % sys.version_info[:1],
"pip%s.%s=pip._internal.main:main" % sys.version_info[:2],
],
},

Expand Down
2 changes: 1 addition & 1 deletion src/pip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

from pip._internal import main as _main # isort:skip # noqa
from pip._internal.main import main as _main # isort:skip # noqa

if __name__ == '__main__':
sys.exit(_main())
39 changes: 0 additions & 39 deletions src/pip/_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/usr/bin/env python
from __future__ import absolute_import

import locale
import logging
import os
import sys
import warnings

# We ignore certain warnings from urllib3, since they are not relevant to pip's
Expand All @@ -15,45 +11,10 @@
)

import pip._internal.utils.inject_securetransport # noqa
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

# Raised when using --trusted-host.
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
# Raised since socks support depends on PySocks, which may not be installed.
# Barry Warsaw noted (on 2016-06-17) that this should be done before
# importing pip.vcs, which has since moved to pip._internal.vcs.
warnings.filterwarnings("ignore", category=DependencyWarning)

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)
44 changes: 44 additions & 0 deletions src/pip/_internal/main.py
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)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import six
from setuptools.wheel import Wheel

import pip._internal
from pip._internal.main import main as pip_entry_point
from tests.lib import DATA_DIR, SRC_DIR, TestData
from tests.lib.path import Path
from tests.lib.scripttest import PipTestEnvironment
Expand Down Expand Up @@ -342,7 +342,7 @@ def pip(self, *args):
stdout = io.BytesIO()
sys.stdout = stdout
try:
returncode = pip._internal.main(list(args))
returncode = pip_entry_point(list(args))
except SystemExit as e:
returncode = e.code or 0
finally:
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def setup_completion(script, words, cword, cwd=None):

# expect_error is True because autocomplete exists with 1 status code
result = script.run(
'python', '-c', 'import pip._internal;pip._internal.autocomplete()',
'python', '-c',
'from pip._internal.cli.autocompletion import autocomplete;'
'autocomplete()',
expect_error=True,
cwd=cwd,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import pytest

import pip._internal.configuration
from pip._internal import main
from pip._internal.commands import create_command
from pip._internal.exceptions import PipError
from pip._internal.main import main
from tests.lib.options_helpers import AddFakeCommandMixin


Expand Down