Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the debugpy adapter over tramp? #143

Open
jsadusk opened this issue Aug 24, 2024 · 4 comments
Open

How to use the debugpy adapter over tramp? #143

jsadusk opened this issue Aug 24, 2024 · 4 comments

Comments

@jsadusk
Copy link

jsadusk commented Aug 24, 2024

Deleting my previous issue because I have a working config, it is just very manual and I'm trying to figure out if there's a way to do this automatically.

Here's my use case. I am developing python, remotely via tramp over ssh, and my python is being launched by the bazel build system. This has a few implications:

  • dape is unable to launch debugpy directly, because all launching is done by bazel run with a config option for debugpy. As a result, an attach config is necessary, and the debugpy config entry doesn't work
  • Since I am developing over ssh, the only way I can reach the debugpy port is using ssh port forwarding, so dape needs to connect to localhost
  • Source paths to place the marker need to be prefixed by the tramp prefix for the current project
  • Bazel has the lovely behavior that it doesn't launch code directly from the project directory, it makes a sandbox directory and symlinks python source back to it. Dape needs to map paths from the sandbox back to the source dir

Given all this, I was able to make dape work, beautifully I might add, with this config:

(add-to-list 'dape-configs
     '(debugpy-attach .
           (modes (python-mode python-ts-mode)
                  port 5678
                  host "localhost"
                  :request "attach"
                  :type "python"
                  :cwd dape-cwd
                  :program dape-buffer-default
                  :args []
                  :justMyCode nil
                  :console "integratedTerminal"
                  :showReturnValue t
                  :stopOnEntry nil
                  prefix-local "/ssh:dev:/home/jsadusk/my/project/dir/"
                  prefix-remote "/data/jsadusk/cache/bazel/_bazel_jsadusk/08376eed31abaac569ecaec66be8adad/execroot/waabi-av/bazel-out/k8-opt/bin/my-bazel-run/-arget.runfiles/base-path/"
                  )
           )
     )

(paths are not real for security reasons)

Setting prefix-local and prefix-remote made everything work. But there's no reason those can't be automatically determined.
First, /ssh:dev: is in the project root, but it looks like dape--path doesn't make use of the project dir.
Second, the file returned by the debugger inside the sandbox is a symlink. I think if dape-path followed symlinks it would be able to resolve this easily.

Does this seem like a reasonable enhancement? I may try to make a PR myself to do this if you don't mind.

@jsadusk
Copy link
Author

jsadusk commented Sep 4, 2024

I submitted a PR to fix this: #148

@jsadusk
Copy link
Author

jsadusk commented Sep 4, 2024

My PR doesn't actually work, because it prevents mapping from local back to remote. "Remote" files in this context are symlinks in a bazel cache for a specific run target, local files are in the project repo. I am not sure how to find a mapping back from a project repo file to the bazel cache in an automatic fashion. However each separate run target gets its own sandbox directory, so putting a remote prefix in a config is not feasible. I'm searching for a way to build a good bazel config. The portion of the above PR that adds tramp prefix does seem to be good however.

@svaante
Copy link
Owner

svaante commented Sep 11, 2024

Which version of dape are you using?

Dape detects if command-cwd is by tramp and sets prefix-local prefix-remote.
This is done in dape-config-tramp I am not sure why this does not work in your case.

@jsadusk
Copy link
Author

jsadusk commented Sep 11, 2024

I'm looking at the code and I think the issue is I'm trying to do an attach to an already running debugpy, so it doesn't look like command-cwd gets set:
https://github.com/svaante/dape/blob/master/dape.el#L92

Also, because I'm trying to work with bazel's insane sandbox directory, I'm setting prefix-local and prefix-remote, which I think prevents that auto set.

Aside, would it be possible to make prefix-local and prefix-remote be lambdas? I'm struggling with making an automatic way to determine the sandbox directory path conversion with a simple string replacement.

Oh and I currently have dape master checked out in my straight repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants