Let's start simple: There is of course logging. For good old printf-debugging.
import logging log = logging.getLogger('gajim.groupchat_control') log.debug(result)
In most files the first two lines for logging should already be present. The string 'gajim.groupchat_control' depends on the part of Gajim you're working with.
Starting Gajim with
gajim -l gajim=DEBUG will enable full debug logging, while
gajim -l gajim.groupchat_control=DEBUG will limit log output to that specific part of Gajim. Read more about log levels.
The IPython interface
Helpful to see Gajim internals at runtime. IPython interface is documented here.
An actual debugger!
If you have at least Python 3.7 you can just insert
somewhere in the code and it will drop you into the pdb debugger. You can find the documentation for that here. If you're using an older version of Python the command is not quite as convenient but it should still work. Just use
import pdb; pdb.set_trace()
An even nicer debugger: PyCharm
Getting PyCharm to work with Gajim is pretty easy. Just load the cloned folder as a project. Then:
Go to File -> Settings then Project: gajim -> Project Interpreter
Click on the gear in the top right icon and Add... to add a new interpreters
Select Existing environment and then choose
[...]/venv/bin/pythonin your virtual environment. This will get the right environment set up. Next we need to tell PyCharm how to launch Gajim.
Go to Run -> Edit Configurations.... There is sometimes a weird bug and this entry is disabled. In that case just hit Run -> Run... and then a window offering only Edit Configurations... should show up.
Hit the + on the top left and select Python and give it a nice name.
Also select the "launch.py" script for Script path: and put
-p testprofile -c ../config -s -l gajim=DEBUG"
into the Parameters: box.
That's it! Now you can explore the code and put breakpoints in it and then just hit the little bug button to run this configuration in debug mode and it will stop on your breakpoints and allow you to step.
python -m cProfile -s cumtime launch.py > stats.txt