Deregister_plugin breaks loading of the file

Hi,
I’m trying to load plugins based on if UI is loaded or not
This is an example:

if not pyblish.api.registered_guis():
    pyblish.plugin.deregister_plugin(ValidateNegativeVolume)

I put this at the end of my module but for some reason debug info shows this message:
# DEBUG:pyblish.plugin:Ski
# pyblish.plugin : Skipped: “validate_model” (‘ValidateNegativeVolume’) #

Hi @sega_m, what results are you expecting? How are you registering the plug-in? What do you do to get that message? What GUI is registered?

Hi @marcus, i expect some plugins to skip validation when gui is not loaded
I register plugins by pyblish.plugin.register_plugin_path(“C:/pyblish_plugins”)
I’m using pyblish_qml gui

Ah, the problem is you’re registering a path, and deregistering a plug-in.

If you want to deregister a path, you should use deregister_plugin_path and if you want to deregister a plug-in, you need to also register a plug-in with register_plugin.

Thanks !
What if i will register plugins by both ways at the same time (e.g. i will add register_plugin at the end of the file ) will deregister_plugin work ? Or it still will load it by path ?

Plug-ins from paths are discovered first, and then plug-ins registered explicitly, and there can’t be any duplicates.

If you need total control, you probably want to register plug-ins explicitly, and not paths.

I found the way to register_plugins but i’m not sure that this is the best way
So what i did

import sys
sys.path.append("C:/pyblish_plugins")
import collect_instances, extract_scene, validate_model, validate_rig

And at the end of each file i added register_plugin method
Is it ok to do so ?

Yes, that should work. Remember the plug-ins are the classes inside the modules.

You could try using this, plugins_from_module() to automate some of it. You can also pass a path to discover() which would return the contained plug-ins from all the files, and then register those.

Thanks a lot,
Discover method works best for me:
pyblish.api.discover(paths=["C:/pyblish_plugins"])

1 Like