diff --git a/src/pip/_internal/cli/parser.py b/src/pip/_internal/cli/parser.py index 5bacd47a1d3..b64e967806c 100644 --- a/src/pip/_internal/cli/parser.py +++ b/src/pip/_internal/cli/parser.py @@ -7,6 +7,7 @@ import logging import optparse +import shutil import sys import textwrap from distutils.util import strtobool @@ -15,7 +16,6 @@ from pip._internal.cli.status_codes import UNKNOWN_ERROR from pip._internal.configuration import Configuration, ConfigurationError -from pip._internal.utils.compat import get_terminal_size from pip._internal.utils.misc import redact_auth_from_url logger = logging.getLogger(__name__) @@ -28,7 +28,7 @@ def __init__(self, *args, **kwargs): # help position must be aligned with __init__.parseopts.description kwargs['max_help_position'] = 30 kwargs['indent_increment'] = 1 - kwargs['width'] = get_terminal_size()[0] - 2 + kwargs['width'] = shutil.get_terminal_size()[0] - 2 optparse.IndentedHelpFormatter.__init__(self, *args, **kwargs) def format_option_strings(self, option): diff --git a/src/pip/_internal/commands/search.py b/src/pip/_internal/commands/search.py index 146d653e55f..f382ddc6516 100644 --- a/src/pip/_internal/commands/search.py +++ b/src/pip/_internal/commands/search.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import logging +import shutil import sys import textwrap from collections import OrderedDict @@ -18,7 +19,6 @@ from pip._internal.exceptions import CommandError from pip._internal.models.index import PyPI from pip._internal.network.xmlrpc import PipXmlrpcTransport -from pip._internal.utils.compat import get_terminal_size from pip._internal.utils.logging import indent_log from pip._internal.utils.misc import get_distribution, write_output from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -64,7 +64,7 @@ def run(self, options, args): terminal_width = None if sys.stdout.isatty(): - terminal_width = get_terminal_size()[0] + terminal_width = shutil.get_terminal_size()[0] print_results(hits, terminal_width=terminal_width) if pypi_hits: diff --git a/src/pip/_internal/utils/compat.py b/src/pip/_internal/utils/compat.py index 0115c307db8..e6ddbcb5f8e 100644 --- a/src/pip/_internal/utils/compat.py +++ b/src/pip/_internal/utils/compat.py @@ -11,13 +11,12 @@ import locale import logging import os -import shutil import sys from pip._internal.utils.typing import MYPY_CHECK_RUNNING if MYPY_CHECK_RUNNING: - from typing import Callable, Optional, Protocol, Text, Tuple, TypeVar, Union + from typing import Callable, Optional, Protocol, Text, TypeVar, Union # Used in the @lru_cache polyfill. F = TypeVar('F') @@ -40,7 +39,7 @@ def __call__(self, maxsize=None): __all__ = [ "ipaddress", "console_to_str", - "get_path_uid", "stdlib_pkgs", "WINDOWS", "get_terminal_size", + "get_path_uid", "stdlib_pkgs", "WINDOWS", ] @@ -190,15 +189,6 @@ def expanduser(path): (sys.platform == 'cli' and os.name == 'nt')) -def get_terminal_size(): - # type: () -> Tuple[int, int] - """ - Returns a tuple (x, y) representing the width(x) and the height(y) - in characters of the terminal window. - """ - return tuple(shutil.get_terminal_size()) # type: ignore - - # Fallback to noop_lru_cache in Python 2 # TODO: this can be removed when python 2 support is dropped! def noop_lru_cache(maxsize=None):