Host filtering out of the box

We’ve established a series of plugins and have everything running smoothly within one of our DCC platforms. When I attempted running within another DCC I got a slew of exceptions that certain plugins were not for the correct host. I was under the impression that host filtering was done at the api level… do I have to perform additional functionality?

Here’s what I’m currently doing:

  • Registering the current host
  • Registering a slew of plugins for a slew of hosts (some are shared some are specific)

Is this possible out of the box to filter plugins based on current host, or am I doing it wrong?

I was looking at the register_discovery_filter function, but it feels overly complex for what I’m attempting to achieve. Is this what I would need to do before registering plugins:

my_host = 'maya'
pyblish.api.register_host(my_host)

def filter_by_host(plugin):
    return pyblish.plugin.current_host() in plugin.hosts

register_discovery_filter(filter_by_host)

Any info would be appreciated.

Hm, I’m having trouble following. Would it be possible to provide a reproducible?

import pyblish.api

class PotatoPlugin(pyblish.api.ContextPlugin):
    hosts = ['potato']

class TomatoPlugin(pyblish.api.ContextPlugin):
    hosts = ['tomato']


pyblish.api.register_host('tomato')

for plugin in (PotatoPlugin, TomatoPlugin):
    pyblish.api.register_plugin(plugin)

An exception is raised while registering PotatoPlugin. It might seem obvious, just use a try/except when registering or don’t include the plugin that doesn’t match the host. In my case I want to register every plugin we develop, and use the host/families/targets to filter what plugins are executed at runtime. Hopefully that makes more sense.

Oh yes I see. That was unexpected indeed, I would have expected it to simply get filtered.

It looks to be handled here (A), but isn’t consistent with how I it is and how I think it should get handled here (B).

If you put together a PR to convert A into B that would be great. Thanks for bringing this up.