Saturday, August 5, 2017

Debugging Dependencies of Django Project in Eclipse

This is another one of those posts to help myself in the future.  I've got some legacy python projects whose directions only get you a django app running in a virtualenv within eclipse but the dependencies themselves are not debuggable.

It was straightforward once I found the right advice.

If you're like me and have a build that creates a virtualenv with everything installed already by pip and a requirements.txt file.  Here's how to get the environment and eclipse changed so that you can debug any dependency.

#Step 1.  Remove the dependencies files from the virtualenv


This works for mac and uninstalls files that might have spaces in them too
python setup.py install --record files.txt
# inspect files.txt to make sure it looks ok. Then:
tr
'\n' '\0' < files.txt | xargs -0 sudo rm -f --

I figured that out after a few different attempts and the best way to do it came from StackOverflow here:  https://stackoverflow.com/a/25209129

 

#Step 2. Add the source folder as an external build dependency on the Python Interpreter Path


Add source folder to eclipse for debugging dependency

 

 

 

 

 

Credit for this step goes to a small sentence buried here:  https://lukeplant.me.uk/blog/posts/eclipse-pydev-and-virtualenv/

 

That's it.  Restart your django server and set a breakpoint inside that internal dependency.

This will save you a ton of time vs. all those import pdb; pdb.set_trace() statements

Drawbacks


This will break the virtualenv from the command line so for things like python manage.py commands.  For those items, I went ahead and set up a second virtualenv.

No comments:

Post a Comment