Skip to content

Commit 4868558

Browse files
authored
Always set debugger to true in kernelspec (#1191)
1 parent 1e3bb9d commit 4868558

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

ipykernel/kernelspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_kernel_dict(extra_arguments: list[str] | None = None) -> dict[str, Any]:
6666
"argv": make_ipkernel_cmd(extra_arguments=extra_arguments),
6767
"display_name": "Python %i (ipykernel)" % sys.version_info[0],
6868
"language": "python",
69-
"metadata": {"debugger": _is_debugpy_available},
69+
"metadata": {"debugger": True},
7070
}
7171

7272

tests/test_debugger.py

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
seq = 0
88

9-
# Skip if debugpy is not available
10-
pytest.importorskip("debugpy")
9+
# Tests support debugpy not being installed, in which case the tests don't do anything useful
10+
# functionally as the debug message replies are usually empty dictionaries, but they confirm that
11+
# ipykernel doesn't block, or segfault, or raise an exception.
12+
try:
13+
import debugpy
14+
except ImportError:
15+
debugpy = None
1116

1217

1318
def wait_for_debug_request(kernel, command, arguments=None, full_reply=False):
@@ -85,15 +90,21 @@ def test_debug_initialize(kernel):
8590
"locale": "en",
8691
},
8792
)
88-
assert reply["success"]
93+
if debugpy:
94+
assert reply["success"]
95+
else:
96+
assert reply == {}
8997

9098

9199
def test_attach_debug(kernel_with_debug):
92100
reply = wait_for_debug_request(
93101
kernel_with_debug, "evaluate", {"expression": "'a' + 'b'", "context": "repl"}
94102
)
95-
assert reply["success"]
96-
assert reply["body"]["result"] == ""
103+
if debugpy:
104+
assert reply["success"]
105+
assert reply["body"]["result"] == ""
106+
else:
107+
assert reply == {}
97108

98109

99110
def test_set_breakpoints(kernel_with_debug):
@@ -104,7 +115,11 @@ def test_set_breakpoints(kernel_with_debug):
104115
f(2, 3)"""
105116

106117
r = wait_for_debug_request(kernel_with_debug, "dumpCell", {"code": code})
107-
source = r["body"]["sourcePath"]
118+
if debugpy:
119+
source = r["body"]["sourcePath"]
120+
else:
121+
assert r == {}
122+
source = "non-existent path"
108123

109124
reply = wait_for_debug_request(
110125
kernel_with_debug,
@@ -115,20 +130,29 @@ def test_set_breakpoints(kernel_with_debug):
115130
"sourceModified": False,
116131
},
117132
)
118-
assert reply["success"]
119-
assert len(reply["body"]["breakpoints"]) == 1
120-
assert reply["body"]["breakpoints"][0]["verified"]
121-
assert reply["body"]["breakpoints"][0]["source"]["path"] == source
133+
if debugpy:
134+
assert reply["success"]
135+
assert len(reply["body"]["breakpoints"]) == 1
136+
assert reply["body"]["breakpoints"][0]["verified"]
137+
assert reply["body"]["breakpoints"][0]["source"]["path"] == source
138+
else:
139+
assert reply == {}
122140

123141
r = wait_for_debug_request(kernel_with_debug, "debugInfo")
124142

125143
def func(b):
126144
return b["source"]
127145

128-
assert source in map(func, r["body"]["breakpoints"])
146+
if debugpy:
147+
assert source in map(func, r["body"]["breakpoints"])
148+
else:
149+
assert r == {}
129150

130151
r = wait_for_debug_request(kernel_with_debug, "configurationDone")
131-
assert r["success"]
152+
if debugpy:
153+
assert r["success"]
154+
else:
155+
assert r == {}
132156

133157

134158
def test_stop_on_breakpoint(kernel_with_debug):
@@ -139,7 +163,11 @@ def test_stop_on_breakpoint(kernel_with_debug):
139163
f(2, 3)"""
140164

141165
r = wait_for_debug_request(kernel_with_debug, "dumpCell", {"code": code})
142-
source = r["body"]["sourcePath"]
166+
if debugpy:
167+
source = r["body"]["sourcePath"]
168+
else:
169+
assert r == {}
170+
source = "some path"
143171

