Move version.qt_version() to earlyinit
Importing version in earlyinit is a bad idea, as it already pulls in a lot of stuff we don't want.
This commit is contained in:
parent
a5db21abe9
commit
fdba676933
@ -253,6 +253,21 @@ def get_backend(args):
|
||||
return 'webengine'
|
||||
|
||||
|
||||
def qt_version(qversion=None, qt_version=None):
|
||||
"""Get a Qt version string based on the runtime/compiled versions."""
|
||||
if qversion is None:
|
||||
from PyQt5.QtCore import qVersion
|
||||
qversion = qVersion()
|
||||
if qt_version is None:
|
||||
from PyQt5.QtCore import QT_VERSION_STR
|
||||
qt_version = QT_VERSION_STR
|
||||
|
||||
if qversion != qt_version:
|
||||
return '{} (compiled {})'.format(qversion, qt_version)
|
||||
else:
|
||||
return qversion
|
||||
|
||||
|
||||
def check_qt_version(backend):
|
||||
"""Check if the Qt version is recent enough."""
|
||||
from PyQt5.QtCore import PYQT_VERSION, PYQT_VERSION_STR
|
||||
@ -260,7 +275,7 @@ def check_qt_version(backend):
|
||||
if (not qtutils.version_check('5.2.0', strict=True) or
|
||||
PYQT_VERSION < 0x050200):
|
||||
text = ("Fatal error: Qt and PyQt >= 5.2.0 are required, but Qt {} / "
|
||||
"PyQt {} is installed.".format(version.qt_version(),
|
||||
"PyQt {} is installed.".format(qt_version(),
|
||||
PYQT_VERSION_STR))
|
||||
_die(text)
|
||||
elif (backend == 'webengine' and (
|
||||
@ -268,7 +283,7 @@ def check_qt_version(backend):
|
||||
PYQT_VERSION < 0x050700)):
|
||||
text = ("Fatal error: Qt >= 5.7.1 and PyQt >= 5.7 are required for "
|
||||
"QtWebEngine support, but Qt {} / PyQt {} is installed."
|
||||
.format(version.qt_version(), PYQT_VERSION_STR))
|
||||
.format(qt_version(), PYQT_VERSION_STR))
|
||||
_die(text)
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ except ImportError: # pragma: no cover
|
||||
|
||||
import qutebrowser
|
||||
from qutebrowser.utils import log, utils, standarddir, usertypes, qtutils
|
||||
from qutebrowser.misc import objects
|
||||
from qutebrowser.misc import objects, earlyinit
|
||||
from qutebrowser.browser import pdfjs
|
||||
|
||||
|
||||
@ -280,14 +280,6 @@ def _pdfjs_version():
|
||||
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 _chromium_version():
|
||||
"""Get the Chromium version for QtWebEngine."""
|
||||
if QWebEngineProfile is None:
|
||||
@ -326,7 +318,7 @@ def version():
|
||||
'',
|
||||
'{}: {}'.format(platform.python_implementation(),
|
||||
platform.python_version()),
|
||||
'Qt: {}'.format(qt_version()),
|
||||
'Qt: {}'.format(earlyinit.qt_version()),
|
||||
'PyQt: {}'.format(PYQT_VERSION_STR),
|
||||
'',
|
||||
]
|
||||
|
@ -108,3 +108,20 @@ class TestFixHarfbuzz:
|
||||
"""Without QtWidgets in sys.modules, no warning should be shown."""
|
||||
monkeypatch.setattr(earlyinit.sys, 'modules', {})
|
||||
earlyinit.fix_harfbuzz(args)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('same', [True, False])
|
||||
def test_qt_version(same):
|
||||
if same:
|
||||
qt_version_str = '5.4.0'
|
||||
expected = '5.4.0'
|
||||
else:
|
||||
qt_version_str = '5.3.0'
|
||||
expected = '5.4.0 (compiled 5.3.0)'
|
||||
actual = earlyinit.qt_version(qversion='5.4.0', qt_version=qt_version_str)
|
||||
assert actual == expected
|
||||
|
||||
|
||||
def test_qt_version_no_args():
|
||||
"""Make sure qt_version without arguments at least works."""
|
||||
earlyinit.qt_version()
|
||||
|
@ -774,19 +774,6 @@ class FakeQSslSocket:
|
||||
return self._version
|
||||
|
||||
|
||||
@pytest.mark.parametrize('same', [True, False])
|
||||
def test_qt_version(monkeypatch, same):
|
||||
if same:
|
||||
qt_version_str = '5.4.0'
|
||||
expected = '5.4.0'
|
||||
else:
|
||||
qt_version_str = '5.3.0'
|
||||
expected = '5.4.0 (compiled 5.3.0)'
|
||||
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('ua, expected', [
|
||||
(None, 'unavailable'), # No QWebEngineProfile
|
||||
('Mozilla/5.0', 'unknown'),
|
||||
|
Loading…
Reference in New Issue
Block a user