<no subject>

PyCharm Pro 3.1.1 Trial (Windows 7)

I thought I would try to see if it was possible to debug Calibre plugins
using PyCharm Pro since Calibre uses an embedded Python 2.7 interpreter. My understanding is that this should be possible by setting up a Python
Remote Debug configuration. I did that and then added the following to my plugin's __init__.py file:

import sys
sys.path.append('../pycharm-debug-py3k.egg')
import pydevd
pydevd.settrace('localhost', port=12420, stdoutToServer=True, stderrToServer=True)
prettyPrint(); I have also set my project's Python Interpreter Paths to point at my calibre.zip I created to contain Calibre's python source files (its equivalent of a site-packages directory).

When I debug my configuration I see in the Console window:

   Starting debug server at port 12420
   Use the following code to connect to the debugger:
   import pydevd pydevd.settrace('localhost', port=12420, stdoutToServer=True, stderrToServer=True)
   Waiting for connection...


And when I run the following in an external command window:

   calibre-customize.exe -b .


to "install" my plugin using the source files from the current directory I get:


   pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)
   pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.
   pydev debugger: Related bug: http://bugs.python.org/issue1666807

   pydev debugger: Unable to find real location for: threading.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_comm.py
   pydev debugger: Unable to find real location for: calibre_plugins.count_pages.__init__
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_tracing.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\zipplugin.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\ui.py
   pydev debugger: Unable to find real location for: site.py


At this point the calibre-customize program hangs and I have to Control-C to stop it. And calibre-customize is just installing the program. To actually run it you have to use calibre-debug. [Edit: I should try putting the settrace() call somewhere else.]

And the Debugger Console window then says:

   Connected to pydev debugger (build 133.881)
   pydev debugger: Unable to find real location for: threading.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_comm.py
   pydev debugger: Unable to find real location for: calibre_plugins.count_pages.__init__
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_tracing.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\zipplugin.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\ui.py
   pydev debugger: Unable to find real location for: site.py


I should mention at this point that Calibre dynamically loads plugins, so that's why it's looking in calibre_plugins.count_pages for my plugin. See here for details.

Okay, so I figured I had to set up some Path Mappings. In my case my "remote" machine is the same as the machine that is running PyCharm. Here's some of what I tried. If I map local:

   <AbsolutePathTo>/Count Pages/__init__.py


to remote:

   calibre_plugins.count_pages.__init__


and try again, I then see in the command window (omitting the same CRITICAL WARNING that never seems to change):

   pydev debugger: Unable to find real location for: calibre_plugins.count_pages.__init__
   pydev debugger: warning: trying to add breakpoint to file that does not exist: calibre_plugins.count_pages.__init__
    (will have no effect)
   pydev debugger: Unable to find real location for: threading.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_comm.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_tracing.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\zipplugin.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\ui.py
   pydev debugger: Unable to find real location for: site.py


and the debugger console shows:

   Connected to pydev debugger (build 133.881)
   pydev debugger: Unable to find real location for: threading.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_comm.py
   pydev debugger: Unable to find real location for: ..\pycharm-debug-py3k.egg\pydevd_tracing.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\zipplugin.py
   pydev debugger: Unable to find real location for: site-packages\calibre\customize\ui.py
   pydev debugger: Unable to find real location for: site.py


So at least the Debugger Console window now stops complaining about __init__.py and the command window says something different than before.

The site-packages\calibre\ things it is complaining about are in my calibre.zip that I have added to my project interpreter's Paths.

I've also tried the same and other permutations for the other items with no success. Can someone tell me what Path Mappings I should be using?

Please sign in to leave a comment.