144172
wait_for_debug_request(kernel_with_debug, "debugInfo")
145173

@@ -157,6 +185,10 @@ def test_stop_on_breakpoint(kernel_with_debug):
157185

158186
kernel_with_debug.execute(code)
159187

188+
if not debugpy:
189+
# Cannot stop on breakpoint if debugpy not installed
190+
return
191+
160192
# Wait for stop on breakpoint
161193
msg: dict = {"msg_type": "", "content": {}}
162194
while msg.get("msg_type") != "debug_event" or msg["content"].get("event") != "stopped":
@@ -175,7 +207,11 @@ def f(a, b):
175207
f(2, 3)"""
176208

177209
r = wait_for_debug_request(kernel_with_debug, "dumpCell", {"code": code})
178-
source = r["body"]["sourcePath"]
210+
if debugpy:
211+
source = r["body"]["sourcePath"]
212+
else:
213+
assert r == {}
214+
source = "some path"
179215

180216
wait_for_debug_request(kernel_with_debug, "debugInfo")
181217

@@ -193,6 +229,10 @@ def f(a, b):
193229

194230
kernel_with_debug.execute(code)
195231

232+
if not debugpy:
233+
# Cannot stop on breakpoint if debugpy not installed
234+
return
235+
196236
# Wait for stop on breakpoint
197237
msg: dict = {"msg_type": "", "content": {}}
198238
while msg.get("msg_type") != "debug_event" or msg["content"].get("event") != "stopped":
@@ -216,15 +256,21 @@ def test_rich_inspect_not_at_breakpoint(kernel_with_debug):
216256
def func(v):
217257
return v["name"]
218258

219-
assert var_name in list(map(func, r["body"]["variables"]))
259+
if debugpy:
260+
assert var_name in list(map(func, r["body"]["variables"]))
261+
else:
262+
assert r == {}
220263

221264
reply = wait_for_debug_request(
222265
kernel_with_debug,
223266
"richInspectVariables",
224267
{"variableName": var_name},
225268
)
226269

227-
assert reply["body"]["data"] == {"text/plain": f"'{value}'"}
270+
if debugpy:
271+
assert reply["body"]["data"] == {"text/plain": f"'{value}'"}
272+
else:
273+
assert reply == {}
228274

229275

230276
def test_rich_inspect_at_breakpoint(kernel_with_debug):
@@ -235,7 +281,11 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
235281
f(2, 3)"""
236282

237283
r = wait_for_debug_request(kernel_with_debug, "dumpCell", {"code": code})
238-
source = r["body"]["sourcePath"]
284+
if debugpy:
285+
source = r["body"]["sourcePath"]
286+
else:
287+
assert r == {}
288+
source = "some path"
239289

240290
wait_for_debug_request(
241291
kernel_with_debug,
@@ -253,6 +303,10 @@ def test_rich_inspect_at_breakpoint(kernel_with_debug):
253303

254304
kernel_with_debug.execute(code)
255305

306+
if not debugpy:
307+
# Cannot stop on breakpoint if debugpy not installed
308+
return
309+
256310
# Wait for stop on breakpoint
257311
msg: dict = {"msg_type": "", "content": {}}
258312
while msg.get("msg_type") != "debug_event" or msg["content"].get("event") != "stopped":
@@ -304,7 +358,11 @@ def my_test():
304358

305359
# Init debugger and set breakpoint
306360
r = wait_for_debug_request(kernel_with_debug, "dumpCell", {"code": code})
307-
source = r["body"]["sourcePath"]
361+
if debugpy:
362+
source = r["body"]["sourcePath"]
363+
else:
364+
assert r == {}
365+
source = "some path"
308366

309367
wait_for_debug_request(
310368
kernel_with_debug,
@@ -323,6 +381,10 @@ def my_test():
323381
# Execute code
324382
kernel_with_debug.execute(code)
325383

384+
if not debugpy:
385+
# Cannot stop on breakpoint if debugpy not installed
386+
return
387+
326388
# Wait for stop on breakpoint
327389
msg: dict = {"msg_type": "", "content": {}}
328390
while msg.get("msg_type") != "debug_event" or msg["content"].get("event") != "stopped":

0 commit comments

Comments
 (0)