Skip to content

Commit

Permalink
Replace compat shim with shutil.get_terminal_size()
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 22, 2020
1 parent 9db9754 commit add5cfa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging
import optparse
import shutil
import sys
import textwrap
from distutils.util import strtobool
Expand All @@ -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__)
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/commands/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import logging
import shutil
import sys
import textwrap
from collections import OrderedDict
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 2 additions & 12 deletions src/pip/_internal/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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",
]


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit add5cfa

Please sign in to comment.