Пример #1
0
def _check_modules(modules):
    """Make sure the given modules are available."""
    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://github.com/pallets/jinja/pull/628
            # https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
            # https://github.com/pallets/jinja/issues/646
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            messages = ['invalid escape sequence',
                        'Flags not at the start of the expression']
            with log.ignore_py_warnings(
                    category=DeprecationWarning,
                    message=r'({})'.format('|'.join(messages))
            ), log.ignore_py_warnings(
                    category=PendingDeprecationWarning,
                    module='imp'
            ), log.ignore_py_warnings(
                    category=ImportWarning,
                    message=r'Not importing directory .*: missing __init__'
            ):
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #2
0
def _check_modules(modules):
    """Make sure the given modules are available."""
    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://github.com/pallets/jinja/pull/628
            # https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
            # https://github.com/pallets/jinja/issues/646
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            messages = ['invalid escape sequence',
                        'Flags not at the start of the expression']
            with log.ignore_py_warnings(
                    category=DeprecationWarning,
                    message=r'({})'.format('|'.join(messages))
            ), log.ignore_py_warnings(
                    category=PendingDeprecationWarning,
                    module='imp'
            ), log.ignore_py_warnings(
                    category=ImportWarning,
                    message=r'Not importing directory .*: missing __init__'
            ):
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #3
0
def yaml_load(f):
    """Wrapper over yaml.load using the C loader if possible."""
    start = datetime.datetime.now()

    # WORKAROUND for https://github.com/yaml/pyyaml/pull/181
    with log.ignore_py_warnings(
            category=DeprecationWarning,
            message=r"Using or importing the ABCs from 'collections' instead "
            r"of from 'collections\.abc' is deprecated, and in 3\.8 it will "
            r"stop working"):
        data = yaml.load(f, Loader=YamlLoader)

    end = datetime.datetime.now()

    delta = (end - start).total_seconds()
    deadline = 10 if 'CI' in os.environ else 2
    if delta > deadline:  # pragma: no cover
        log.misc.warning(
            "YAML load took unusually long, please report this at "
            "https://github.com/qutebrowser/qutebrowser/issues/2777\n"
            "duration: {}s\n"
            "PyYAML version: {}\n"
            "C extension: {}\n"
            "Stack:\n\n"
            "{}".format(delta, yaml.__version__, YAML_C_EXT,
                        ''.join(traceback.format_stack())))

    return data
Пример #4
0
def yaml_load(f: typing.Union[str, typing.IO[str]]) -> typing.Any:
    """Wrapper over yaml.load using the C loader if possible."""
    start = datetime.datetime.now()

    # WORKAROUND for https://github.com/yaml/pyyaml/pull/181
    with log.ignore_py_warnings(
            category=DeprecationWarning,
            message=r"Using or importing the ABCs from 'collections' instead "
            r"of from 'collections\.abc' is deprecated.*"):
        try:
            data = yaml.load(f, Loader=YamlLoader)
        except ValueError as e:
            if str(e).startswith('could not convert string to float'):
                # WORKAROUND for https://github.com/yaml/pyyaml/issues/168
                raise yaml.YAMLError(e)
            raise  # pragma: no cover

    end = datetime.datetime.now()

    delta = (end - start).total_seconds()
    deadline = 10 if 'CI' in os.environ else 2
    if delta > deadline:  # pragma: no cover
        log.misc.warning(
            "YAML load took unusually long, please report this at "
            "https://github.com/qutebrowser/qutebrowser/issues/2777\n"
            "duration: {}s\n"
            "PyYAML version: {}\n"
            "C extension: {}\n"
            "Stack:\n\n"
            "{}".format(delta, yaml.__version__, YAML_C_EXT,
                        ''.join(traceback.format_stack())))

    return data
