Hi folks, I'm trying to use `--debug-adapter` with...
# general
a
Hi folks, I'm trying to use
--debug-adapter
with a python target in VS Code at Pants version
2.16.0.dev5
. It starts up and connects ok, but in one of my projects it fails on importing a (generated) protobuf module. In another simple project breakpoints simply aren't hit. Both of these things seem to point to the debugger not being aware of the sandboxing. I tried adding
run_goal_use_sandbox=False,
to my target to no avail (which maybe wouldn't work with generated protobuf modules anyway?). If I revert to
2.14.0
things seem to work ok. Any ideas to try? @bitter-ability-32190
👀 1
b
Although that would only help if
run_goal_use_sandbox=False
For the other case, what's your
launch.json
pathMappings
look like?
a
i guess it's just the default: "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "." } ],
i added a print(os.getcwd()), it's indeed running in the repo root, not sandbox (regardless of using
run_goal_use_sandbox
or not). Without
--debug-adapter
it runs fine, but with it I get an import error not finding generated proto modules
b
So the linked PR should fix the issue with running in the repo/build root
I tested it in my work repo, and I also was able to step into paths only in the sandbox as well
a
do you mind trying a sample repo? https://github.com/jonas25007/pants-proto-test
./pants run --debug-adapter :run
breakpoints are hit with
2.14.0
but not
2.16.0.dev5
b
That PR is relatively new and isn't in a release yet, try using
PANTS_SHA=1767af454873dc26c66e3ef89306f733bb9ddcdd ./pants ...
a
ah ok, yeah that seems to fix the breakpoints in my simple project, but not the imports in my bigger one which I think is probably a separate issue. let me bang my head on the keyboard for a while
b
Feel free to dump all the relevant info here. Happy to help 🙂
Unfortunately all the "can I hit a breakpoint" tests are manual so far, because trying to fake the client server is... not feasible 😕
a
ah, I think it's an
__init__.py
thing. https://www.pantsbuild.org/docs/protobuf-python recommends adding empty
__init__.py
files, but that messes with debugging apparently
b
😐
Thats annoying if true. What's your thought process here? How'd you get to
__init__
being the issue?
a
that above repo I linked was working (and didn't have inits). Just a process of finding the differences between that and my other repo, as soon as I removed them from the other one it started working
(once I started using your fix, that is)
conversely, if I add inits to my little repo, it breaks (so have a repro)
b
Wow, well feel free to dump as much info in a ticket
e
If you rename the
proto
dir to - say `proto2`and update this dep correspondingly: https://github.com/jonas25007/pants-proto-test/blob/main/BUILD#L4 does that work? If so I'll leave you the pleasure of understanding why.
a
Sorry just saw this. Tried naming to proto2, does not work
e
@average-sugar-68948 the issue is there is a
proto/
dir on the
sys.path
both in the sandbox and in your local repo with
run_goal_use_sandbox=False
. Since there are two sources of the same package (
proto
), you need to be using namespace packages. You can either PEP-420, which is no
__init__.py
, or, if you need
__init__.py
, they must not be empty, but contain ns-package magic. For example, this works and debug breakpoints are hit:
echo "__path__ = __import__('pkgutil').extend_path(__path__, __name__)" > proto/__init__.py
, see: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
a
good to know, thanks! I'm happy with no init.py myself