Currently, if a python script is executed directly as a subprocess by using a shebang, it isn't debugged.
This is clear from the code which is currently only checking the executable name for python and family.
|
for name in _get_str_type_compatible(filename, ["python", "jython", "pypy"]): |
Looking at pydevd logs, it exits with "Process is not python, returning." as expected from the code.
|
pydev_log.debug("Process is not python, returning.") |
Not simple, but IIUC fixing this means that it should open the file, check for a shebang, and replace the executable with the shebang line + script location. I'm uncertain if only patch_args needs to be updated with such logic or every caller of is_python.
Note I don't create the script myself but use project.scripts, and uv_build compiles the script wrapper when running uv sync. A manually shebanged file would naturally have the same issue though is easier for the user to replace with a python invocation - with a project.scripts, there is some awkwardness with it being in the .venv/bin directory, not cwd (I am using a multi-project workspace). As a workaround, I will probably still resolve the absolute path of the script and prepend python.
Environment data
Skipping since it's obvious from the code
Actual behavior
debugpy does not patch the subprocess args for a python script, causing debug to fail
Expected behavior
A python script subprocess can be debugged
Steps to reproduce:
- Create a python script with a shebang
- Create another script that invokes the script directly with
subprocess.run, without python
- Debug the launcher script with a breakpoint in the shebang script
My shebang script for a django project created by uv looks like
manage
#!/Users/anuraag/git/workspace/.venv/bin/python3
# -*- coding: utf-8 -*-
import sys
from sysadmin.manage import main
if __name__ == "__main__":
if sys.argv[0].endswith("-script.pyw"):
sys.argv[0] = sys.argv[0][:-11]
elif sys.argv[0].endswith(".exe"):
sys.argv[0] = sys.argv[0][:-4]
sys.exit(main())
Currently, if a python script is executed directly as a subprocess by using a shebang, it isn't debugged.
This is clear from the code which is currently only checking the executable name for
pythonand family.debugpy/src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py
Line 283 in ea1dd9a
Looking at pydevd logs, it exits with "Process is not python, returning." as expected from the code.
debugpy/src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py
Line 394 in ea1dd9a
Not simple, but IIUC fixing this means that it should open the file, check for a shebang, and replace the executable with the shebang line + script location. I'm uncertain if only
patch_argsneeds to be updated with such logic or every caller ofis_python.Note I don't create the script myself but use
project.scripts, anduv_buildcompiles the script wrapper when runninguv sync. A manually shebanged file would naturally have the same issue though is easier for the user to replace with apythoninvocation - with aproject.scripts, there is some awkwardness with it being in the.venv/bindirectory, notcwd(I am using a multi-project workspace). As a workaround, I will probably still resolve the absolute path of the script and prepend python.Environment data
Skipping since it's obvious from the code
Actual behavior
debugpy does not patch the subprocess args for a python script, causing debug to fail
Expected behavior
A python script subprocess can be debugged
Steps to reproduce:
subprocess.run, withoutpythonMy shebang script for a django project created by uv looks like
manage