Pdb++ and rlcompleter_ng
When hacking on PyPy, I spend a lot of time inside pdb; thus, I tried to create a more comfortable environment where I can pass my nights :-).
As a result, I wrote two modules:
- pdb.py, which extends the default behaviour of pdb, by adding some commands and some fancy features such as syntax highlight and powerful tab completion; pdb.py is meant to be placed somewhere in your PYTHONPATH, in order to override the default version of pdb.py shipped with the stdlib;
- rlcompleter_ng.py, whose most important feature is the ability to show coloured completions depending on the type of the objects.
To find more informations about those modules and how to install them, have a look at their docstrings.
It's important to underline that these modules are not PyPy specific, and they work perfectly also on top of CPython.
Comments
That's pretty impressive, but I think having to modify readline itself in order to do this is a little excessive. readline's completion capabilities are pretty limited. I wonder if there are any better alternatives that could be used with Python.
I have something similar set up for my Python prompt: https://bitheap.org/hg/dotfiles/file/tip/.pythonrc.py -- it allows completion and indentation, it persists command history with readline, and it prints documentation if you try to evaluate certain objects like functions, classes, and methods. It also pretty-prints output, but I'm still trying to tweak it so it's aware of the terminal width.
yes, I agree that having to modify readline is not too nice. I tried hard to avoid this but with bad luck :-/.
I suppose I could try to reimplement readline in Python, but I think it would be too much work; if you are aware of something already done, please let me know :-).
would this work be suitable to inclusion in the standard pdb module?. That would be awesome.
Thanks!
There is readline implementation on top of pyrepl in pypy already :) PyPy by default does not use readline, but just uses this.
Nice job antonio. I'd clean the code up, conform to new-style classes and proper MRO handling. I'd also think about refactoring some of those names and find something better suited. Overall, awesome job man.
This looks great. You've taken a step futher than my own attempts here:
https://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182
Two small comments though: it crashes on startup without the right config in ~/.pdbrc.py and once I got it started I see things like this when completing th tab:
^[[000;00m^[[00mtest^[[00m
but syntax highlighting seems to work perfectly. Thanks!
@Stephen: as described in the docs of rlcompleter_ng, to use colorized completion you need to use a patched version of readline, there is no chance to get it working without that.
Could you describe in more details what problem did you encounter with ~/.pdbrc.py, so that I can fix it, please?
Antonio - I created a minor patch for rlcompleter_ng.py which will allow it to run on both Python 2 and 3.
https://mikewatkins.ca/2008/12/10/colorized-interpreter/
I was disappointed that pdb++ doesn't work on Windows. Apparently it uses the `termios` module which is not available on Windows.