DOC: Add chapter on how to debug a CLI with pdb
bzah opened this issue · comments
AFAIK, It is not documented how one can use the python standard debugger (pdb) with click. It is not so intuitive especially for new python developers so a page describing this would likely be useful.
I think there are multiple approaches to debug a click based cli, for example one can add breakpoint()
statements in the sources and rebuild it. I also found here that we can start python in interactive mode with the path to the generated cli and debug the last exception.
I'm willing to make this contribution to the documentation to add this chapter.
I don't really see this being relevant to Click specifically. "How to debug with PDB" is general, and is already well described in the official docs https://docs.python.org/3/library/pdb.html#module-pdb, including this part at the top that covers exactly what you're mentioning:
The typical usage to break into the debugger is to insert:
import pdb; pdb.set_trace()
Or:
breakpoint()
at the location you want to break into the debugger, and then run the program. You can then step through the code following this statement ...
I agree that breakpoints are well described in the pdb doc.
Regarding click use case, I would be interested to find in the doc how to debug a built CLI, which can be done with
python -i $(which my-click-cli) my-cli-arg
and import pdb; pdb.pm()
(or even better with ipython and %debug
).
This I find really useful and not that well documented.