summaryrefslogtreecommitdiff
path: root/qutebrowser/misc/earlyinit.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/misc/earlyinit.py')
-rw-r--r--qutebrowser/misc/earlyinit.py89
1 files changed, 52 insertions, 37 deletions
diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py
index 286d4f071..ef7814ab1 100644
--- a/qutebrowser/misc/earlyinit.py
+++ b/qutebrowser/misc/earlyinit.py
@@ -78,8 +78,8 @@ def _die(message, exception=None):
message: The message to display.
exception: The exception object if we're handling an exception.
"""
- from PyQt5.QtWidgets import QApplication, QMessageBox
- from PyQt5.QtCore import Qt
+ from qutebrowser.qt.widgets import QApplication, QMessageBox
+ from qutebrowser.qt.core import Qt
if (('--debug' in sys.argv or '--no-err-windows' in sys.argv) and
exception is not None):
print(file=sys.stderr)
@@ -91,9 +91,9 @@ def _die(message, exception=None):
else:
if exception is not None:
message = message.replace('%ERROR%', str(exception))
- msgbox = QMessageBox(QMessageBox.Critical, "qutebrowser: Fatal error!",
+ msgbox = QMessageBox(QMessageBox.Icon.Critical, "qutebrowser: Fatal error!",
message)
- msgbox.setTextFormat(Qt.RichText)
+ msgbox.setTextFormat(Qt.TextFormat.RichText)
msgbox.resize(msgbox.sizeHint())
msgbox.exec()
app.quit()
@@ -138,7 +138,10 @@ def init_faulthandler(fileobj=sys.__stderr__):
def check_pyqt():
"""Check if PyQt core modules (QtCore/QtWidgets) are installed."""
- for name in ['PyQt5.QtCore', 'PyQt5.QtWidgets']:
+ from qutebrowser.qt import machinery
+
+ packages = [f'{machinery.PACKAGE}.QtCore', f'{machinery.PACKAGE}.QtWidgets']
+ for name in packages:
try:
importlib.import_module(name)
except ImportError as e:
@@ -162,10 +165,10 @@ def check_pyqt():
def qt_version(qversion=None, qt_version_str=None):
"""Get a Qt version string based on the runtime/compiled versions."""
if qversion is None:
- from PyQt5.QtCore import qVersion
+ from qutebrowser.qt.core import qVersion
qversion = qVersion()
if qt_version_str is None:
- from PyQt5.QtCore import QT_VERSION_STR
+ from qutebrowser.qt.core import QT_VERSION_STR
qt_version_str = QT_VERSION_STR
if qversion != qt_version_str:
@@ -174,33 +177,38 @@ def qt_version(qversion=None, qt_version_str=None):
return qversion
-def check_qt_version():
- """Check if the Qt version is recent enough."""
- from PyQt5.QtCore import QT_VERSION, PYQT_VERSION, PYQT_VERSION_STR
+def get_qt_version():
+ """Get the Qt version, or None if too old for QLibaryInfo.version()."""
try:
- from PyQt5.QtCore import QVersionNumber, QLibraryInfo
- qt_ver = QLibraryInfo.version().normalized()
- recent_qt_runtime = qt_ver >= QVersionNumber(5, 12) # type: ignore[operator]
+ from qutebrowser.qt.core import QLibraryInfo
+ return QLibraryInfo.version().normalized()
except (ImportError, AttributeError):
- # QVersionNumber was added in Qt 5.6, QLibraryInfo.version() in 5.8
- recent_qt_runtime = False
+ return None
+
- if QT_VERSION < 0x050C00 or PYQT_VERSION < 0x050C00 or not recent_qt_runtime:
- text = ("Fatal error: Qt >= 5.12.0 and PyQt >= 5.12.0 are required, "
+def check_qt_version():
+ """Check if the Qt version is recent enough."""
+ from qutebrowser.qt.core import QT_VERSION, PYQT_VERSION, PYQT_VERSION_STR
+ from qutebrowser.qt.core import QVersionNumber
+ qt_ver = get_qt_version()
+ recent_qt_runtime = qt_ver is not None and qt_ver >= QVersionNumber(5, 15)
+
+ if QT_VERSION < 0x050F00 or PYQT_VERSION < 0x050F00 or not recent_qt_runtime:
+ text = ("Fatal error: Qt >= 5.15.0 and PyQt >= 5.15.0 are required, "
"but Qt {} / PyQt {} is installed.".format(qt_version(),
PYQT_VERSION_STR))
_die(text)
- if qt_ver == QVersionNumber(5, 12, 0):
- from qutebrowser.utils import log
- log.init.warning("Running on Qt 5.12.0. Doing so is unsupported "
- "(newer 5.12.x versions are fine).")
+ if 0x060000 <= PYQT_VERSION < 0x060202:
+ text = ("Fatal error: With Qt 6, PyQt >= 6.2.2 is required, but "
+ "{} is installed.".format(PYQT_VERSION_STR))
+ _die(text)
def check_ssl_support():
"""Check if SSL support is available."""
try:
- from PyQt5.QtNetwork import QSslSocket # pylint: disable=unused-import
+ from qutebrowser.qt.network import QSslSocket # pylint: disable=unused-import
except ImportError:
_die("Fatal error: Your Qt is built without SSL support.")
@@ -232,21 +240,28 @@ def _check_modules(modules):
def check_libraries():
"""Check if all needed Python libraries are installed."""
+ from qutebrowser.qt import machinery
modules = {
'jinja2': _missing_str("jinja2"),
'yaml': _missing_str("PyYAML"),
- 'PyQt5.QtQml': _missing_str("PyQt5.QtQml"),
- 'PyQt5.QtSql': _missing_str("PyQt5.QtSql"),
- 'PyQt5.QtOpenGL': _missing_str("PyQt5.QtOpenGL"),
- 'PyQt5.QtDBus': _missing_str("PyQt5.QtDBus"),
}
+
+ for subpkg in ['QtQml', 'QtOpenGL', 'QtDBus']:
+ package = f'{machinery.PACKAGE}.{subpkg}'
+ modules[package] = _missing_str(package)
+
if sys.version_info < (3, 9):
# Backport required
modules['importlib_resources'] = _missing_str("importlib_resources")
+
if sys.platform.startswith('darwin'):
- # Used for resizable hide_decoration windows on macOS
- modules['objc'] = _missing_str("pyobjc-core")
- modules['AppKit'] = _missing_str("pyobjc-framework-Cocoa")
+ from qutebrowser.qt.core import QVersionNumber
+ qt_ver = get_qt_version()
+ if qt_ver is not None and qt_ver < QVersionNumber(6, 3):
+ # Used for resizable hide_decoration windows on macOS
+ modules['objc'] = _missing_str("pyobjc-core")
+ modules['AppKit'] = _missing_str("pyobjc-framework-Cocoa")
+
_check_modules(modules)
@@ -256,17 +271,17 @@ def configure_pyqt():
Doing this means we can't use the interactive shell anymore (which we don't
anyways), but we can use pdb instead.
"""
- from PyQt5 import QtCore
- QtCore.pyqtRemoveInputHook()
+ from qutebrowser.qt.core import pyqtRemoveInputHook
+ pyqtRemoveInputHook()
+
+ from qutebrowser.qt import sip
try:
- QtCore.pyqt5_enable_new_onexit_scheme(True) # type: ignore[attr-defined]
+ sip.enableoverflowchecking(True)
except AttributeError:
- # Added in PyQt 5.13 somewhere, going to be the default in 5.14
+ # default in PyQt6
+ # FIXME:qt6 solve this in qutebrowser/qt/sip.py equivalent?
pass
- from qutebrowser.qt import sip
- sip.enableoverflowchecking(True)
-
def init_log(args):
"""Initialize logging.
@@ -297,7 +312,7 @@ def webengine_early_import():
error messages in backendproblem.py are accurate.
"""
try:
- from PyQt5 import QtWebEngineWidgets # pylint: disable=unused-import
+ from qutebrowser.qt import webenginewidgets # pylint: disable=unused-import
except ImportError:
pass