Make qtutils.version_check strict by default

This also renames 'strict' to 'compiled' to be more descriptive.
It also fixes a crash when starting qutebrowser with an older compiled Qt
version which was introduced recently (calling setSpellCheckEnabled).
This commit is contained in:
Florian Bruhin 2017-10-08 19:08:37 +02:00
parent 13b7647443
commit 6c3f90146f
10 changed files with 21 additions and 20 deletions

View File

@ -150,7 +150,7 @@ def _get_suggested_filename(path):
"""
filename = os.path.basename(path)
filename = re.sub(r'\([0-9]+\)(?=\.|$)', '', filename)
if not qtutils.version_check('5.9'):
if not qtutils.version_check('5.9', compiled=False):
# https://bugreports.qt.io/browse/QTBUG-58155
filename = urllib.parse.unquote(filename)
# Doing basename a *second* time because there could be a %2F in

View File

@ -240,7 +240,7 @@ def init(args):
# We need to do this here as a WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-58650
if not qtutils.version_check('5.9'):
if not qtutils.version_check('5.9', compiled=False):
PersistentCookiePolicy().set(config.val.content.cookies.store)
Attribute(QWebEngineSettings.FullScreenSupportEnabled).set(True)
@ -340,6 +340,6 @@ if qtutils.version_check('5.8'):
MAPPINGS['spellcheck.languages'] = DictionaryLanguageSetter()
if qtutils.version_check('5.9'):
if qtutils.version_check('5.9', compiled=False):
# https://bugreports.qt.io/browse/QTBUG-58650
MAPPINGS['content.cookies.store'] = PersistentCookiePolicy()

View File

@ -412,7 +412,7 @@ class WebEngineHistory(browsertab.AbstractHistory):
return self._history.goToItem(item)
def serialize(self):
if not qtutils.version_check('5.9'):
if not qtutils.version_check('5.9', compiled=False):
# WORKAROUND for
# https://github.com/qutebrowser/qutebrowser/issues/2289
# Don't use the history's currentItem here, because of
@ -602,7 +602,7 @@ class WebEngineTab(browsertab.AbstractTab):
def shutdown(self):
self.shutting_down.emit()
self.action.exit_fullscreen()
if qtutils.version_check('5.8', exact=True):
if qtutils.version_check('5.8', exact=True, compiled=False):
# WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-58563
self.search.clear()
@ -728,8 +728,8 @@ class WebEngineTab(browsertab.AbstractTab):
@pyqtSlot()
def _on_load_started(self):
"""Clear search when a new load is started if needed."""
if (qtutils.version_check('5.9') and
not qtutils.version_check('5.9.2')):
if (qtutils.version_check('5.9', compiled=False) and
not qtutils.version_check('5.9.2', compiled=False)):
# WORKAROUND for
# https://bugreports.qt.io/browse/QTBUG-61506
self.search.clear()

View File

@ -49,6 +49,6 @@ class DiskCache(QNetworkDiskCache):
if size is None:
size = 1024 * 1024 * 50 # default from QNetworkDiskCachePrivate
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-59909
if not qtutils.version_check('5.9'): # pragma: no cover
size = 0
if not qtutils.version_check('5.9', compiled=False):
size = 0 # pragma: no cover
self.setMaximumCacheSize(size)

View File

@ -720,7 +720,7 @@ class TabbedBrowser(tabwidget.TabWidget):
tab.set_html(html)
log.webview.error(msg)
if qtutils.version_check('5.9'):
if qtutils.version_check('5.9', compiled=False):
url_string = tab.url(requested=True).toDisplayString()
error_page = jinja.render(
'error.html', title="Error loading {}".format(url_string),

View File

@ -170,8 +170,7 @@ def check_qt_version():
"""Check if the Qt version is recent enough."""
from PyQt5.QtCore import PYQT_VERSION, PYQT_VERSION_STR
from qutebrowser.utils import qtutils
if (not qtutils.version_check('5.7.1', strict=True) or
PYQT_VERSION < 0x050200):
if not qtutils.version_check('5.7.1') or PYQT_VERSION < 0x050200:
text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required, "
"but Qt {} / PyQt {} is installed.".format(qt_version(),
PYQT_VERSION_STR))

View File

@ -260,7 +260,7 @@ class WrapperLayout(QLayout):
self._widget = widget
container.setFocusProxy(widget)
widget.setParent(container)
if (qtutils.version_check('5.8.0', exact=True) and
if (qtutils.version_check('5.8.0', exact=True, compiled=False) and
objects.backend == usertypes.Backend.QtWebEngine and
container.window() and
container.window().windowHandle() and

View File

@ -71,13 +71,13 @@ class QtOSError(OSError):
self.qt_errno = None
def version_check(version, exact=False, strict=False):
def version_check(version, exact=False, compiled=True):
"""Check if the Qt runtime version is the version supplied or newer.
Args:
version: The version to check against.
exact: if given, check with == instead of >=
strict: If given, also check the compiled Qt version.
compiled: Set to False to not check the compiled version.
"""
# Catch code using the old API for this
assert exact not in [operator.gt, operator.lt, operator.ge, operator.le,
@ -85,7 +85,7 @@ def version_check(version, exact=False, strict=False):
parsed = pkg_resources.parse_version(version)
op = operator.eq if exact else operator.ge
result = op(pkg_resources.parse_version(qVersion()), parsed)
if strict and result:
if compiled and result:
# v1 ==/>= parsed, now check if v2 ==/>= parsed too.
result = op(pkg_resources.parse_version(QT_VERSION_STR), parsed)
return result

View File

@ -26,7 +26,8 @@ from qutebrowser.utils import qtutils
pytestmark = pytest.mark.skipif(
qtutils.version_check('5.7.1') and not qtutils.version_check('5.9'),
qtutils.version_check('5.7.1', compiled=False) and
not qtutils.version_check('5.9', compiled=False),
reason="QNetworkDiskCache is broken on Qt 5.7.1 and 5.8")

View File

@ -74,11 +74,12 @@ def test_version_check(monkeypatch, qversion, compiled, version, exact,
monkeypatch.setattr(qtutils, 'qVersion', lambda: qversion)
if compiled is not None:
monkeypatch.setattr(qtutils, 'QT_VERSION_STR', compiled)
strict = True
compiled_arg = True
else:
strict = False
compiled_arg = False
assert qtutils.version_check(version, exact, strict=strict) == expected
actual = qtutils.version_check(version, exact, compiled=compiled_arg)
assert actual == expected
@pytest.mark.parametrize('version, is_new', [