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

Allow server to configure its root #1130

Open
thejcannon opened this issue Nov 17, 2022 · 6 comments · May be fixed by fabioz/PyDev.Debugger#243
Open

Allow server to configure its root #1130

thejcannon opened this issue Nov 17, 2022 · 6 comments · May be fixed by fabioz/PyDev.Debugger#243
Labels
enhancement New feature or request P1

Comments

@thejcannon
Copy link

In the Pants project we're facing an issue where we can't set breakpoints on files when running some code, and it boils down to the remoteRoot being CWD but code is running in a tempr sandbox.

To give an overview of the workflow here:

  • User tells pants to run their code and launch a debug server
  • Pants creates a sandbox in /tmp/... with all the code laid out
  • Pants launches the debug server (using debugpy) and waits for connection
    • CWD of the process is the user's code root
  • User connects but since the remote root is configured as "." which isn't the tempdir breakpoints relative to the code root aren't loaded

You could say "OK, the user should be setting the pathMapping", which would be annoying at the least, but is ultimately impossible as the sandboxes (the tempdir) is ephemeral, fresh, and distinct per run.

I suspect what I really want is to allow the server to (somehow) specify it's "root" when being invoked (which in this case would be the sandbox tempdir)

@fabioz
Copy link
Collaborator

fabioz commented Nov 17, 2022

If paths are ephemeral and you can't pre-configure them to apply path mappings, maybe you could use an API which would collect the paths and runtime and set the mapping for the debugger?

See: #743 (comment) for how to do that.

@fabioz
Copy link
Collaborator

fabioz commented Nov 17, 2022

I was also thinking that maybe having the path mapping allow for environment variables set in the server could potentially be a solution here too (so, you could have an environment variable resolved in the server as a part of the path mapping resolution) -- note that this isn't implemented at this point.

@thejcannon
Copy link
Author

so, you could have an environment variable resolved in the server as a part of the path mapping resolution

So that'd be relevant here?

@fabioz
Copy link
Collaborator

fabioz commented Nov 17, 2022

so, you could have an environment variable resolved in the server as a part of the path mapping resolution

So that'd be relevant here?

Yes.

@thejcannon
Copy link
Author

See: #743 (comment) for how to do that.

Ah hey that works, thanks! I'd still advocate for a env var, as thats much easier.

@thejcannon
Copy link
Author

thejcannon commented Nov 17, 2022

OK I actually did something slightly different:

import debugpy._vendored.force_pydevd
from _pydevd_bundle.pydevd_process_net_command_json import PyDevJsonCommandProcessor
orig_resolve_remote_root = PyDevJsonCommandProcessor._resolve_remote_root

def patched_resolve_remote_root(self, local_root, remote_root):
    if remote_root == ".":
        remote_root = CHROOT
    return orig_resolve_remote_root(self, local_root, remote_root)

PyDevJsonCommandProcessor._resolve_remote_root = patched_resolve_remote_root

I didn't want to tell our users to omit pathMappings as that is the VS Code default. This way we assume "." means our sandbox root.

@int19h int19h added the enhancement New feature or request label Nov 21, 2022
@thejcannon thejcannon linked a pull request Dec 5, 2022 that will close this issue
@int19h int19h added the pydevd label Feb 1, 2023
@judej judej added P1 and removed pydevd labels Jan 3, 2024
@judej judej assigned debonte and unassigned debonte Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants