<commit_before>import sys

from array      import array
from contextlib import contextmanager
from inspect    import getmembers
from pkgutil    import iter_modules


__all__ = ['get_terminal_size',
           'import_dotted_name',
           'deep_iter_modules',
           'deep_get_members',
           'parse_options',
           'nested',
          ]


def get_terminal_size(default=(80, 24)):
    """Try to get the size of the terminal as a tuple ``(width, height)``
    falling back on `default`.

    .. versionadded:: 0.6

    """
    try:
        import fcntl, termios
    except ImportError:
        return default
    ary = array('h', fcntl.ioctl(sys.stdin, termios.TIOCGWINSZ, chr(0) * 8))
    return ary[1], ary[0]


def import_dotted_name(name):
    """Get an object by its "dotted name", a string representing its import<commit_msg>Fix bug in utils.get_terminal_size when not run in a terminal<commit_after>import sys

from array      import array
from contextlib import contextmanager
from inspect    import getmembers
from pkgutil    import iter_modules


__all__ = ['get_terminal_size',
           'import_dotted_name',
           'deep_iter_modules',
           'deep_get_members',
           'parse_options',
           'nested',
          ]


def get_terminal_size(default=(80, 24)):
    """Try to get the size of the terminal as a tuple ``(width, height)``
    falling back on `default`.

    .. versionadded:: 0.6

    """
    try:
        import fcntl, termios
    except ImportError:
        return default
    try:
        ary = array('h', fcntl.fcntl(sys.stdin, termios.TIOCGWINSZ, chr(0) * 8))
        return ary[1], ary[0]
    except IOError:
        return default


def import_dotted_name(name):
    """Get an object by its "dotted name", a string representing its import
{'fraction_non_alphanumeric': 0.09600443951165372, 'fraction_numerical': 0.011098779134295227, 'mean_word_length': 2.6497975708502026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6837286', 'n_tokens_mistral': 569, 'n_tokens_neox': 537, 'n_words': 169}