Skip to content

[FR]: Attaching debuggers to py_binary is difficult #539

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

Open
zfy0701 opened this issue Mar 16, 2025 · 2 comments
Open

[FR]: Attaching debuggers to py_binary is difficult #539

zfy0701 opened this issue Mar 16, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request need: discussion We have to do some design work in a meeting

Comments

@zfy0701
Copy link

zfy0701 commented Mar 16, 2025

What happened?

when use default debugger for py_binary

Image

the command generated is like:

/usr/local/bin/python3.12 -X pycache_prefix=/.../JetBrains/PyCharm2024.3/cpython-cache /Users/fuyaoz/Applications/PyCharm Professional Edition.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 55690 --file /.../server/server 

notice the last parameter /../server/server is a shell instead of python file, the debugger will fail here:

Image

switch back to official rules_python works

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.4.1

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: MODULE.bazel

Language(s) and/or frameworks involved: pyth

python plugin 1.0.0~ 1.3.2 behaviors similar

How to reproduce

Any other information?

No response

@zfy0701 zfy0701 added the bug Something isn't working label Mar 16, 2025
@thesayyn thesayyn added the need: discussion We have to do some design work in a meeting label May 2, 2025
@arrdem arrdem changed the title [Bug]: py_binary not compatible with pycharm/intellij's builtin debugger [FR]: Attaching debuggers to py_binary is difficult May 2, 2025
@arrdem arrdem added enhancement New feature or request and removed bug Something isn't working labels May 2, 2025
@arrdem
Copy link
Contributor

arrdem commented May 2, 2025

It's difficult to simultaneously support debuggers which want to supervise or control debuggee startup with the needs of configuring a hermetic Python interpreter.

I suspect this will soon be broken in rules_python upstream too if you turn on the new /bin/sh based launcher script and only happens to work using the old non-hermetic python3 based launcher shim. This will continue to not work post- #551 which again uses a shell-based launcher.

Probably the only way to harmonize the two would be to teach IDEA how to request Bazel build and run a configuration of a Python program which embeds the IDEA pydev helper and treats that helper as its entrypoint.

@jab
Copy link

jab commented May 3, 2025

@zfy0701, in case you can take a similar approach with PyCharm, in https://youtu.be/GTsy7IfmywQ?si=2eVPMRPLPySsjoQA&t=286 @alexeagle shows how to get VSCode's Python debugger to work with a rules_py project essentially by bypassing Bazel and just using the rules_py-generated virtualenv directly, which is not difficult.

You also may be interested in liking/subscribing to https://youtrack.jetbrains.com/issue/PY-63403/Support-debugpy which tracks adding support for debugpy to PyCharm. debugpy allows IDEs to set and hit breakpoints even for Python programs started via Bazel. I've tried it with VSCode and it works like a (wait for it) charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request need: discussion We have to do some design work in a meeting
Projects
None yet
Development

No branches or pull requests

4 participants