eric6/DebugClients/Python/ModuleLoader.py

Mon, 21 Dec 2020 10:45:10 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 21 Dec 2020 10:45:10 +0100
changeset 7904
0424ebe2d3b1
parent 7894
4370a8b30648
child 7911
4621c9082a43
permissions
-rw-r--r--

DebugBase: fixed an issue with Python < 3.7.

7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an import hook patching modules to support debugging.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import importlib
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
13 from QProcessExtension import patchQProcess
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
14 from SubprocessExtension import patchSubprocess
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
15 from MultiprocessingExtension import patchMultiprocessing
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
16
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class ModuleLoader(object):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing an import hook patching modules to support debugging.
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, debugClient):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param debugClient reference to the debug client object
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @type DebugClient
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.__dbgClient = debugClient
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 self.__enableImportHooks = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 # reset already imported thread module to apply hooks at next import
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 for moduleName in ("thread", "_thread", "threading"):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 if moduleName in sys.modules:
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 del sys.modules[moduleName]
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__modulesToPatch = (
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
39 'thread', '_thread', 'threading',
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
40 'greenlet',
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
41 'subprocess',
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
42 'multiprocessing',
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
43 'PyQt5.QtCore',
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
44 'PySide2.QtCore',
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 )
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 sys.meta_path.insert(0, self)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 def __loadModule(self, fullname):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
51 Private method to load a module.
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param fullname name of the module to be loaded
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @type str
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @return reference to the loaded module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 @rtype module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 module = importlib.import_module(fullname)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 sys.modules[fullname] = module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 ## Add hook for _thread.start_new_thread
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 if (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 fullname in ('thread', '_thread') and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.__dbgClient.patchPyThread(module)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 ## Add hook for threading.run()
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 elif (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 fullname == "threading" and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.__dbgClient.patchPyThreading(module)
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 ## greenlet support
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 elif (
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 fullname == 'greenlet' and
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if self.__dbgClient.patchGreenlet(module):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
85 ## Add hook for subprocess.Popen()
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
86 elif (
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
87 fullname == 'subprocess' and
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
88 not hasattr(module, 'eric6_patched')
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
89 ):
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
90 module.eric6_patched = True
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
91 patchSubprocess(module, self.__dbgClient)
7563
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
92
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
93 ## Add hook for multiprocessing.Process
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
94 elif (
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
95 fullname == 'multiprocessing' and
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
96 not hasattr(module, 'eric6_patched')
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
97 ):
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
98 module.eric6_patched = True
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
99 patchMultiprocessing(module, self.__dbgClient)
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
100
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
101 ## Add hook for *.QThread and *.QProcess
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 elif (
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
103 fullname in ('PyQt5.QtCore', 'PySide2.QtCore') and
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 not hasattr(module, 'eric6_patched')
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 ):
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 module.eric6_patched = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.__dbgClient.patchQThread(module)
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7408
diff changeset
108 patchQProcess(module, self.__dbgClient)
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__enableImportHooks = True
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 return module
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
113 def find_spec(self, fullname, path, target=None):
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
114 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
115 Public method returning the module spec.
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
116
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
117 @param fullname name of the module to be loaded
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
118 @type str
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
119 @param path path to resolve the module name
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
120 @type str
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
121 @param target module object to use for a more educated guess
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
122 about what spec to return
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
123 @type module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
124 @return module spec object pointing to the module loader
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
125 @rtype ModuleSpec
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
126 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
127 if fullname in sys.modules or not self.__dbgClient.debugging:
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 return None
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
130 if (
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
131 fullname in self.__modulesToPatch and
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
132 self.__enableImportHooks
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
133 ):
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
134 # Disable hook to be able to import original module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
135 self.__enableImportHooks = False
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
136 return importlib.machinery.ModuleSpec(fullname, self)
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
138 return None
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
140 def create_module(self, spec):
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
141 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
142 Public method to create a module based on the passed in spec.
7404
663f1c3d6f53 Placed the module loader and patching logic into a separate module of the debug client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
144 @param spec module spec object for loading the module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
145 @type ModuleSpec
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
146 @return created and patched module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
147 @rtype module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
148 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
149 return self.__loadModule(spec.name)
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
150
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
151 def exec_module(self, module):
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
152 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
153 Public method to execute the created module.
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
154
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
155 @param module module to be executed
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
156 @type module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
157 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
158 pass

eric ide

mercurial