Step by step debugging

Does anyone have a workflow or a workaround in order to use a debugger while running plugins ?
It would be really great to be able to jump in the process() code with pdb or pudb…

What happens when you try?

Here is the log of pdb when setting a trace in a collector plugin:

Processing CollectSingleFilesInCwd
> <string>(26)process()
(Pdb) l

I have a similar issue with pudb where it suggests to use inline_cache module…

Ah, I can’t tell for sure, but my guess is it’s having trouble following a command that doesn’t have a file associated to it. You see when plug-ins are discovered on disk, they are loaded as a block of text, rather than imported directly. This is how they are able to reload themselves interactively. It’s possible this throws off any debugger.

Try running it with a simpler program, like this one.

from pyblish import api, util

class MyPlugin(api.ContextPlugin):
  order = api.CollectorOrder
  def process(self, context):
    context.create_instance("MyInstance")"Hello world")


This won’t do any of the discovery magic, but rather just run the class as declared.

For the moment as I need more the debugging than the autoreload, I’ve switched to using imp module to load the plugins from source. Here is a snippet of my updated code (imp is imported first):

    module = imp.load_source(mod_name, abspath)
except Exception as err:
    log.debug("Skipped: \"%s\" (%s)", mod_name, err)

Is the autoreload a functionality used within the UI only ?
Would it be interesting to have the ability to switch between the two loading modes ? Using an env var or an argument to

Yes, that could be interesting. If you’re up for it, I’d be happy to consider PYBLISH_AUTORELOAD as a good canditate for an environment variable.

Did the debugger work with that?

Yep it works like a charm… (python-2.7.5)

I don’t know if imp the correct goto as it might be replaced with importlib with >2.7. We just need to be careful not to have different behaviours with different pythons…

Also there might be some optimisation in loading precompiled python if found in the folder.