Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor plugin validation #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,35 +938,9 @@ def register_plugin(plugin):

"""

if not hasattr(plugin, "__call__"):
raise TypeError("Plug-in must be callable "
"returning an instance of a class")

if not plugin_is_valid(plugin):
raise TypeError("Plug-in invalid: %s", plugin)

if not version_is_compatible(plugin):
raise TypeError(
"Plug-in %s not compatible with "
"this version (%s) of Pyblish." % (
plugin, __version__))

if not host_is_compatible(plugin):

hosts = registered_hosts()
required_hosts = plugin.hosts

err = """Plug-in %s is not compatible with available host(s).

Required host(s): %s
Registered host(s): %s

Make sure the integration for your host is correctly setup
or register a new host using `pyblish.api.register_host("%s")`
""" % (plugin, repr(required_hosts), repr(hosts), required_hosts[0])

raise TypeError(err)

_registered_plugins[plugin.__name__] = plugin


Expand Down Expand Up @@ -1429,16 +1403,6 @@ def plugins_from_module(module):
log.debug("Plug-in invalid: %s", obj)
continue

if not version_is_compatible(obj):
log.debug("Plug-in %s not compatible with "
"this version (%s) of Pyblish." % (
obj, __version__))
continue

if not host_is_compatible(obj):
log.debug("No supported host found for plugin:%s", obj)
continue

plugins.append(obj)

return plugins
Expand All @@ -1452,6 +1416,11 @@ def plugin_is_valid(plugin):

"""

if not hasattr(plugin, "__call__"):
log.debug("Plug-in must be callable "
"returning an instance of a class")
return False

if not isinstance(plugin.requires, six.string_types):
log.debug("Plug-in requires must be of type string: %s", plugin)
return False
Expand Down Expand Up @@ -1491,6 +1460,27 @@ def plugin_is_valid(plugin):
"pyblish.api.Exact")
return False

if not version_is_compatible(plugin):
log.debug("Plug-in %s not compatible with "
"this version (%s) of Pyblish." % (plugin, __version__))
return False

if not host_is_compatible(plugin):
hosts = registered_hosts()
required_hosts = plugin.hosts

err = """Plug-in %s is not compatible with available host(s).

Required host(s): %s
Registered host(s): %s

Make sure the integration for your host is correctly setup
or register a new host using `pyblish.api.register_host("%s")`
""" % (plugin, repr(required_hosts), repr(hosts), required_hosts[0])

log.debug(err)
return False

return True


Expand Down