Mapping file paths for pdbtrack
I saw python-mode 6.0.8 was release two weeks ago, and that reminded me to look and see if my change was included. Turns out it was included in 6.0.6, released in April:
– files inside a virtual machine made visible for pdbtrack
That’s my contribution.
python-mode provides support for developing with Python in Emacs. One of its most powerful (and often unknown) features is pdbtrack. pdbtrack recognizes when you’re interacting with a Python Debugger (PDB) session within Emacs, and opens the relevant files for you as you step through the program. When you’re digging into something very deep (lots of calls on the stack) or very broad (using lots of supporting libraries), this is invaluable for providing perspective on “where” your program is.
At work we develop using a Vagrant-managed virtual machine. The source checkout is stored “locally” and exported to the virtual machine using NFS. That’s great for development — edit locally, run from within the virtual machine — but broke pdbtrack. When Python reported it was at a certain line of a certain file, it was referring to a file inside the virtual machine. When pdbtrack tried to find that path, it didn’t exist because Emacs was running outside the virtual machine. When I want to use pdbtrack I’m usually pretty confused and in need of perspective, so it’s a pretty important tool for me. So I decided to fix this.
Starting with python-mode 6.0.6, you can customize the
py-pdbtrack-filename-mapping
variable. This is an alist which maps paths
the Python interpreter sees to paths Emacs can see. If pdbtrack can’t find the
buffer to open directly, it checks this mapping to see if the file exists in a
different location. For example, my configuration has the following
customization:
'(py-pdbtrack-filename-mapping (quote
(("/home/vagrant/eventbritecore/" . "/Volumes/eb_home/work/eventbritecore/"))
))
Using Vagrant means we are able to develop on a configuration far closer to production than we would [easily] be able to otherwise. And starting with python-mode 6.0.6, I don’t have to give up pdbtrack to do that.