Add QLibraryInfo wrapper
This commit is contained in:
parent
8011eb4b49
commit
894acbd6f7
|
|
@ -19,16 +19,13 @@
|
|||
|
||||
"""Customized QWebInspector for QtWebEngine."""
|
||||
|
||||
import pathlib
|
||||
|
||||
from qutebrowser.qt.core import QLibraryInfo
|
||||
from qutebrowser.qt.webenginewidgets import QWebEngineView, QWebEnginePage
|
||||
from qutebrowser.qt.widgets import QWidget
|
||||
|
||||
from qutebrowser.browser import inspector
|
||||
from qutebrowser.browser.webengine import webenginesettings
|
||||
from qutebrowser.misc import miscwidgets
|
||||
from qutebrowser.utils import version, usertypes
|
||||
from qutebrowser.utils import version, usertypes, qtutils
|
||||
from qutebrowser.keyinput import modeman
|
||||
|
||||
|
||||
|
|
@ -92,7 +89,7 @@ class WebEngineInspector(inspector.AbstractWebInspector):
|
|||
if dist is None or dist.parsed != version.Distribution.fedora:
|
||||
return
|
||||
|
||||
data_path = pathlib.Path(QLibraryInfo.location(QLibraryInfo.LibraryLocation.DataPath))
|
||||
data_path = qtutils.library_path(qtutils.LibraryPath.data)
|
||||
pak = data_path / 'resources' / 'qtwebengine_devtools_resources.pak'
|
||||
if not pak.exists():
|
||||
raise inspector.Error("QtWebEngine devtools resources not found, "
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import argparse
|
|||
import pathlib
|
||||
from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple
|
||||
|
||||
from qutebrowser.qt.core import QLibraryInfo, QLocale
|
||||
from qutebrowser.qt.core import QLocale
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.misc import objects
|
||||
|
|
@ -199,7 +199,7 @@ def _webengine_locales_path() -> pathlib.Path:
|
|||
# not QtWebEngine.
|
||||
base = pathlib.Path('/app/translations')
|
||||
else:
|
||||
base = pathlib.Path(QLibraryInfo.location(QLibraryInfo.LibraryLocation.TranslationsPath))
|
||||
base = qtutils.library_path(qtutils.LibraryPath.translations)
|
||||
return base / 'qtwebengine_locales'
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,7 @@ import mmap
|
|||
import pathlib
|
||||
from typing import Any, IO, ClassVar, Dict, Optional, Tuple, cast
|
||||
|
||||
from qutebrowser.qt.core import QLibraryInfo
|
||||
|
||||
from qutebrowser.utils import log, version
|
||||
from qutebrowser.utils import log, version, qtutils
|
||||
|
||||
|
||||
class ParseError(Exception):
|
||||
|
|
@ -314,7 +312,7 @@ def parse_webenginecore() -> Optional[Versions]:
|
|||
# Flatpak has Qt in /usr/lib/x86_64-linux-gnu, but QtWebEngine in /app/lib.
|
||||
library_path = pathlib.Path("/app/lib")
|
||||
else:
|
||||
library_path = pathlib.Path(QLibraryInfo.location(QLibraryInfo.LibraryLocation.LibrariesPath))
|
||||
library_path = qtutils.library_path(qtutils.LibraryPath.libraries)
|
||||
|
||||
library_name = sorted(library_path.glob('libQt5WebEngineCore.so*'))
|
||||
if not library_name:
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ Module attributes:
|
|||
|
||||
|
||||
import io
|
||||
import enum
|
||||
import pathlib
|
||||
import operator
|
||||
import contextlib
|
||||
from typing import (Any, AnyStr, TYPE_CHECKING, BinaryIO, IO, Iterator,
|
||||
|
|
@ -36,7 +38,7 @@ from typing import (Any, AnyStr, TYPE_CHECKING, BinaryIO, IO, Iterator,
|
|||
|
||||
from qutebrowser.qt.core import (qVersion, QEventLoop, QDataStream, QByteArray,
|
||||
QIODevice, QFileDevice, QSaveFile, QT_VERSION_STR,
|
||||
PYQT_VERSION_STR, QObject, QUrl)
|
||||
PYQT_VERSION_STR, QObject, QUrl, QLibraryInfo)
|
||||
from qutebrowser.qt.gui import QColor
|
||||
try:
|
||||
from qutebrowser.qt.webkit import qWebKitVersion
|
||||
|
|
@ -548,3 +550,40 @@ def interpolate_color(
|
|||
out = out.convertTo(start.spec())
|
||||
ensure_valid(out)
|
||||
return out
|
||||
|
||||
|
||||
class LibraryPath(enum.Enum):
|
||||
|
||||
"""A path to be passed to QLibraryInfo.
|
||||
|
||||
Should mirror QLibraryPath (Qt 5) and QLibraryLocation (Qt 6).
|
||||
Values are the respective Qt names.
|
||||
"""
|
||||
|
||||
prefix = "PrefixPath"
|
||||
documentation = "DocumentationPath"
|
||||
headers = "HeadersPath"
|
||||
libraries = "LibrariesPath"
|
||||
library_executables = "LibraryExecutablesPath"
|
||||
binaries = "BinariesPath"
|
||||
plugins = "PluginsPath"
|
||||
qml2_imports = "Qml2ImportsPath"
|
||||
arch_data = "ArchDataPath"
|
||||
data = "DataPath"
|
||||
translations = "TranslationsPath"
|
||||
examples = "ExamplesPath"
|
||||
tests = "TestsPath"
|
||||
settings = "SettingsPath"
|
||||
|
||||
|
||||
def library_path(which: LibraryPath) -> pathlib.Path:
|
||||
if hasattr(QLibraryInfo, "path"):
|
||||
# Qt 6
|
||||
val = getattr(QLibraryInfo.LibraryPath, which.value)
|
||||
ret = QLibraryInfo.path(val)
|
||||
else:
|
||||
# Qt 5
|
||||
val = getattr(QLibraryInfo.LibraryLocation, which.value)
|
||||
ret = QLibraryInfo.location(val)
|
||||
assert ret
|
||||
return pathlib.Path(ret)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ from typing import (Mapping, Optional, Sequence, Tuple, ClassVar, Dict, cast,
|
|||
TYPE_CHECKING)
|
||||
|
||||
|
||||
from qutebrowser.qt.core import PYQT_VERSION_STR, QLibraryInfo, qVersion
|
||||
from qutebrowser.qt.core import PYQT_VERSION_STR, qVersion
|
||||
from qutebrowser.qt.network import QSslSocket
|
||||
from qutebrowser.qt.gui import QOpenGLContext, QOffscreenSurface
|
||||
from qutebrowser.qt.opengl import QOpenGLVersionProfile
|
||||
|
|
@ -56,7 +56,8 @@ except ImportError: # pragma: no cover
|
|||
|
||||
|
||||
import qutebrowser
|
||||
from qutebrowser.utils import log, utils, standarddir, usertypes, message, resources
|
||||
from qutebrowser.utils import (log, utils, standarddir, usertypes, message, resources,
|
||||
qtutils)
|
||||
from qutebrowser.misc import objects, earlyinit, sql, httpclient, pastebin, elf
|
||||
from qutebrowser.browser import pdfjs
|
||||
from qutebrowser.config import config
|
||||
|
|
@ -849,8 +850,8 @@ def version_info() -> str:
|
|||
"Imported from {}".format(importpath),
|
||||
"Using Python from {}".format(sys.executable),
|
||||
"Qt library executable path: {}, data path: {}".format(
|
||||
QLibraryInfo.location(QLibraryInfo.LibraryLocation.LibraryExecutablesPath),
|
||||
QLibraryInfo.location(QLibraryInfo.LibraryLocation.DataPath)
|
||||
qtutils.library_path(qtutils.LibraryPath.library_executables),
|
||||
qtutils.library_path(qtutils.LibraryPath.data),
|
||||
)
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import unittest.mock
|
|||
|
||||
import pytest
|
||||
from qutebrowser.qt.core import (QDataStream, QPoint, QUrl, QByteArray, QIODevice,
|
||||
QTimer, QBuffer, QFile, QProcess, QFileDevice)
|
||||
QTimer, QBuffer, QFile, QProcess, QFileDevice, QLibraryInfo)
|
||||
from qutebrowser.qt.gui import QColor
|
||||
|
||||
from qutebrowser.utils import qtutils, utils, usertypes
|
||||
|
|
@ -1030,3 +1030,22 @@ class TestInterpolateColor:
|
|||
testutils.Color(0, 0, 0), testutils.Color(255, 255, 255), percentage, None)
|
||||
assert isinstance(color, QColor)
|
||||
assert testutils.Color(color) == testutils.Color(*expected)
|
||||
|
||||
|
||||
class TestLibraryPath:
|
||||
|
||||
def test_simple(self):
|
||||
try:
|
||||
# Qt 6
|
||||
path = QLibraryInfo.path(QLibraryInfo.LibraryPath.DataLocation)
|
||||
except AttributeError:
|
||||
# Qt 5
|
||||
path = QLibraryInfo.location(QLibraryInfo.LibraryLocation.DataLocation)
|
||||
|
||||
assert path
|
||||
assert str(qtutils.library_path(qtutils.LibraryPath.data)) == path
|
||||
|
||||
@pytest.mark.parametrize("which", list(qtutils.LibraryPath))
|
||||
def test_all(self, which):
|
||||
path = qtutils.library_path(which)
|
||||
assert path.exists()
|
||||
|
|
|
|||
|
|
@ -1237,7 +1237,7 @@ def test_version_info(params, stubs, monkeypatch, config_stub):
|
|||
'_path_info': lambda: {'PATH DESC': 'PATH NAME'},
|
||||
'objects.qapp': (stubs.FakeQApplication(style='STYLE', platform_name='PLATFORM')
|
||||
if params.qapp else None),
|
||||
'QLibraryInfo.location': (lambda _loc: 'QT PATH'),
|
||||
'qtutils.library_path': (lambda _loc: 'QT PATH'),
|
||||
'sql.version': lambda: 'SQLITE VERSION',
|
||||
'_uptime': lambda: datetime.timedelta(hours=1, minutes=23, seconds=45),
|
||||
'config.instance.yaml_loaded': params.autoconfig_loaded,
|
||||
|
|
|
|||
Loading…
Reference in New Issue