eric6/DebugClients/Python/ModuleLoader.py

Tue, 02 Mar 2021 17:17:09 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 02 Mar 2021 17:17:09 +0100
changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8207
d359172d11be
permissions
-rw-r--r--

Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7911
diff changeset
3 # Copyright (c) 2020 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
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
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',
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7894
diff changeset
44 'PyQt6.QtCore',
7646
39e3db2b4936 Merged with default to track recent development.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7563
diff changeset
45 'PySide2.QtCore',
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7894
diff changeset
46 'PySide6.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
47 )
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 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
50
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
51 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
52 """
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
53 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
54
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 @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
56 @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
57 @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
58 @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
59 """
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 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
61 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
62
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 ## 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
64 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
65 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
66 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
67 ):
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 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
69 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
70
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 ## 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
72 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
73 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
74 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
75 ):
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 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
77 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
78
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 ## 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
80 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
81 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
82 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
83 ):
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 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
85 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
86
7424
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
87 ## 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
88 elif (
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
89 fullname == 'subprocess' and
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
90 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
91 ):
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
92 module.eric6_patched = True
9bb7d8b0f966 Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7409
diff changeset
93 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
94
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
95 ## 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
96 elif (
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
97 fullname == 'multiprocessing' and
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
98 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
99 ):
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
100 module.eric6_patched = True
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
101 patchMultiprocessing(module, self.__dbgClient)
b0d6b63f2843 Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7424
diff changeset
102
7407
a0b6acee2c20 Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7404
diff changeset
103 ## 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
104 elif (
7911
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7894
diff changeset
105 fullname in ('PyQt5.QtCore', 'PyQt6.QtCore',
4621c9082a43 Added support for PySide6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7894
diff changeset
106 'PySide2.QtCore', 'PySide6.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
107 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
108 ):
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 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
110 self.__dbgClient.patchQThread(module)
7409
1413bfe73d41 Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7408
diff changeset
111 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
112
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
113 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
114 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
115
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
116 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
117 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
118 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
119
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
120 @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
121 @type str
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
122 @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
123 @type str
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
124 @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
125 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
126 @type module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
127 @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
128 @rtype ModuleSpec
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
129 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
130 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
131 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
132
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
133 if (
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
134 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
135 self.__enableImportHooks
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
136 ):
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
137 # 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
138 self.__enableImportHooks = False
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
139 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
140
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
141 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
142
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
143 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
144 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
145 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
146
7894
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
147 @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
148 @type ModuleSpec
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
149 @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
150 @rtype module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
151 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
152 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
153
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
154 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
155 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
156 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
157
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
158 @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
159 @type module
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
160 """
4370a8b30648 Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7887
diff changeset
161 pass

eric ide

mercurial