未验证 提交 aabf71bd 编写于 作者: P Paul Moore 提交者: GitHub

Merge pull request #4985 from anubhavp28/master

Updated get_terminal_size to check for shutil.get_terminal_size first.
Terminal size is now correctly inferred when using Python 3 on Windows.
...@@ -9,8 +9,8 @@ from distutils.util import strtobool ...@@ -9,8 +9,8 @@ from distutils.util import strtobool
from pip._vendor.six import string_types from pip._vendor.six import string_types
from pip._internal.compat import get_terminal_size
from pip._internal.configuration import Configuration, ConfigurationError from pip._internal.configuration import Configuration, ConfigurationError
from pip._internal.utils.misc import get_terminal_size
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -12,12 +12,12 @@ from pip._vendor.packaging.version import parse as parse_version ...@@ -12,12 +12,12 @@ from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.six.moves import xmlrpc_client # type: ignore from pip._vendor.six.moves import xmlrpc_client # type: ignore
from pip._internal.basecommand import SUCCESS, Command from pip._internal.basecommand import SUCCESS, Command
from pip._internal.compat import get_terminal_size
from pip._internal.download import PipXmlrpcTransport from pip._internal.download import PipXmlrpcTransport
from pip._internal.exceptions import CommandError from pip._internal.exceptions import CommandError
from pip._internal.models import PyPI from pip._internal.models import PyPI
from pip._internal.status_codes import NO_MATCHES_FOUND from pip._internal.status_codes import NO_MATCHES_FOUND
from pip._internal.utils.logging import indent_log from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import get_terminal_size
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -6,6 +6,7 @@ import codecs ...@@ -6,6 +6,7 @@ import codecs
import locale import locale
import logging import logging
import os import os
import shutil
import sys import sys
from pip._vendor.six import text_type from pip._vendor.six import text_type
...@@ -23,7 +24,7 @@ except ImportError: ...@@ -23,7 +24,7 @@ except ImportError:
__all__ = [ __all__ = [
"ipaddress", "uses_pycache", "console_to_str", "native_str", "ipaddress", "uses_pycache", "console_to_str", "native_str",
"get_path_uid", "stdlib_pkgs", "WINDOWS", "samefile", "get_path_uid", "stdlib_pkgs", "WINDOWS", "samefile", "get_terminal_size",
] ]
...@@ -192,3 +193,43 @@ def samefile(file1, file2): ...@@ -192,3 +193,43 @@ def samefile(file1, file2):
path1 = os.path.normcase(os.path.abspath(file1)) path1 = os.path.normcase(os.path.abspath(file1))
path2 = os.path.normcase(os.path.abspath(file2)) path2 = os.path.normcase(os.path.abspath(file2))
return path1 == path2 return path1 == path2
if hasattr(shutil, 'get_terminal_size'):
def get_terminal_size():
"""
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())
else:
def get_terminal_size():
"""
Returns a tuple (x, y) representing the width(x) and the height(y)
in characters of the terminal window.
"""
def ioctl_GWINSZ(fd):
try:
import fcntl
import termios
import struct
cr = struct.unpack(
'hh',
fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')
)
except:
return None
if cr == (0, 0):
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
return int(cr[1]), int(cr[0])
...@@ -43,7 +43,7 @@ __all__ = ['rmtree', 'display_path', 'backup_dir', ...@@ -43,7 +43,7 @@ __all__ = ['rmtree', 'display_path', 'backup_dir',
'is_svn_page', 'file_contents', 'is_svn_page', 'file_contents',
'split_leading_dir', 'has_leading_dir', 'split_leading_dir', 'has_leading_dir',
'normalize_path', 'normalize_path',
'renames', 'get_terminal_size', 'get_prog', 'renames', 'get_prog',
'unzip_file', 'untar_file', 'unpack_file', 'call_subprocess', 'unzip_file', 'untar_file', 'unpack_file', 'call_subprocess',
'captured_stdout', 'ensure_dir', 'captured_stdout', 'ensure_dir',
'ARCHIVE_EXTENSIONS', 'SUPPORTED_EXTENSIONS', 'ARCHIVE_EXTENSIONS', 'SUPPORTED_EXTENSIONS',
...@@ -438,36 +438,6 @@ def dist_location(dist): ...@@ -438,36 +438,6 @@ def dist_location(dist):
return dist.location return dist.location
def get_terminal_size():
"""Returns a tuple (x, y) representing the width(x) and the height(x)
in characters of the terminal window."""
def ioctl_GWINSZ(fd):
try:
import fcntl
import termios
import struct
cr = struct.unpack(
'hh',
fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')
)
except:
return None
if cr == (0, 0):
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
return int(cr[1]), int(cr[0])
def current_umask(): def current_umask():
"""Get the current umask which involves having to set it temporarily.""" """Get the current umask which involves having to set it temporarily."""
mask = os.umask(0) mask = os.umask(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册