https://pantsbuild.org/ logo
#development
Title
# development
b

bitter-ability-32190

06/08/2022, 4:50 PM
So this is huge... I just started poking at Microsoft's DAP for editor-agnostic debugging and turns out it would be trivial to get working (at least for Python, likely easy for other languages). What does this mumbo jumbo mean? YOU CAN USE IN-EDITOR BREAKPOINTS TO DEBUG YOUR CODE/TESTS RUN BY PANTS! It's quite trivial to support too! See 🧵
(Focusing on Python because that's where I am 🙂) So turbo speed-run on DAP: Generic protocol Editors can opt into to allow language-agnostic debugging experience. Then lagnuage-specific server does the language-specific finagling under the hood. Python's DAP is
debugpy
: https://github.com/microsoft/debugpy So essentially there's two halves: • A
debugpy
server must be launched with the relevant code running • Your Editor (like VS Code) connects to it via a client, and sends the breakpoint and other info to it. So if you wanted to do this today (try it!) Put the following at the top of your code:
Copy code
import debugpy
debugpy.listen(5678)  # Thats the port, localhost by debugpy.wait_for_client()
Running your code (
./pants test --debug
or
./pants run
) then launches the server and waits for connection. In your editor pick the "remote attach" option using the right port. Then F5 to launch the debugger. This connects to the server and tells it the current debugging info (breakpoints and other settings). 🎉
What does this have to do with Pants?
We can add an option to Pants to launch the relevant DAP when requested, so no code instrumentation is needed.
debugpy
comes with a "launched" out of the box for this. So (and details to be discussed)
./pants debug <spec>
would run your code with the DAP server launched and waiting for a connection.
I gotta get a PoC going, we can figure out the right CLI sauce though
w

witty-crayon-22786

06/08/2022, 4:59 PM
very nice!
DAP is lightly related to BSP, as it is the protocol supported by `debugSession/start`: https://build-server-protocol.github.io/docs/specification.html#debug-request
1
we don’t support it yet for Scala, but we’d like to
b

bitter-ability-32190

06/08/2022, 5:01 PM
In this case, I think it can be done seprately. In this instance I'm happy to tackle Python because of how easy it is
w

witty-crayon-22786

06/08/2022, 5:01 PM
bsp is launched via
experimental-bsp
… so
experimental-dap
might be a good parallel
b

bitter-ability-32190

06/08/2022, 5:06 PM
One goofy bit is ambiguity between
run
and
test
.
./pants dap path/to/test_file.py
should probably run the file like the test goal, but with my proposal might be ambiguous
An alternative is to add
--use-dap
to
run
and
test
w

witty-crayon-22786

06/08/2022, 5:07 PM
yea. fwiw:
test
has
--debug
, which supports conditionally adding additional arguments
b

bitter-ability-32190

06/08/2022, 5:08 PM
Yeah thats what you need to do to (cleanly, you dont have to) get this working with the instrumentation
w

witty-crayon-22786

06/08/2022, 5:09 PM
…correction. the conditional additional arguments are JVM specific. so that’s more of a convention. but: when you set
--debug
, the JVM code adds
[jvm] debug_args
: https://www.pantsbuild.org/docs/reference-jvm#section-debug-args
b

bitter-ability-32190

06/08/2022, 5:11 PM
Yeah I think it could be as simple as
--debug-dap
(or similar) flags. I think we'd wanna compare Python's "drop-in" ability to maybe Java's or GO's DAP
w

witty-crayon-22786

06/08/2022, 5:23 PM
yea, good idea.
b

bitter-ability-32190

06/08/2022, 9:05 PM
So thinking about this,
debugpy
need to be launching the python script/module which makes it conflict a bit with the pytest PEX. I'm gonna have to finagle this one
w

witty-crayon-22786

06/09/2022, 9:24 PM
woot!
b

bitter-ability-32190

06/13/2022, 7:32 PM
Bump on the PR. I'd like another set of eyes before I make the same change to
--run
👍 1
w

witty-crayon-22786

06/13/2022, 8:46 PM
looks good!