Пример #5
0
def yaml_load(f):
    """Wrapper over yaml.load using the C loader if possible."""
    start = datetime.datetime.now()

    # WORKAROUND for https://github.com/yaml/pyyaml/pull/181
    with log.ignore_py_warnings(
            category=DeprecationWarning,
            message=r"Using or importing the ABCs from 'collections' instead "
            r"of from 'collections\.abc' is deprecated, and in 3\.8 it will "
            r"stop working"):
        data = yaml.load(f, Loader=YamlLoader)

    end = datetime.datetime.now()

    delta = (end - start).total_seconds()
    deadline = 10 if 'CI' in os.environ else 2
    if delta > deadline:  # pragma: no cover
        log.misc.warning(
            "YAML load took unusually long, please report this at "
            "https://github.com/qutebrowser/qutebrowser/issues/2777\n"
            "duration: {}s\n"
            "PyYAML version: {}\n"
            "C extension: {}\n"
            "Stack:\n\n"
            "{}".format(
                delta, yaml.__version__, YAML_C_EXT,
                ''.join(traceback.format_stack())))

    return data
Пример #6
0
def ignore_bs4_warning():
    """WORKAROUND for https://bugs.launchpad.net/beautifulsoup/+bug/1847592."""
    with log.ignore_py_warnings(
            category=DeprecationWarning,
            message="Using or importing the ABCs from 'collections' instead "
            "of from 'collections.abc' is deprecated", module='bs4.element'):
        yield
Пример #7
0
def test_ignore_py_warnings(caplog):
    logging.captureWarnings(True)
    with log.ignore_py_warnings(category=UserWarning):
        warnings.warn("hidden", UserWarning)
    with caplog.at_level(logging.WARNING):
        warnings.warn("not hidden", UserWarning)
    assert len(caplog.records) == 1
    msg = caplog.records[0].message.splitlines()[0]
    assert msg.endswith("UserWarning: not hidden")
Пример #8
0
def _check_modules(modules):
    """Make sure the given modules are available."""
    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            # pylint: disable=bad-continuation
            with log.ignore_py_warnings(
                    category=DeprecationWarning,
                    message=r'invalid escape sequence'
            ), log.ignore_py_warnings(
                    category=ImportWarning,
                    message=r'Not importing directory .*: missing __init__'):
                # pylint: enable=bad-continuation
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #9
0
def test_ignore_py_warnings(caplog):
    logging.captureWarnings(True)
    with log.ignore_py_warnings(category=UserWarning):
        warnings.warn("hidden", UserWarning)
    with caplog.at_level(logging.WARNING):
        warnings.warn("not hidden", UserWarning)
    assert len(caplog.records) == 1
    msg = caplog.records[0].message.splitlines()[0]
    assert msg.endswith("UserWarning: not hidden")
