Also check compiled Qt version in version checks

This commit is contained in:
Florian Bruhin 2017-02-28 21:01:47 +01:00
parent 67dfbc7e5f
commit 47a9c8e17c
6 changed files with 69 additions and 41 deletions

View File

@ -200,8 +200,9 @@ def data(readonly=False):
('print-element-backgrounds', ('print-element-backgrounds',
SettingValue(typ.Bool(), 'true', SettingValue(typ.Bool(), 'true',
backends=(None if qtutils.version_check('5.8') backends=(
else [usertypes.Backend.QtWebKit])), None if qtutils.version_check('5.8', strict=True)
else [usertypes.Backend.QtWebKit])),
"Whether the background color and images are also drawn when the " "Whether the background color and images are also drawn when the "
"page is printed.\n" "page is printed.\n"
"This setting only works with Qt 5.8 or newer when using the " "This setting only works with Qt 5.8 or newer when using the "

View File

@ -263,18 +263,19 @@ def get_backend(args):
def check_qt_version(backend): def check_qt_version(backend):
"""Check if the Qt version is recent enough.""" """Check if the Qt version is recent enough."""
from PyQt5.QtCore import qVersion, PYQT_VERSION, PYQT_VERSION_STR from PyQt5.QtCore import qVersion, PYQT_VERSION, PYQT_VERSION_STR
from qutebrowser.utils import qtutils from qutebrowser.utils import qtutils, version
if (qtutils.version_check('5.2.0', operator.lt) or if (qtutils.version_check('5.2.0', operator.lt, strict=True) or
PYQT_VERSION < 0x050200): PYQT_VERSION < 0x050200):
text = ("Fatal error: Qt and PyQt >= 5.2.0 are required, but Qt {} / " text = ("Fatal error: Qt and PyQt >= 5.2.0 are required, but Qt {} / "
"PyQt {} is installed.".format(qVersion(), PYQT_VERSION_STR)) "PyQt {} is installed.".format(version.qt_version(),
PYQT_VERSION_STR))
_die(text) _die(text)
elif (backend == 'webengine' and ( elif (backend == 'webengine' and (
qtutils.version_check('5.7.1', operator.lt) or qtutils.version_check('5.7.1', operator.lt, strict=True) or
PYQT_VERSION < 0x050700)): PYQT_VERSION < 0x050700)):
text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required for " text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required for "
"QtWebEngine support, but Qt {} / PyQt {} is installed." "QtWebEngine support, but Qt {} / PyQt {} is installed."
.format(qVersion(), PYQT_VERSION_STR)) .format(version.qt_version(), PYQT_VERSION_STR))
_die(text) _die(text)

View File

@ -34,7 +34,7 @@ import operator
import contextlib import contextlib
from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray, from PyQt5.QtCore import (qVersion, QEventLoop, QDataStream, QByteArray,
QIODevice, QSaveFile) QIODevice, QSaveFile, QT_VERSION_STR)
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from qutebrowser.utils import log from qutebrowser.utils import log
@ -80,15 +80,19 @@ class QtOSError(OSError):
self.qt_errno = None self.qt_errno = None
def version_check(version, op=operator.ge): def version_check(version, op=operator.ge, strict=False):
"""Check if the Qt runtime version is the version supplied or newer. """Check if the Qt runtime version is the version supplied or newer.
Args: Args:
version: The version to check against. version: The version to check against.
op: The operator to use for the check. op: The operator to use for the check.
strict: If given, also check the compiled Qt version.
""" """
return op(pkg_resources.parse_version(qVersion()), parsed = pkg_resources.parse_version(version)
pkg_resources.parse_version(version)) result = op(pkg_resources.parse_version(qVersion()), parsed)
if result and strict:
result = op(pkg_resources.parse_version(QT_VERSION_STR), parsed)
return result
def is_qtwebkit_ng(version): def is_qtwebkit_ng(version):

View File

@ -225,6 +225,14 @@ def _pdfjs_version():
return '{} ({})'.format(pdfjs_version, file_path) return '{} ({})'.format(pdfjs_version, file_path)
def qt_version():
"""Get a Qt version string based on the runtime/compiled versions."""
if qVersion() != QT_VERSION_STR:
return '{} (compiled {})'.format(qVersion(), QT_VERSION_STR)
else:
return qVersion()
def version(): def version():
"""Return a string with various version informations.""" """Return a string with various version informations."""
lines = ["qutebrowser v{}".format(qutebrowser.__version__)] lines = ["qutebrowser v{}".format(qutebrowser.__version__)]
@ -239,16 +247,11 @@ def version():
backend = 'QtWebKit-NG' backend = 'QtWebKit-NG'
lines.append("Backend: {}".format(backend)) lines.append("Backend: {}".format(backend))
if qVersion() != QT_VERSION_STR:
qt_version = 'Qt: {} (compiled {})'.format(qVersion(), QT_VERSION_STR)
else:
qt_version = 'Qt: {}'.format(qVersion())
lines += [ lines += [
'', '',
'{}: {}'.format(platform.python_implementation(), '{}: {}'.format(platform.python_implementation(),
platform.python_version()), platform.python_version()),
qt_version, 'Qt: {}'.format(qt_version()),
'PyQt: {}'.format(PYQT_VERSION_STR), 'PyQt: {}'.format(PYQT_VERSION_STR),
'', '',
] ]

View File

