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 relevant module appears to be import
(api)
| 118 | |
| 119 | |
| 120 | def has_binding(api): |
| 121 | """Safely check for PyQt4/5, PySide or PySide2, without importing submodules |
| 122 | |
| 123 | Parameters |
| 124 | ---------- |
| 125 | api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault'] |
| 126 | Which module to check for |
| 127 | |
| 128 | Returns |
| 129 | ------- |
| 130 | True if the relevant module appears to be importable |
| 131 | """ |
| 132 | module_name = api_to_module[api] |
| 133 | from importlib.util import find_spec |
| 134 | |
| 135 | required = ['QtCore', 'QtGui', 'QtSvg'] |
| 136 | if api in (QT_API_PYQT5, QT_API_PYSIDE2, QT_API_PYQT6, QT_API_PYSIDE6): |
| 137 | # QT5 requires QtWidgets too |
| 138 | required.append('QtWidgets') |
| 139 | |
| 140 | for submod in required: |
| 141 | try: |
| 142 | spec = find_spec('%s.%s' % (module_name, submod)) |
| 143 | except ImportError: |
| 144 | # Package (e.g. PyQt5) not found |
| 145 | return False |
| 146 | else: |
| 147 | if spec is None: |
| 148 | # Submodule (e.g. PyQt5.QtCore) not found |
| 149 | return False |
| 150 | |
| 151 | if api == QT_API_PYSIDE: |
| 152 | # We can also safely check PySide version |
| 153 | import PySide |
| 154 | |
| 155 | return PySide.__version_info__ >= (1, 0, 3) |
| 156 | |
| 157 | return True |
| 158 | |
| 159 | |
| 160 | def qtapi_version(): |
no outgoing calls
no test coverage detected
searching dependent graphs…