From d6211201b5729a2e75da462ee7b3710f6a9109ab Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 6 Sep 2019 09:53:44 +0200 Subject: [PATCH 1/2] fixed method name in close window connection --- pype/clockify/clockify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pype/clockify/clockify.py b/pype/clockify/clockify.py index ed6d996e2e..5e6cfec778 100644 --- a/pype/clockify/clockify.py +++ b/pype/clockify/clockify.py @@ -194,7 +194,7 @@ class ClockifyModule: self.message_widget = MessageWidget( self.main_parent, msg, "Clockify - Info Message" ) - self.message_widget.closed.connect(self.message_widget) + self.message_widget.closed.connect(self.on_message_widget_close) self.message_widget.show() return From 2bbe2f9372837ee03cc5100e6ef85fafe89012f2 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Fri, 6 Sep 2019 14:28:41 +0200 Subject: [PATCH 2/2] added avalon loader/creator presets --- pype/__init__.py | 53 ++++++++++++++++++++++++ pype/tests/test_avalon_plugin_presets.py | 40 ++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 pype/tests/test_avalon_plugin_presets.py diff --git a/pype/__init__.py b/pype/__init__.py index a5858f49e7..bcbedc9a90 100644 --- a/pype/__init__.py +++ b/pype/__init__.py @@ -3,6 +3,8 @@ import os from pyblish import api as pyblish from avalon import api as avalon from .lib import filter_pyblish_plugins +from pypeapp import config + import logging log = logging.getLogger(__name__) @@ -16,6 +18,51 @@ PLUGINS_DIR = os.path.join(PACKAGE_DIR, "plugins") PUBLISH_PATH = os.path.join(PLUGINS_DIR, "global", "publish") LOAD_PATH = os.path.join(PLUGINS_DIR, "global", "load") +# we are monkey patching `avalon.api.discover()` to allow us to load +# plugin presets on plugins being discovered by avalon. Little bit of +# hacking, but it allows us to add out own features without need +# to modify upstream code. + +_original_discover = avalon.discover + + +def patched_discover(superclass): + """ + Monkey patched version of :func:`avalon.api.discover()`. It allows + us to load presets on plugins being discovered. + """ + # run original discover and get plugins + plugins = _original_discover(superclass) + + # determine host application to use for finding presets + host = avalon.registered_host().__name__.split(".")[-1] + + # map plugin superclass to preset json. Currenly suppoted is load and + # create (avalon.api.Loader and avalon.api.Creator) + plugin_type = "undefined" + if superclass.__name__.split(".")[-1] == "Loader": + plugin_type = "load" + elif superclass.__name__.split(".")[-1] == "Creator": + plugin_type = "create" + + print(">>> trying to find presets for {}:{} ...".format(host, plugin_type)) + try: + config_data = config.get_presets()['plugins'][host][plugin_type] + except KeyError: + print("*** no presets found.") + else: + for plugin in plugins: + if plugin.__name__ in config_data: + print(">>> We have preset for {}".format(plugin.__name__)) + for option, value in config_data[plugin.__name__].items(): + if option == "enabled" and value is False: + setattr(plugin, "active", False) + print(" - is disabled by preset") + else: + setattr(plugin, option, value) + print(" - setting `{}`: `{}`".format(option, value)) + return plugins + def install(): log.info("Registering global plug-ins..") @@ -23,6 +70,9 @@ def install(): pyblish.register_discovery_filter(filter_pyblish_plugins) avalon.register_plugin_path(avalon.Loader, LOAD_PATH) + # apply monkey patched discover to original one + avalon.discover = patched_discover + def uninstall(): log.info("Deregistering global plug-ins..") @@ -30,3 +80,6 @@ def uninstall(): pyblish.deregister_discovery_filter(filter_pyblish_plugins) avalon.deregister_plugin_path(avalon.Loader, LOAD_PATH) log.info("Global plug-ins unregistred") + + # restore original discover + avalon.discover = _original_discover diff --git a/pype/tests/test_avalon_plugin_presets.py b/pype/tests/test_avalon_plugin_presets.py new file mode 100644 index 0000000000..7f023ea358 --- /dev/null +++ b/pype/tests/test_avalon_plugin_presets.py @@ -0,0 +1,40 @@ +import avalon.api as api +import pype + + +class MyTestCreator(api.Creator): + + my_test_property = "A" + + def __init__(self, name, asset, options=None, data=None): + super(MyTestCreator, self).__init__(self, name, asset, + options=None, data=None) + + +# this is hack like no other - we need to inject our own avalon host +# and bypass all its validation. Avalon hosts are modules that needs +# `ls` callable as attribute. Voila: +class Test: + __name__ = "test" + ls = len + + def __call__(self): + pass + + +def test_avalon_plugin_presets(monkeypatch, printer): + + pype.install() + api.register_host(Test()) + api.register_plugin(api.Creator, MyTestCreator) + plugins = api.discover(api.Creator) + printer("Test if we got our test plugin") + assert MyTestCreator in plugins + for p in plugins: + if p.__name__ == "MyTestCreator": + printer("Test if we have overriden existing property") + assert p.my_test_property == "B" + printer("Test if we have overriden superclass property") + assert p.active is False + printer("Test if we have added new property") + assert p.new_property == "new"