When working on a python project with several dependencies, sometimes I want to see what's going on in one of the required packages. I don't use IDEs so the preferred method of debugging code inside of package dependencies is to grep for an entry point to that package inside of virtualenv, open the source file, add a debug point and re-run test suite or a script until the code hits the debug point. Figuring out what is the actual problem left as an exercise to the reader.
The main issue with the approach above is that when debug console gets activated, it doesn't print out any source code surrounding the debug point, I have to constantly switch between source editor and console hoping that the line printed out in the console matches file lines open in the editor.
A better approach is to clone the source package in question and then install it in the current virtual environment with regular install command.
(myproj)$ python setup.py develop
This solves the immediate problem of debugger not printing line numbers, instead of poking inside of files under virtualenv it's possible to open the files from cloned location. The drawback of this approach is that it still involves a few steps -- I need to figure out where the source package is located, clone it, then run the command.
(myproj)$ pip install -e .
I've been using command above as an alias for python setup.py develop for a while and assumed it's magical properties for that purpose, however these days pip automates a lot more. According to the man page of version 9.0.1, any path/url can be passed to the command.
-e,--editable <path/url> Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.
As well as installing any packages in development mode from local repositories, it's possible to install any remote packages from VCS, since pretty much any project on pypi has link to VCS this becomes a two step process:
- Lookup package name on pypi.python.org, and copy link to VCS
- run pip install -e <copied_link>
Pip Reference Guide | Pip Install | VCS Support section -- https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support
Automating entry function definition lookup with Sublime Text & Anaconda -- https://avolkov.github.io/linting-and-declaration-lookup-for-python-with-sublime-text-3.html