Visual Debugger for pythonista [share]
I have been toying with various ideas for a pythonista debugging system for a long time, to replace pdb in the console. With ObjC, we can finally integrate this into the editor itself.
Here is a working, albeit not yet complete, visual debugger. right now it supports stepping in/over/continue/quit, as well as a Locals/Globals display (read only right now).
I have separately working an overlay system for setting breakpoints by tapping the line number, though this is not yet fully baked and is not integrated into the main class yet (see inwork folder) I think I want to also go back to my older line highlight method (currently using editor annotations, but the "warning" is not overridable and interferes with the interface a bit)...
Anyhoo, here's the Readme/install/screenies:
interactive debugger inside pythonista editor
- single stepping, or step over
- continue, or quit
- watch window (view only right now)
- During debugging, current line is highlighted, and editor opens new file if needed
- breakpoint set/clear by tapping line s
- launch script via menu
- stack up/down
- help menu
- optimizations for small devices
usage (where debugging is needed)
import vdb vdb.VDB().set_trace()
Thanks to @ywangd for this method.
import requests as r; exec r.get('https://raw.githubusercontent.com/jsbain/vdb/master/get_vdb.py').text
I like ObjC heavy code. It's always worth learning. Thanks for sharing.
PS: you may wanna mention it requires the beta.
@JonB , hmmm, I am back 😱
Sorry, it's not working for me. I assume it works for Pythonista v2 beta.
Is installed. But not sure why. If I don't run your test vdb_test.py, the import module can not find module vdb in other files.
Then when I use it even in your vdb_test.py I never get to see the ui View.
Some of the warning to the console
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 314, in 'calling callback function'
File "/var/mobile/Containers/Bundle/Application/956011B9-D2AE-4CA3-A416-47CD071AB988/Pythonista.app/Frameworks/PythonistaKit.framework/pylib/site-packages/objc_util.py", line 820, in OMMainThreadDispatcher_invoke_imp
retval = func(*args, **kwargs)
File "/private/var/mobile/Containers/Shared/AppGroup/A83A4237-28DA-41B4-AA91-84BC6770F30C/Documents/site-packages/vdb/debug_menu.py", line 44, in create_menu
@Phuket2 You are right about not able to import vdb. A
__init__.pyfile is needed to make vdb a module.
@ywangd , thanks. That fixed the import problem 👍
You are right, when I tested I simply ran the vdb_test script, which is in the same folder so worked. I suspect other things such as loading the step icon images only work when running from the folder, since I was lazy and didn't use absolute paths.
This was more of a proof of concept at this point. I spent an embarrasinly long amount of time working out how the Bdb interface would look so that it blocked for user interaction, yet was also cancelable using a KeyboardInterrupt.
@JonB , it's ok. I just wanted to try it. Will wait until you get time to update it
Awesome! will give it a go later, but I think things like this are important for thinking of pythonista as a full-fledged IDE.
I updated the repo to act as a package. Also,
import vdb vdb.set_trace()
should work, similar to the way pdb works.