aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py2/IPython/external
diff options
context:
space:
mode:
authorsmosker <smosker@yandex-team.ru>2022-02-10 16:48:22 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:22 +0300
commit01fa2667d0e5e868b18424bc1906146e5ee340db (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /contrib/python/ipython/py2/IPython/external
parentdd14d17a747a9c259858faf2fcc3ea6b92df4e15 (diff)
downloadydb-01fa2667d0e5e868b18424bc1906146e5ee340db.tar.gz
Restoring authorship annotation for <smosker@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/external')
-rw-r--r--contrib/python/ipython/py2/IPython/external/qt_for_kernel.py8
-rw-r--r--contrib/python/ipython/py2/IPython/external/qt_loaders.py188
2 files changed, 98 insertions, 98 deletions
diff --git a/contrib/python/ipython/py2/IPython/external/qt_for_kernel.py b/contrib/python/ipython/py2/IPython/external/qt_for_kernel.py
index be7a4d6470..1a94e7e0a2 100644
--- a/contrib/python/ipython/py2/IPython/external/qt_for_kernel.py
+++ b/contrib/python/ipython/py2/IPython/external/qt_for_kernel.py
@@ -33,10 +33,10 @@ import sys
from IPython.utils.version import check_version
from IPython.external.qt_loaders import (load_qt, loaded_api, QT_API_PYSIDE,
- QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5,
+ QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5,
QT_API_PYQTv1, QT_API_PYQT_DEFAULT)
-_qt_apis = (QT_API_PYSIDE, QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,
+_qt_apis = (QT_API_PYSIDE, QT_API_PYSIDE2, QT_API_PYQT, QT_API_PYQT5, QT_API_PYQTv1,
QT_API_PYQT_DEFAULT)
#Constraints placed on an imported matplotlib
@@ -83,8 +83,8 @@ def get_options():
qt_api = os.environ.get('QT_API', None)
if qt_api is None:
#no ETS variable. Ask mpl, then use default fallback path
- return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE,
- QT_API_PYQT5, QT_API_PYSIDE2]
+ return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE,
+ QT_API_PYQT5, QT_API_PYSIDE2]
elif qt_api not in _qt_apis:
raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
(qt_api, ', '.join(_qt_apis)))
diff --git a/contrib/python/ipython/py2/IPython/external/qt_loaders.py b/contrib/python/ipython/py2/IPython/external/qt_loaders.py
index a9cdf7785c..3b894fb2ab 100644
--- a/contrib/python/ipython/py2/IPython/external/qt_loaders.py
+++ b/contrib/python/ipython/py2/IPython/external/qt_loaders.py
@@ -20,17 +20,17 @@ QT_API_PYQT5 = 'pyqt5'
QT_API_PYQTv1 = 'pyqtv1' # Force version 2
QT_API_PYQT_DEFAULT = 'pyqtdefault' # use system default for version 1 vs. 2
QT_API_PYSIDE = 'pyside'
-QT_API_PYSIDE2 = 'pyside2'
+QT_API_PYSIDE2 = 'pyside2'
+
+api_to_module = {QT_API_PYSIDE2: 'PySide2',
+ QT_API_PYSIDE: 'PySide',
+ QT_API_PYQT: 'PyQt4',
+ QT_API_PYQTv1: 'PyQt4',
+ QT_API_PYQT5: 'PyQt5',
+ QT_API_PYQT_DEFAULT: 'PyQt4',
+ }
-api_to_module = {QT_API_PYSIDE2: 'PySide2',
- QT_API_PYSIDE: 'PySide',
- QT_API_PYQT: 'PyQt4',
- QT_API_PYQTv1: 'PyQt4',
- QT_API_PYQT5: 'PyQt5',
- QT_API_PYQT_DEFAULT: 'PyQt4',
- }
-
class ImportDenier(object):
"""Import Hook that will guard against bad Qt imports
once IPython commits to a specific binding
@@ -56,28 +56,28 @@ class ImportDenier(object):
""" % (fullname, loaded_api()))
ID = ImportDenier()
-sys.meta_path.insert(0, ID)
+sys.meta_path.insert(0, ID)
def commit_api(api):
"""Commit to a particular API, and trigger ImportErrors on subsequent
dangerous imports"""
- if api == QT_API_PYSIDE2:
- ID.forbid('PySide')
- ID.forbid('PyQt4')
- ID.forbid('PyQt5')
+ if api == QT_API_PYSIDE2:
+ ID.forbid('PySide')
+ ID.forbid('PyQt4')
+ ID.forbid('PyQt5')
if api == QT_API_PYSIDE:
- ID.forbid('PySide2')
+ ID.forbid('PySide2')
ID.forbid('PyQt4')
ID.forbid('PyQt5')
elif api == QT_API_PYQT5:
- ID.forbid('PySide2')
+ ID.forbid('PySide2')
ID.forbid('PySide')
ID.forbid('PyQt4')
else: # There are three other possibilities, all representing PyQt4
ID.forbid('PyQt5')
- ID.forbid('PySide2')
+ ID.forbid('PySide2')
ID.forbid('PySide')
@@ -89,7 +89,7 @@ def loaded_api():
Returns
-------
- None, 'pyside2', 'pyside', 'pyqt', 'pyqt5', or 'pyqtv1'
+ None, 'pyside2', 'pyside', 'pyqt', 'pyqt5', or 'pyqtv1'
"""
if 'PyQt4.QtCore' in sys.modules:
if qtapi_version() == 2:
@@ -98,21 +98,21 @@ def loaded_api():
return QT_API_PYQTv1
elif 'PySide.QtCore' in sys.modules:
return QT_API_PYSIDE
- elif 'PySide2.QtCore' in sys.modules:
- return QT_API_PYSIDE2
+ elif 'PySide2.QtCore' in sys.modules:
+ return QT_API_PYSIDE2
elif 'PyQt5.QtCore' in sys.modules:
return QT_API_PYQT5
return None
def has_binding(api):
- """Safely check for PyQt4/5, PySide or PySide2, without importing submodules
+ """Safely check for PyQt4/5, PySide or PySide2, without importing submodules
+
+ Supports Python <= 3.3
- Supports Python <= 3.3
-
Parameters
----------
- api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
+ api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
Which module to check for
Returns
@@ -122,7 +122,7 @@ def has_binding(api):
# we can't import an incomplete pyside and pyqt4
# this will cause a crash in sip (#1431)
# check for complete presence before importing
- module_name = api_to_module[api]
+ module_name = api_to_module[api]
import imp
try:
@@ -132,7 +132,7 @@ def has_binding(api):
imp.find_module('QtCore', mod.__path__)
imp.find_module('QtGui', mod.__path__)
imp.find_module('QtSvg', mod.__path__)
- if api in (QT_API_PYQT5, QT_API_PYSIDE2):
+ if api in (QT_API_PYQT5, QT_API_PYSIDE2):
# QT5 requires QtWidgets too
imp.find_module('QtWidgets', mod.__path__)
@@ -144,49 +144,49 @@ def has_binding(api):
except ImportError:
return False
-def has_binding_new(api):
- """Safely check for PyQt4/5, PySide or PySide2, without importing submodules
-
- Supports Python >= 3.4
-
- Parameters
- ----------
- api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
- Which module to check for
-
- Returns
- -------
- True if the relevant module appears to be importable
- """
- module_name = api_to_module[api]
- from importlib.util import find_spec
-
- required = ['QtCore', 'QtGui', 'QtSvg']
- if api in (QT_API_PYQT5, QT_API_PYSIDE2):
- # QT5 requires QtWidgets too
- required.append('QtWidgets')
-
- for submod in required:
- try:
- spec = find_spec('%s.%s' % (module_name, submod))
- except ImportError:
- # Package (e.g. PyQt5) not found
- return False
- else:
- if spec is None:
- # Submodule (e.g. PyQt5.QtCore) not found
- return False
-
- if api == QT_API_PYSIDE:
- # We can also safely check PySide version
- import PySide
- return check_version(PySide.__version__, '1.0.3')
-
- return True
-
-if sys.version_info >= (3, 4):
- has_binding = has_binding_new
-
+def has_binding_new(api):
+ """Safely check for PyQt4/5, PySide or PySide2, without importing submodules
+
+ Supports Python >= 3.4
+
+ Parameters
+ ----------
+ api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
+ Which module to check for
+
+ Returns
+ -------
+ True if the relevant module appears to be importable
+ """
+ module_name = api_to_module[api]
+ from importlib.util import find_spec
+
+ required = ['QtCore', 'QtGui', 'QtSvg']
+ if api in (QT_API_PYQT5, QT_API_PYSIDE2):
+ # QT5 requires QtWidgets too
+ required.append('QtWidgets')
+
+ for submod in required:
+ try:
+ spec = find_spec('%s.%s' % (module_name, submod))
+ except ImportError:
+ # Package (e.g. PyQt5) not found
+ return False
+ else:
+ if spec is None:
+ # Submodule (e.g. PyQt5.QtCore) not found
+ return False
+
+ if api == QT_API_PYSIDE:
+ # We can also safely check PySide version
+ import PySide
+ return check_version(PySide.__version__, '1.0.3')
+
+ return True
+
+if sys.version_info >= (3, 4):
+ has_binding = has_binding_new
+
def qtapi_version():
"""Return which QString API has been set, if any
@@ -285,23 +285,23 @@ def import_pyside():
from PySide import QtGui, QtCore, QtSvg
return QtCore, QtGui, QtSvg, QT_API_PYSIDE
-def import_pyside2():
- """
- Import PySide2
-
- ImportErrors raised within this function are non-recoverable
- """
- from PySide2 import QtGui, QtCore, QtSvg, QtWidgets, QtPrintSupport
-
- # Join QtGui and QtWidgets for Qt4 compatibility.
- QtGuiCompat = types.ModuleType('QtGuiCompat')
- QtGuiCompat.__dict__.update(QtGui.__dict__)
- QtGuiCompat.__dict__.update(QtWidgets.__dict__)
- QtGuiCompat.__dict__.update(QtPrintSupport.__dict__)
-
- return QtCore, QtGuiCompat, QtSvg, QT_API_PYSIDE2
-
-
+def import_pyside2():
+ """
+ Import PySide2
+
+ ImportErrors raised within this function are non-recoverable
+ """
+ from PySide2 import QtGui, QtCore, QtSvg, QtWidgets, QtPrintSupport
+
+ # Join QtGui and QtWidgets for Qt4 compatibility.
+ QtGuiCompat = types.ModuleType('QtGuiCompat')
+ QtGuiCompat.__dict__.update(QtGui.__dict__)
+ QtGuiCompat.__dict__.update(QtWidgets.__dict__)
+ QtGuiCompat.__dict__.update(QtPrintSupport.__dict__)
+
+ return QtCore, QtGuiCompat, QtSvg, QT_API_PYSIDE2
+
+
def load_qt(api_options):
"""
Attempt to import Qt, given a preference list
@@ -312,7 +312,7 @@ def load_qt(api_options):
Parameters
----------
api_options: List of strings
- The order of APIs to try. Valid items are 'pyside', 'pyside2',
+ The order of APIs to try. Valid items are 'pyside', 'pyside2',
'pyqt', 'pyqt5', 'pyqtv1' and 'pyqtdefault'
Returns
@@ -328,14 +328,14 @@ def load_qt(api_options):
bindings (either becaues they aren't installed, or because
an incompatible library has already been installed)
"""
- loaders = {
- QT_API_PYSIDE2: import_pyside2,
- QT_API_PYSIDE: import_pyside,
+ loaders = {
+ QT_API_PYSIDE2: import_pyside2,
+ QT_API_PYSIDE: import_pyside,
QT_API_PYQT: import_pyqt4,
QT_API_PYQT5: import_pyqt5,
QT_API_PYQTv1: partial(import_pyqt4, version=1),
QT_API_PYQT_DEFAULT: partial(import_pyqt4, version=None)
- }
+ }
for api in api_options:
@@ -355,18 +355,18 @@ def load_qt(api_options):
else:
raise ImportError("""
Could not load requested Qt binding. Please ensure that
- PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,
+ PyQt4 >= 4.7, PyQt5, PySide >= 1.0.3 or PySide2 is available,
and only one is imported per session.
Currently-imported Qt library: %r
PyQt4 available (requires QtCore, QtGui, QtSvg): %s
PyQt5 available (requires QtCore, QtGui, QtSvg, QtWidgets): %s
PySide >= 1.0.3 installed: %s
- PySide2 installed: %s
+ PySide2 installed: %s
Tried to load: %r
""" % (loaded_api(),
has_binding(QT_API_PYQT),
has_binding(QT_API_PYQT5),
has_binding(QT_API_PYSIDE),
- has_binding(QT_API_PYSIDE2),
+ has_binding(QT_API_PYSIDE2),
api_options))