MCPcopy Create free account
hub / github.com/ipython/ipython / has_binding

Function has_binding

IPython/external/qt_loaders.py:109–145  ·  view source on GitHub ↗

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 Returns ------- True if the relevan

(api)

Source from the content-addressed store, hash-verified

107
108
109def has_binding(api):
110 """Safely check for PyQt4/5, PySide or PySide2, without importing submodules
111
112 Parameters
113 ----------
114 api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
115 Which module to check for
116
117 Returns
118 -------
119 True if the relevant module appears to be importable
120 """
121 module_name = api_to_module[api]
122 from importlib.util import find_spec
123
124 required = ['QtCore', 'QtGui', 'QtSvg']
125 if api in (QT_API_PYQT5, QT_API_PYSIDE2):
126 # QT5 requires QtWidgets too
127 required.append('QtWidgets')
128
129 for submod in required:
130 try:
131 spec = find_spec('%s.%s' % (module_name, submod))
132 except ImportError:
133 # Package (e.g. PyQt5) not found
134 return False
135 else:
136 if spec is None:
137 # Submodule (e.g. PyQt5.QtCore) not found
138 return False
139
140 if api == QT_API_PYSIDE:
141 # We can also safely check PySide version
142 import PySide
143 return check_version(PySide.__version__, '1.0.3')
144
145 return True
146
147
148def qtapi_version():

Callers 2

can_importFunction · 0.85
load_qtFunction · 0.85

Calls 1

check_versionFunction · 0.90

Tested by

no test coverage detected