https://pantsbuild.org/ logo
#general
Title
# general
a

ancient-accountant-55836

11/14/2022, 4:20 AM
Hi everyone! 👋 Our startup is looking to switching our whole code base to use Pants. One issue we’ve been having is that we’ve been unable to figure out the correct way to get the debugger to work for FastAPI. I created a sample project here to give an example of what we’re trying to do. When I run
./pants run --debug-adapter src/python/greeter/main.py
, I can successfully connect through
Python: Remote Attach
in Visual Studio Code. However, when I set a breakpoint on line 9 of
/src/python/greeter/main.py
and try to visit
localhost:8000/
in my browser, the breakpoint is never activated. I see output in both my terminal and the debug console but the breakpoint is just never activated. Any help would be greatly appreciated, thanks!
👋 2
Example:
h

happy-kitchen-89482

11/14/2022, 7:16 AM
cc @bitter-ability-32190, since alas I am not too familiar with VS Code, more of a PyCharm guy (but I do know how to get remote debugging working on that IDE…)
👍 1
b

bitter-ability-32190

11/14/2022, 1:22 PM
It's been a bit since I worked on this, so bear with me. Two things come to mind: • File paths have to roughly match. I remember some issues with paths when I was implementing and testing the feature. Are you using source roots? • Debugpy has verbose logging. You can add --debugpy-args=... And pass extra flags to debugpy (I'll look up the flags when I'm on desktop)
a

ancient-accountant-55836

11/14/2022, 4:49 PM
@bitter-ability-32190 No problem! I tried explicitly adding source roots here and it still looks like it is not working for me. I’m new to Pants so I’m not sure if I configured everything properly
b

bitter-ability-32190

11/14/2022, 4:52 PM
It should be pretty plug-n-play
👍 1
I'll try and take a look when I can
Arg yeah it's a path issue.
a

ancient-accountant-55836

11/14/2022, 5:24 PM
Gotcha, so does that mean you were able to get it to work and I made a mistake in my project config?
I just confirmed in the
pycharm
branch of the repo I linked to that I can get it to work in Pycharm
b

bitter-ability-32190

11/14/2022, 5:24 PM
No, it's shortcoming of the Pants code
Essentially, the debug server is using the sandbox path and isn't able to cross-correlate the with "in-repo" path
If you crack open the sandbox in VS Code and set breakpoints, they get hit
Although it occurs to me, if you stop using the sandbox altogether it'll work
So: • Set that in your
pants.toml
• Use the CLI flag/env var: ``--python-default-run-goal-use-sandbox` or ``PANTS_PYTHON_DEFAULT_RUN_GOAL_USE_SANDBOX=1` • Set it on the target:
python_sources(run_goal_use_sandbox=False)
@happy-kitchen-89482 We'll have to remember this for next time. @ancient-accountant-55836 I'd love if using the sandbox still worked. Mind filing an issue?
a

ancient-accountant-55836

11/14/2022, 5:59 PM
@bitter-ability-32190 For sure, I will include a link to this slack thread Pardon my ignorance, but is what you’re saying is that by default Pants tries to use a sandbox (temporary directory) and that is what is causing path issues in this case for VS Code debugging?
Thanks for your help!
b

bitter-ability-32190

11/14/2022, 6:00 PM
Yup! You got it. Eventually we plan to swap the default
h

happy-kitchen-89482

11/14/2022, 7:19 PM
Maybe docs update and a blog post, instead of memory? 🙂
👆 1
💯 1
b

bitter-ability-32190

11/14/2022, 7:28 PM
Well when time permits I'd rather just find out if we can cajole debugpy into doing it right in the sandbox too 😛
b

busy-vase-39202

11/14/2022, 11:06 PM
For now, let's publish whatever allows people to be productive, even if it's not perfect. We can publish the more optimal solution when it's available, but let's not sit on a solution that's minimally viable.
Given that when people evaluate Pants they make decisions based in part on how well it meshes with existing workflows, being able to check off "we can continue to use VS Code" can be a make-or-break point (pardon the pun).
b

bitter-ability-32190

11/14/2022, 11:11 PM
Well since I'm likely doing the work, might be worth just making it work first. Then blogging about it later. After all I love me some coding
b

busy-vase-39202

11/14/2022, 11:18 PM
Meantime, a quick update to the docs? A tip box or something?
a

ancient-accountant-55836

11/15/2022, 3:12 AM
@busy-vase-39202 Not sure if it’s helpful at all, but that was the case for our team. Since our team is smaller, the code base is relatively young, and the majority of our team uses VS Code, it was a big sticking point for us to decide if we should migrate to Pants if we couldn’t use our existing debugging workflow. We almost decided not to, but then we were able to find this solution and we are greatly relieved.
🎉 3
❤️ 2
b

bitter-ability-32190

11/15/2022, 10:43 AM
Early next year I'm hoping to get to spend much more time on making VS Code + Pants very friendly
🎉 2
❤️ 2
Got it working with some, uh, creative monkeypatching https://github.com/pantsbuild/pants/pull/17566
5 Views