Пример #10
0
def check_libraries(backend):
    """Check if all needed Python libraries are installed."""
    modules = {
        'pkg_resources':
        _missing_str("pkg_resources/setuptools",
                     windows="Run   python -m ensurepip."),
        'pypeg2':
        _missing_str("pypeg2", pip="pypeg2"),
        'jinja2':
        _missing_str("jinja2",
                     windows="Install from http://www.lfd.uci.edu/"
                     "~gohlke/pythonlibs/#jinja2 or via pip.",
                     pip="jinja2"),
        'pygments':
        _missing_str("pygments",
                     windows="Install from http://www.lfd.uci.edu/"
                     "~gohlke/pythonlibs/#pygments or via pip.",
                     pip="pygments"),
        'yaml':
        _missing_str("PyYAML",
                     windows="Use the installers at "
                     "http://pyyaml.org/download/pyyaml/ (py3.4) "
                     "or Install via pip.",
                     pip="PyYAML"),
        'PyQt5.QtQml':
        _missing_str("PyQt5.QtQml"),
        'PyQt5.QtSql':
        _missing_str("PyQt5.QtSql"),
    }
    if backend == 'webengine':
        modules['PyQt5.QtWebEngineWidgets'] = _missing_str("QtWebEngine",
                                                           webengine=True)
        modules['PyQt5.QtOpenGL'] = _missing_str("PyQt5.QtOpenGL")
    else:
        assert backend == 'webkit'
        modules['PyQt5.QtWebKit'] = _missing_str("PyQt5.QtWebKit")
        modules['PyQt5.QtWebKitWidgets'] = _missing_str(
            "PyQt5.QtWebKitWidgets")

    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://github.com/pallets/jinja/pull/628
            # https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
            # https://github.com/pallets/jinja/issues/646
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            messages = [
                'invalid escape sequence',
                'Flags not at the start of the expression'
            ]
            with log.ignore_py_warnings(category=DeprecationWarning,
                                        message=r'({})'.format(
                                            '|'.join(messages))):
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #11
0
def _check_modules(modules):
    """Make sure the given modules are available."""
    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            # pylint: disable=bad-continuation
            with log.ignore_py_warnings(
                category=DeprecationWarning,
                message=r'invalid escape sequence'
            ), log.ignore_py_warnings(
                category=ImportWarning,
                message=r'Not importing directory .*: missing __init__'
            ):
                # pylint: enable=bad-continuation
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #12
0
def check_libraries(backend):
    """Check if all needed Python libraries are installed."""
    modules = {
        'pkg_resources':
            _missing_str("pkg_resources/setuptools",
                         windows="Run   python -m ensurepip."),
        'pypeg2':
            _missing_str("pypeg2",
                         pip="pypeg2"),
        'jinja2':
            _missing_str("jinja2",
                         windows="Install from http://www.lfd.uci.edu/"
                                 "~gohlke/pythonlibs/#jinja2 or via pip.",
                         pip="jinja2"),
        'pygments':
            _missing_str("pygments",
                         windows="Install from http://www.lfd.uci.edu/"
                                 "~gohlke/pythonlibs/#pygments or via pip.",
                         pip="pygments"),
        'yaml':
            _missing_str("PyYAML",
                         windows="Use the installers at "
                                 "http://pyyaml.org/download/pyyaml/ (py3.4) "
                                 "or Install via pip.",
                         pip="PyYAML"),
    }
    if backend == 'webengine':
        modules['PyQt5.QtWebEngineWidgets'] = _missing_str("QtWebEngine",
                                                           webengine=True)
    else:
        assert backend == 'webkit'
        modules['PyQt5.QtWebKit'] = _missing_str("PyQt5.QtWebKit")
        modules['PyQt5.QtWebKitWidgets'] = _missing_str(
            "PyQt5.QtWebKitWidgets")

    from qutebrowser.utils import log

    for name, text in modules.items():
        try:
            # https://github.com/pallets/jinja/pull/628
            # https://bitbucket.org/birkenfeld/pygments-main/issues/1314/
            # https://github.com/pallets/jinja/issues/646
            # https://bitbucket.org/fdik/pypeg/commits/dd15ca462b532019c0a3be1d39b8ee2f3fa32f4e
            messages = ['invalid escape sequence',
                        'Flags not at the start of the expression']
            with log.ignore_py_warnings(
                    category=DeprecationWarning,
                    message=r'({})'.format('|'.join(messages))):
                importlib.import_module(name)
        except ImportError as e:
            _die(text, e)
Пример #13
0
"""


import io
import os
import sys
import operator
import contextlib

from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
                          QIODevice, QSaveFile)
from PyQt5.QtWidgets import QApplication

from qutebrowser.utils import log

with log.ignore_py_warnings(category=PendingDeprecationWarning, module='imp'):
    with log.ignore_py_warnings(category=ImportWarning):
        # This imports 'imp' and gives us a PendingDeprecationWarning on
        # Debian Jessie.
        #
        # On Archlinux, we get ImportWarning from
        # importlib/_bootstrap_external.py for modules with missing __init__.
        import pkg_resources


MAXVALS = {
    'int': 2 ** 31 - 1,
    'int64': 2 ** 63 - 1,
}

MINVALS = {
Пример #14
0
import os
import sys
import operator
import contextlib

from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
                          QIODevice, QSaveFile, QT_VERSION_STR)
from PyQt5.QtWidgets import QApplication
try:
    from PyQt5.QtWebKit import qWebKitVersion
except ImportError:  # pragma: no cover
    qWebKitVersion = None

from qutebrowser.utils import log

with log.ignore_py_warnings(category=PendingDeprecationWarning, module='imp'):
    with log.ignore_py_warnings(category=ImportWarning):
        # This imports 'imp' and gives us a PendingDeprecationWarning on
        # Debian Jessie.
        #
        # On Archlinux, we get ImportWarning from
        # importlib/_bootstrap_external.py for modules with missing __init__.
        import pkg_resources

MAXVALS = {
    'int': 2**31 - 1,
    'int64': 2**63 - 1,
}

MINVALS = {
    'int': -(2**31),