diff options
author | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
---|---|---|
committer | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
commit | 9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75 (patch) | |
tree | 78b522cab9f76336e62064d4d8ff7c897659b20e /contrib/python/ipython/py3/IPython/external/qt_loaders.py | |
parent | 8113a823ffca6451bb5ff8f0334560885a939a24 (diff) |
Update contrib/python/ipython/py3 to 8.3.0
ref:e84342d4d30476f9148137f37fd0c6405fd36f55
Diffstat (limited to 'contrib/python/ipython/py3/IPython/external/qt_loaders.py')
-rw-r--r-- | contrib/python/ipython/py3/IPython/external/qt_loaders.py | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/contrib/python/ipython/py3/IPython/external/qt_loaders.py b/contrib/python/ipython/py3/IPython/external/qt_loaders.py index 79805358e72..39ea298460b 100644 --- a/contrib/python/ipython/py3/IPython/external/qt_loaders.py +++ b/contrib/python/ipython/py3/IPython/external/qt_loaders.py @@ -8,13 +8,12 @@ bindings, which is unstable and likely to crash This is used primarily by qt and qt_for_kernel, and shouldn't be accessed directly from the outside """ +import importlib.abc import sys import types from functools import partial, lru_cache import operator -from IPython.utils.version import check_version - # ### Available APIs. # Qt6 QT_API_PYQT6 = "pyqt6" @@ -47,7 +46,7 @@ api_to_module = { } -class ImportDenier(object): +class ImportDenier(importlib.abc.MetaPathFinder): """Import Hook that will guard against bad Qt imports once IPython commits to a specific binding """ @@ -59,17 +58,17 @@ class ImportDenier(object): sys.modules.pop(module_name, None) self.__forbidden.add(module_name) - def find_module(self, fullname, path=None): + def find_spec(self, fullname, path, target=None): if path: return if fullname in self.__forbidden: - return self - - def load_module(self, fullname): - raise ImportError(""" + raise ImportError( + """ Importing %s disabled by IPython, which has already imported an Incompatible QT Binding: %s - """ % (fullname, loaded_api())) + """ + % (fullname, loaded_api()) + ) ID = ImportDenier() @@ -78,7 +77,7 @@ sys.meta_path.insert(0, ID) def commit_api(api): """Commit to a particular API, and trigger ImportErrors on subsequent - dangerous imports""" + dangerous imports""" modules = set(api_to_module.values()) modules.remove(api_to_module[api]) @@ -118,15 +117,15 @@ def loaded_api(): def has_binding(api): """Safely check for PyQt4/5, PySide or PySide2, without importing submodules - Parameters - ---------- - api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault'] - Which module to check for + Parameters + ---------- + api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault'] + Which module to check for - Returns - ------- - True if the relevant module appears to be importable - """ + Returns + ------- + True if the relevant module appears to be importable + """ module_name = api_to_module[api] from importlib.util import find_spec @@ -149,7 +148,8 @@ def has_binding(api): if api == QT_API_PYSIDE: # We can also safely check PySide version import PySide - return check_version(PySide.__version__, '1.0.3') + + return PySide.__version_info__ >= (1, 0, 3) return True @@ -195,10 +195,9 @@ def import_pyqt4(version=2): Parameters ---------- version : 1, 2, or None - Which QString/QVariant API to use. Set to None to use the system - default - - ImportErrors rasied within this function are non-recoverable + Which QString/QVariant API to use. Set to None to use the system + default + ImportErrors raised within this function are non-recoverable """ # The new-style string API (version=2) automatically # converts QStrings to Unicode Python strings. Also, automatically unpacks @@ -211,7 +210,7 @@ def import_pyqt4(version=2): from PyQt4 import QtGui, QtCore, QtSvg - if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): + if QtCore.PYQT_VERSION < 0x040700: raise ImportError("IPython requires PyQt4 >= 4.7, found %s" % QtCore.PYQT_VERSION_STR) @@ -229,7 +228,7 @@ def import_pyqt5(): """ Import PyQt5 - ImportErrors rasied within this function are non-recoverable + ImportErrors raised within this function are non-recoverable """ from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui @@ -251,7 +250,7 @@ def import_pyqt6(): """ Import PyQt6 - ImportErrors rasied within this function are non-recoverable + ImportErrors raised within this function are non-recoverable """ from PyQt6 import QtCore, QtSvg, QtWidgets, QtGui @@ -321,13 +320,12 @@ def load_qt(api_options): Parameters ---------- - api_options: List of strings + api_options : List of strings The order of APIs to try. Valid items are 'pyside', 'pyside2', 'pyqt', 'pyqt5', 'pyqtv1' and 'pyqtdefault' Returns ------- - A tuple of QtCore, QtGui, QtSvg, QT_API The first three are the Qt modules. The last is the string indicating which module was loaded. |