Skip to content

Commit 14f58f3

Browse files
committed
Add support for the debug modules request
1 parent d9243ee commit 14f58f3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ipykernel/debugger.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import os
23
import re
34
import threading
@@ -265,7 +266,8 @@ class Debugger:
265266

266267
# Requests that can be handled even if the debugger is not running
267268
static_debug_msg_types = [
268-
'debugInfo', 'inspectVariables', 'richInspectVariables'
269+
'debugInfo', 'inspectVariables',
270+
'richInspectVariables', 'modules'
269271
]
270272

271273
def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
@@ -591,6 +593,24 @@ async def richInspectVariables(self, message):
591593
reply["success"] = True
592594
return reply
593595

596+
async def modules(self, message):
597+
modules = [sys.modules[name] for name in sys.modules]
598+
mods = []
599+
for module in modules:
600+
m = str(module)
601+
if ".py'" in m:
602+
a = {}
603+
x = re.findall(r"'(.*?)'", m)
604+
a[x[0]] = x[1]
605+
mods.append(a)
606+
reply = {
607+
'body': {
608+
'modules': mods,
609+
'totalModules': len(modules)
610+
}
611+
}
612+
return reply
613+
594614
async def process_request(self, message):
595615
reply = {}
596616

0 commit comments

Comments
 (0)