Bug with settign breakpoints in discovered pyblish plugins #404
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
I encountered the issue that setting breakpoints in discovered plugins does not trigger that breakpoint. If the plugin has been registered manually, it will, but using
pyblish.api.discover()it will go past the breakpoint in the pluginHow to reproduce the problem
I have created a seperate repository with a small example. Essentially, you set a breakpoint inside a plugin that has been added to the plugin_path before. When running it in vscode with the provided .vscode settings, it should trigger a breakpoint. However it does not.
The reason for the bug
The import mechanism is not quite correct in the discover method.
In plugin.py we use six.exec_ on a raw bytestream. This does import the plugin, however, for each object inside the module, python typically generates a code method. When using the normal import statement, python compiles the code before running exec on it. Crucially, with that compile step it associates the code method with a file. When the code then triggers a breakpoint, the debugger knows in which file it does so and can halt the execution. With the current approach there is no file associated. I attached two screenshots
how it is right. now
how it should be
My research on this topic is backed by this article