Fri, 12 Jan 2024 12:08:29 +0100
Changed some import statements for 'importlib' to 'importlib.util' because sometimes the first doesn't work properly (reason unknown but somewhere in the interpreter).
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 | |
10439
21c28b0f9e41
Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10065
diff
changeset
|
3 | # Copyright (c) 2020 - 2024 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 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
10 | import importlib |
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
|
11 | 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
|
12 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
13 | 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
|
14 | 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
|
15 | from SubprocessExtension import patchSubprocess |
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 | |
8207
d359172d11be
Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7923
diff
changeset
|
18 | class ModuleLoader: |
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
|
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 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
22 | |
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
|
23 | 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
|
24 | """ |
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 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
26 | |
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
|
27 | @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
|
28 | @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
|
29 | """ |
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 | self.__dbgClient = debugClient |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
31 | |
8940
e91951ff3bbd
Fixed cascaded imports which could prevent to apply threading patches. Therefore
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
8881
diff
changeset
|
32 | self.__enableImportHooks = set() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
33 | |
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
|
34 | # 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
|
35 | 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
|
36 | 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
|
37 | del sys.modules[moduleName] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
38 | |
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
|
39 | self.__modulesToPatch = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
40 | "_thread", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
41 | "threading", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
42 | "greenlet", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
43 | "subprocess", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
44 | "multiprocessing", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | "PyQt5.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | "PyQt6.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | "PySide2.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | "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
|
49 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
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
|
51 | sys.meta_path.insert(0, self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
52 | |
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
|
53 | 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
|
54 | """ |
7407
a0b6acee2c20
Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7404
diff
changeset
|
55 | Private method to load a module. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
56 | |
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
|
57 | @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
|
58 | @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
|
59 | @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
|
60 | @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
|
61 | """ |
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 | 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
|
63 | sys.modules[fullname] = module |
8940
e91951ff3bbd
Fixed cascaded imports which could prevent to apply threading patches. Therefore
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
8881
diff
changeset
|
64 | self.__enableImportHooks.remove(fullname) |
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
|
65 | ## Add hook for _thread.start_new_thread |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
66 | if fullname == "_thread" and not hasattr(module, "eric7_patched"): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
67 | module.eric7_patched = True |
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
|
68 | self.__dbgClient.patchPyThread(module) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | |
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
|
70 | ## Add hook for threading.run() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
71 | elif fullname == "threading" and not hasattr(module, "eric7_patched"): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
72 | module.eric7_patched = True |
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
|
73 | self.__dbgClient.patchPyThreading(module) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
74 | |
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
|
75 | ## greenlet support |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | elif fullname == "greenlet" and not hasattr(module, "eric7_patched"): |
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
|
77 | if self.__dbgClient.patchGreenlet(module): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
78 | module.eric7_patched = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | |
7424
9bb7d8b0f966
Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7409
diff
changeset
|
80 | ## Add hook for subprocess.Popen() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
81 | elif fullname == "subprocess" and not hasattr(module, "eric7_patched"): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
82 | module.eric7_patched = True |
7424
9bb7d8b0f966
Implemented multi process debugging support for the 'subprocess' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7409
diff
changeset
|
83 | patchSubprocess(module, self.__dbgClient) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
84 | |
7563
b0d6b63f2843
Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7424
diff
changeset
|
85 | ## Add hook for multiprocessing.Process |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
86 | elif fullname == "multiprocessing" and not hasattr(module, "eric7_patched"): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
87 | module.eric7_patched = True |
7563
b0d6b63f2843
Implemented multi process debugging support for the 'multiprocessing' module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7424
diff
changeset
|
88 | patchMultiprocessing(module, self.__dbgClient) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
89 | |
7407
a0b6acee2c20
Continued with the multiprocess debugger. Started with QProcess support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7404
diff
changeset
|
90 | ## Add hook for *.QThread and *.QProcess |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
91 | elif fullname in ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | "PyQt5.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
93 | "PyQt6.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
94 | "PySide2.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
95 | "PySide6.QtCore", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
96 | ) and not hasattr(module, "eric7_patched"): |
8314
e3642a6a1e71
Finished renaming eric6 to eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
97 | module.eric7_patched = True |
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
|
98 | self.__dbgClient.patchQThread(module) |
7409
1413bfe73d41
Continued with the multiprocess debugger.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7408
diff
changeset
|
99 | patchQProcess(module, self.__dbgClient) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
100 | |
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
|
101 | return module |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | |
10065
de4ae767b0e3
Corrected and checked some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9653
diff
changeset
|
103 | def find_spec(self, fullname, path, target=None): # noqa: U100 |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
104 | """ |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
105 | Public method returning the module spec. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
107 | @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
|
108 | @type str |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
109 | @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
|
110 | @type str |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
111 | @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
|
112 | 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
|
113 | @type module |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
114 | @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
|
115 | @rtype ModuleSpec |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
116 | """ |
8940
e91951ff3bbd
Fixed cascaded imports which could prevent to apply threading patches. Therefore
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
8881
diff
changeset
|
117 | if fullname in sys.modules or self.__dbgClient.debugging is False: |
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
|
118 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
119 | |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
120 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
121 | fullname in self.__modulesToPatch |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
122 | and fullname not in self.__enableImportHooks |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
123 | ): |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
124 | # Disable hook to be able to import original module |
8940
e91951ff3bbd
Fixed cascaded imports which could prevent to apply threading patches. Therefore
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
8881
diff
changeset
|
125 | self.__enableImportHooks.add(fullname) |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
126 | return importlib.machinery.ModuleSpec(fullname, self) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
127 | |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
128 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
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 | 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
|
131 | """ |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
132 | Public method to create a module based on the passed in spec. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
133 | |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
134 | @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
|
135 | @type ModuleSpec |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
136 | @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
|
137 | @rtype module |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
138 | """ |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
139 | return self.__loadModule(spec.name) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
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 | 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
|
142 | """ |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
143 | Public method to execute the created module. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
144 | |
7894
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
145 | @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
|
146 | @type module |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
147 | """ |
4370a8b30648
Changed the minimum supported Python version to 3.6.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7887
diff
changeset
|
148 | pass |