Question about debugging in VSCode. I set up a Py...
# general
a
Question about debugging in VSCode. I set up a Python: Remote Attach VSCode configuration and launched my app with
pants run --debug-adapter apps/python/example_app/app.py
which launches and waits with
Launching debug adapter at '127.0.0.1:5678...'
I then started the remote attach config. The program continues and prints to the VSCode Debug Console but does not stop on break points. So I tried PyCharm and was able to successfully debug by hosting a debug server and including in my python code:
Copy code
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=5150, stdoutToServer=True, stderrToServer=True)
It does not map to the original source file but I'm able to step through with the debugger in PyCharm. I then tried to get VSCode working and found that with the above
pydevd_pycharm
code in place, I can debug in VSCode as well. It also does not map to the original source file but I can connect to the remote session and step through the code. If I remove or comment the
pydevd_pycharm
code, I see the original behavior where the console messages print to the debug console but execution is not halted. Thoughts on what I may be missing?
h
I’ll defer to @bitter-ability-32190 on this. I always use
pydevd_pycharm
(with PyCharm) and it works like a, um, charm…
b
I recently fixed a bug, which this sounds like. Can you try with bleeding edge Pants?
a
I’ll try that tomorrow and let you know! Thanks.
b
The razor is: what are your source roots
Oh wait, you can just use PANTS_SHA since this was merged: https://www.pantsbuild.org/docs/manual-installation
Oh and the issue at Play behind all this is that the "server" is running with CWD set to your build root, but sources from the sandbox. So the path mappings that the client provides are essentially impossible to configure. Hence no breakpoints get hit
a
I was able to run using
PANTS_SHA=008fe0940bf1e870334d4f2dbe7cbf295f15c607 ./pants --version
That's the latest hash from https://github.com/pantsbuild/pants/tree/2.15.x where https://github.com/pantsbuild/pants/issues/17540 was merged. It does not map to the source file so break points aren't hit. I can, however, halt in code and attach as before, and step through the sandbox source. I see the message
Copy code
0.00s - pydev debugger: unable to find translation for: "/private/var/folders/_d/zt8y2x055597l63bhdztp82c0000gn/T/pants-sandbox-4suXBa/apps/python/example_app/app.py" in ["/Users/russellzarse/dev/optios/monorepo_example/", "/Users/russellzarse/dev/optios/monorepo_example"] (please revise your path mappings).
My
.env
file contains
Copy code
PYTHONPATH="./.:./apps/python/example_app:./apps/python/monorepo_util/src:./libraries/python/another_library:./libraries/python/content_module/src:./libraries/python/quoteoftheday:$PYTHONPATH"
My understanding of the docs at [Setting up an IDE](https://www.pantsbuild.org/docs/setting-up-an-ide#first-party-sources) is that the
PYTHONPATH
is picked up from the
.env
file by vsCode. Is there another place where path mappings is configured?
b
There's a very good chance this needs additional massaging on Mac. The error line you mention is perplexing as none of the values configured appear to be the chroot. Two questions just for background: • What's your
source_roots
set to? • Is your VS Code
launch,json
sending
pathMappings
? If so, what are they?
a
Copy code
> ./pants roots
14:23:18.84 [INFO] Initialization options changed: reinitializing scheduler...
14:23:19.55 [INFO] Scheduler initialized.
.
apps/python/example_app
apps/python/monorepo_util/src
libraries/python/another_library
libraries/python/content_module/src
libraries/python/quoteoftheday
VSCode launch.json Config
Copy code
{
  "name": "Python: Remote Attach",
  "type": "python",
  "request": "attach",
  "connect": {
    "host": "localhost",
    "port": 5678
  },
  "pathMappings": [
    {
      "localRoot": "${workspaceFolder}",
      "remoteRoot": "."
    }
  ],
  "justMyCode": true
}