contributing debugpy integration to rules_python #3485
shayanhoshyari
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks to help from @rickeylev in the discussion in #3481 I was able to do a debugger integration running
bazel testorbazel runstraight in vscode. Since it uses debugpy I suspect PyCharm should also work.Here is a full example + demo: https://github.com/shayanhoshyari/issue-reports/tree/main/rules_python/vscode_debugger_v2
It only uses
RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGSfromrules_python(and not even the new--debuggerfeature).Are you interested in having this as an example, or part of docs, or any other way in rules_python? If so, I can take a stab.
More detail on how it works
Summary as a diagram
flowchart TD vscode["vscode (debugpy client)"]-->|configured in launch.json| launch_py["launch.py"] launch_py-->|"set RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS <br> based on pydev_monkey.patch_args()"| bazel["bazel run/test"] bazel --> py_binary["py_binary / py_test"] py_binary --> |"debugpy attach via patched entrypoint through RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS"| vscode py_binary --> |subprocess launch| subprocess subprocess --> |"debugpy attach via patched entrypoint through pdevd usual patching"| vscodeLaunch.json
{ "version": "0.2.0", "configurations": [ { "name": "Python: Bazel py run", "type": "debugpy", "request": "launch", "program": "./.vscode/debugpy/launch.py", "args": ["run", "${input:BazelArgs}"], "console": "integratedTerminal", "justMyCode": false, "env": { // Due to how Bazel sets things up justMyCode: true won't work, instead set this env var // Comment it out to get justMyCode: false "IDE_PROJECT_ROOTS": "${workspaceFolder}", }, }, { "name": "Python: Bazel py test", "type": "debugpy", "request": "launch", "program": "./.vscode/debugpy/launch.py", "args": ["test", "${input:BazelArgs}"], "console": "integratedTerminal", "justMyCode": false, "env": { // Due to how Bazel sets things up justMyCode: true won't work, instead set this env var // Comment it out to get justMyCode: false "IDE_PROJECT_ROOTS": "${workspaceFolder}", }, }, ], "inputs": [ { "id": "BazelArgs", "type": "promptString", "description": "Optional args to pass to executable as single string", }, ] }Launch.py - ran by launch.json, just needs a python (e.g. system python)
Beta Was this translation helpful? Give feedback.
All reactions