@ -42,26 +42,36 @@ from qutebrowser.utils import qtutils
import overflow_test_cases import overflow_test_cases
@pytest.mark.parametrize('qversion, version, op, expected', [ @pytest.mark.parametrize('qversion, compiled, version, op, expected', [
('5.4.0', '5.4.0', operator.ge, True), ('5.4.0', None, '5.4.0', operator.ge, True),
('5.4.0', '5.4.0', operator.eq, True), ('5.4.0', None, '5.4.0', operator.eq, True),
('5.4.0', '5.4', operator.eq, True), ('5.4.0', None, '5.4', operator.eq, True),
('5.4.1', '5.4', operator.ge, True), ('5.4.1', None, '5.4', operator.ge, True),
('5.3.2', '5.4', operator.ge, False), ('5.3.2', None, '5.4', operator.ge, False),
('5.3.0', '5.3.2', operator.ge, False), ('5.3.0', None, '5.3.2', operator.ge, False),
# strict=True
('5.4.0', '5.3.0', '5.4.0', operator.ge, False),
('5.4.0', '5.4.0', '5.4.0', operator.ge, True),
]) ])
def test_version_check(monkeypatch, qversion, version, op, expected): def test_version_check(monkeypatch, qversion, compiled, version, op, expected):
"""Test for version_check(). """Test for version_check().
Args: Args:
monkeypatch: The pytest monkeypatch fixture. monkeypatch: The pytest monkeypatch fixture.
qversion: The version to set as fake qVersion(). qversion: The version to set as fake qVersion().
compiled: The value for QT_VERSION_STR (set strict=True)
version: The version to compare with. version: The version to compare with.
op: The operator to use when comparing. op: The operator to use when comparing.
expected: The expected result. expected: The expected result.
""" """
monkeypatch.setattr('qutebrowser.utils.qtutils.qVersion', lambda: qversion) monkeypatch.setattr('qutebrowser.utils.qtutils.qVersion', lambda: qversion)
assert qtutils.version_check(version, op) == expected if compiled is not None:
monkeypatch.setattr('qutebrowser.utils.qtutils.QT_VERSION_STR', compiled)
strict = True
else:
strict = False
assert qtutils.version_check(version, op, strict=strict) == expected
@pytest.mark.parametrize('version, ng', [ @pytest.mark.parametrize('version, ng', [

View File

@ -638,18 +638,29 @@ class FakeQSslSocket:
return self._version return self._version
@pytest.mark.parametrize(['git_commit', 'frozen', 'style', @pytest.mark.parametrize('same', [True, False])
'equal_qt', 'with_webkit'], [ def test_qt_version(monkeypatch, same):
(True, False, True, True, True), # normal if same:
(False, False, True, True, True), # no git commit qt_version_str = '5.4.0'
(True, True, True, True, True), # frozen expected = '5.4.0'
(True, True, False, True, True), # no style else:
(True, False, True, False, True), # different Qt qt_version_str = '5.3.0'
(True, False, True, True, False), # no webkit expected = '5.4.0 (compiled 5.3.0)'
(True, False, True, True, 'ng'), # QtWebKit-NG monkeypatch.setattr(version, 'qVersion', lambda: '5.4.0')
monkeypatch.setattr(version, 'QT_VERSION_STR', qt_version_str)
assert version.qt_version() == expected
@pytest.mark.parametrize(['git_commit', 'frozen', 'style', 'with_webkit'], [
(True, False, True, True), # normal
(False, False, True, True), # no git commit
(True, True, True, True), # frozen
(True, True, False, True), # no style
(True, False, True, False), # no webkit
(True, False, True, 'ng'), # QtWebKit-NG
]) ])
def test_version_output(git_commit, frozen, style, equal_qt, with_webkit, def test_version_output(git_commit, frozen, style, with_webkit, stubs,
stubs, monkeypatch): monkeypatch):
"""Test version.version().""" """Test version.version()."""
import_path = os.path.abspath('/IMPORTPATH') import_path = os.path.abspath('/IMPORTPATH')
patches = { patches = {
@ -660,8 +671,7 @@ def test_version_output(git_commit, frozen, style, equal_qt, with_webkit,
'platform.python_version': lambda: 'PYTHON VERSION', 'platform.python_version': lambda: 'PYTHON VERSION',
'PYQT_VERSION_STR': 'PYQT VERSION', 'PYQT_VERSION_STR': 'PYQT VERSION',
'QT_VERSION_STR': 'QT VERSION', 'QT_VERSION_STR': 'QT VERSION',
'qVersion': (lambda: 'qVersion': lambda: 'QT VERSION',
'QT VERSION' if equal_qt else 'QT RUNTIME VERSION'),
'_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'], '_module_versions': lambda: ['MODULE VERSION 1', 'MODULE VERSION 2'],
'_pdfjs_version': lambda: 'PDFJS VERSION', '_pdfjs_version': lambda: 'PDFJS VERSION',
'qWebKitVersion': (lambda: 'WEBKIT VERSION') if with_webkit else None, 'qWebKitVersion': (lambda: 'WEBKIT VERSION') if with_webkit else None,
@ -715,8 +725,7 @@ def test_version_output(git_commit, frozen, style, equal_qt, with_webkit,
substitutions = { substitutions = {
'git_commit': '\nGit commit: GIT COMMIT' if git_commit else '', 'git_commit': '\nGit commit: GIT COMMIT' if git_commit else '',
'style': '\nStyle: STYLE' if style else '', 'style': '\nStyle: STYLE' if style else '',
'qt': ('QT VERSION' if equal_qt else 'qt': 'QT VERSION',
'QT RUNTIME VERSION (compiled QT VERSION)'),
'frozen': str(frozen), 'frozen': str(frozen),
'import_path': import_path, 'import_path': import_path,
'webkit': 'WEBKIT VERSION' if with_webkit else 'no', 'webkit': 'WEBKIT VERSION' if with_webkit else 'no',