mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
fix PY-14779 and refix PY-14649
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
|
||||
def _import_module_patched(module_label, classnames):
|
||||
"""
|
||||
Imports the module with the given name.
|
||||
Returns None if the module doesn't exist, but propagates any import errors.
|
||||
"""
|
||||
try:
|
||||
return __import__(module_label, fromlist=classnames)
|
||||
except ImportError:
|
||||
# There are 2 reasons why there could be an ImportError:
|
||||
#
|
||||
# 1. Module does not exist. In that case, we ignore the import and
|
||||
# return None
|
||||
# 2. Module exists but another ImportError occurred when trying to
|
||||
# import the module. In that case, it is important to propagate the
|
||||
# error.
|
||||
#
|
||||
# ImportError does not provide easy way to distinguish those two cases.
|
||||
# Fortunately, the traceback of the ImportError starts at __import__
|
||||
# statement. If the traceback has more than one frame, it means that
|
||||
# application was found and ImportError originates within the local app
|
||||
#
|
||||
# Changes in patch: change 1 to 2 frames because of the frame, added by
|
||||
# plugin_import.
|
||||
#
|
||||
__, __, exc_traceback = sys.exc_info()
|
||||
frames = traceback.extract_tb(exc_traceback)
|
||||
if len(frames) > 2:
|
||||
raise
|
||||
|
||||
|
||||
def patch_oscar_loading():
|
||||
module = sys.modules['oscar.core.loading']
|
||||
setattr(module, '_import_module', _import_module_patched)
|
||||
@@ -12,7 +12,7 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pydevd_constants import IS_PY24, IS_PY3K, IS_JYTHON, DictContains, DictPop
|
||||
from pydevd_constants import IS_PY24, IS_PY3K, IS_JYTHON
|
||||
|
||||
if IS_PY24:
|
||||
from _pydev_imps._pydev_uuid_old import uuid4
|
||||
@@ -405,16 +405,6 @@ class _ImportHook(ModuleType):
|
||||
ModuleType.__init__(self, name)
|
||||
self._system_import = system_import
|
||||
self.enabled = True
|
||||
self._modules_to_patch = {}
|
||||
self._add_modules_for_patching()
|
||||
|
||||
def _add_modules_for_patching(self):
|
||||
try:
|
||||
from _pydev_imps._pydev_django_oscar_patch import \
|
||||
patch_oscar_loading
|
||||
self._modules_to_patch['oscar.core.loading'] = patch_oscar_loading
|
||||
except:
|
||||
sys.stderr.write("Adding modules to patch in pluginbase failed\n")
|
||||
|
||||
def enable(self):
|
||||
"""Enables the import hook which drives the plugin base system.
|
||||
@@ -458,26 +448,29 @@ class _ImportHook(ModuleType):
|
||||
level = -1
|
||||
if IS_JYTHON:
|
||||
import_name = name
|
||||
|
||||
activate_func = None
|
||||
if name == import_name and DictContains(self._modules_to_patch, name):
|
||||
activate_func = DictPop(self._modules_to_patch, name)
|
||||
|
||||
module = self._system_import(import_name, globals, locals, fromlist, level)
|
||||
try:
|
||||
if activate_func:
|
||||
activate_func() #call activate function
|
||||
except:
|
||||
sys.stderr.write("Patching modules in pluginbase failed\n")
|
||||
return module
|
||||
|
||||
return self._system_import(import_name, globals, locals,
|
||||
fromlist, level)
|
||||
|
||||
try:
|
||||
import __builtin__ as builtins
|
||||
except ImportError:
|
||||
import builtins
|
||||
|
||||
|
||||
import_hook = _ImportHook(__name__ + '.import_hook', builtins.__import__)
|
||||
builtins.__import__ = import_hook.plugin_import
|
||||
sys.modules[import_hook.__name__] = import_hook
|
||||
del builtins
|
||||
|
||||
|
||||
def patched_exc_info():
|
||||
type, value, traceback = sys.system_exc_info()
|
||||
if type == ImportError:
|
||||
#we should not show frame added by plugin_import call
|
||||
return type, value, traceback.tb_next
|
||||
return type, value, traceback
|
||||
|
||||
|
||||
system_exc_info = sys.exc_info
|
||||
sys.exc_info = patched_exc_info
|
||||
sys.system_exc_info = system_exc_info
|
||||
|
||||
@@ -57,10 +57,20 @@ def _patch_import_to_patch_pyqt_on_import(patch_qt_on_import):
|
||||
|
||||
dotted = patch_qt_on_import + '.'
|
||||
original_import = __import__
|
||||
import sys
|
||||
original_exc_info = sys.exc_info
|
||||
|
||||
def patched_exc_info():
|
||||
type, value, traceback = original_exc_info()
|
||||
if type == ImportError:
|
||||
#we should not show frame added by patched_import call
|
||||
return type, value, traceback.tb_next
|
||||
return type, value, traceback
|
||||
|
||||
def patched_import(name, *args, **kwargs):
|
||||
if patch_qt_on_import == name or name.startswith(dotted):
|
||||
builtins.__import__ = original_import
|
||||
sys.exc_info = original_exc_info
|
||||
_internal_patch_qt() # Patch it only when the user would import the qt module
|
||||
return original_import(name, *args, **kwargs)
|
||||
|
||||
@@ -68,7 +78,8 @@ def _patch_import_to_patch_pyqt_on_import(patch_qt_on_import):
|
||||
import builtins
|
||||
except ImportError:
|
||||
import __builtin__ as builtins
|
||||
builtins.__import__ = patched_import
|
||||
builtins.__import__ = patched_import
|
||||
sys.exc_info = patched_exc_info
|
||||
|
||||
|
||||
def _internal_patch_qt():
|
||||
|
||||
@@ -122,7 +122,6 @@ DONT_TRACE = {
|
||||
'_pydev_pluginbase.py':1,
|
||||
'_pydev_pkgutil_old.py':1,
|
||||
'_pydev_uuid_old.py':1,
|
||||
'_pydev_django_oscar_patch.py':1,
|
||||
|
||||
#things from pydev that we don't want to trace
|
||||
'_pydev_execfile.py':1,
|
||||
|
||||
Reference in New Issue
Block a user