Description
Context
When using python in a bazel sandbox (bazel run //python/target
), bazel symlinks the required files into a 'runfiles' sandbox. My approach to debugging is to run it under the debugger and make it wait for client to connect (formerly ptvsd, now I'm exploring switching to debugpy).
Once attached, breakpoints trigger, but open a copy of the file at the sandbox path (with some visual quirks, such as that breakpoints don't visually sync between both copies, see screenshot). This pollutes tabs and makes debugging messy, especially when doing complex debugging sessions that involve many files.
This screenshot shows both the double tabs issue, as well as they breakpoints visually not synchronizing between both copies of the same file.
With ptvsd
, there was a simple workaround for this issue, just add this to the launch.json debug config:
"pathMappings": [
{"localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}"}
],
This seemingly no-op mapping effectively solved this issue, presumably because as part of the path mapping, it canonicalizes the path (like os.path.realpath
in python, or readlink -f
in bash for macos and linux) in the process, causing breakpoints to cleanly trigger in the original files.
You might as yourself: why not just do this:
"pathMappings": [
{"localRoot": "${workspaceFolder}", "remoteRoot": "<sandbox_path>"}
],
This isn't tractable for 2 reasons:
- The bazel sandbox path has a random hash in it, so updating the path mapping accordingly for each workspace would be annoying
- The bazel sandbox symlinks individual files and the sandbox doesn't share the same folder structure as the workspace, i.e. files might be in some folder structure in the workspace, but are symlinked into a different folder structure in the sandbox. This means we'd need many pathmappings to get this to work and those will vary from bazel target to target. This is not manually doable in practice (unless solved programmatically perhaps).
I'd like to switch from ptvsd
to debugpy
, as debugpy has significantly better multiprocess handling. But this issue is a major blocker.
Environment data
- debugpy version: 1.5.0
- OS and version: Ubuntu 18.04 (accessed via remote ssh plugin from MacOS)
- Python version (& distribution if applicable, e.g. Anaconda): 3.9 (from apt: python3.9)
- Using VS Code or Visual Studio: VS Code
Actual behavior
- With
ptvsd
the pathmapping trick works to avoid opening sandbox copies of files. - With
dedubpy
the pathmapping trick does not work to avoid opening sandbox copies of files.
Expected behavior
I'd expect both to work. Either through the pathmappings trick, or through some other way such as introducing a new that canonicalizes
paths.
As I believe debugpy
was forked from ptvsd
, we could maybe compare code and see what tweak is needed to make the pathmappings trick work again.
Steps to reproduce:
I've created a small example environment in which this issue can easily be reproduced. Please open this folder as a workspace in vscode and follow the instructions in the readme.