From 1793c83d1632ed65b5129db6edf2312525a0c8ad Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Thu, 6 Feb 2020 15:26:25 +0800 Subject: [PATCH 1/9] Parse post collect order via environment variable into context --- pyblish_qml/ipc/formatting.py | 1 + pyblish_qml/ipc/service.py | 2 ++ pyblish_qml/models.py | 1 + 3 files changed, 4 insertions(+) diff --git a/pyblish_qml/ipc/formatting.py b/pyblish_qml/ipc/formatting.py index 0c8765d8..2cf942e2 100644 --- a/pyblish_qml/ipc/formatting.py +++ b/pyblish_qml/ipc/formatting.py @@ -142,6 +142,7 @@ def format_data(data): "port", "user", "connectTime", + "postCollectOrder", "pyblishVersion", "pyblishRPCVersion", "pythonVersion") diff --git a/pyblish_qml/ipc/service.py b/pyblish_qml/ipc/service.py index 9f8354d5..e0687704 100644 --- a/pyblish_qml/ipc/service.py +++ b/pyblish_qml/ipc/service.py @@ -56,10 +56,12 @@ def context(self): # Append additional metadata to context port = os.environ.get("PYBLISH_CLIENT_PORT", -1) hosts = ", ".join(reversed(pyblish.api.registered_hosts())) + post_collect = float(os.environ.get("PYBLISH_QML_POST_COLLECT", "NaN")) for key, value in {"host": hosts, "port": int(port), "user": getpass.getuser(), + "postCollectOrder": post_collect, "connectTime": pyblish.lib.time(), "pyblishVersion": pyblish.version, "pythonVersion": sys.version}.items(): diff --git a/pyblish_qml/models.py b/pyblish_qml/models.py index 2eaa6d3a..88383353 100644 --- a/pyblish_qml/models.py +++ b/pyblish_qml/models.py @@ -83,6 +83,7 @@ "port": 0, "host": "default", "user": "default", + "postCollectOrder": float("NaN"), "connectTime": "default", "pythonVersion": "default", "pyblishVersion": "default", From e870d05d4a6c8070572bd2a1f67a6ea363117f3a Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Thu, 6 Feb 2020 15:27:08 +0800 Subject: [PATCH 2/9] Implement post collect logic --- pyblish_qml/control.py | 83 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 478e5a69..6f34b957 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -1,6 +1,7 @@ import json import time +import math import collections # Dependencies @@ -857,6 +858,9 @@ def on_discover(plugins, context): base=pyblish.api.Collector.order): continue + if plugin.order >= context.data["postCollectOrder"]: + continue + if not plugin.active: continue @@ -885,6 +889,69 @@ def on_reset(): util.defer(self.host.reset, callback=on_reset) + def post_collect(self, on_post_collected): + + def on_finished(plugins, context): + # Compute compatibility + for plugin in self.data["models"]["item"].plugins: + if plugin.instanceEnabled: + instances = pyblish.logic.instances_by_plugin(context, + plugin) + plugin.compatibleInstances = list(i.id for i in instances) + else: + plugin.compatibleInstances = [context.id] + + self.data["models"]["item"].reorder(context) + self.data["models"]["item"].update_compatibility() + + # Hidden sections + for section in self.data["models"]["item"].sections: + if section.name in settings.HiddenSections: + self.hideSection(True, section.name) + + on_post_collected() + + def on_run(plugins): + """Fetch instances in their current state, right after reset""" + util.defer(self.host.context, + callback=lambda context: on_finished(plugins, context)) + + def on_post_collectors(collectors): + plugins = self.host.cached_discover + context = self.host.cached_context + + self.run(collectors, context, + callback=on_run, + callback_args=[plugins]) + + def post_collectors(): + plugins = self.host.cached_discover + context = self.host.cached_context + collectors = list() + + for plugin in plugins: + # Sort out which of these are Post Collectors + if not pyblish.lib.inrange( + number=plugin.order, + base=pyblish.api.Collector.order): + continue + + if plugin.order < context.data["postCollectOrder"]: + continue + + if not plugin.active: + continue + + collectors.append(plugin) + + return collectors + + util.defer(post_collectors, callback=on_post_collectors) + + def _use_post_collect(self): + context = self.host.cached_context + return not math.isnan(context.data["postCollectOrder"]) + @QtCore.pyqtSlot() def publish(self): """Start asynchonous publishing @@ -921,6 +988,9 @@ def get_data(): return plugins, instances + def on_post_collected(): + util.defer(get_data, callback=on_data_received) + def on_data_received(args): self.run(*args, callback=on_finished) @@ -940,7 +1010,10 @@ def on_finished(): self.info.emit("Published, with errors..") break - util.defer(get_data, callback=on_data_received) + if self._use_post_collect(): + self.post_collect(on_post_collected) + else: + util.defer(get_data, callback=on_data_received) @QtCore.pyqtSlot() def validate(self): @@ -976,13 +1049,19 @@ def get_data(): return plugins, instances + def on_post_collected(): + util.defer(get_data, callback=on_data_received) + def on_data_received(args): self.run(*args, callback=on_finished) def on_finished(): self.host.emit("validated", context=None) - util.defer(get_data, callback=on_data_received) + if self._use_post_collect(): + self.post_collect(on_post_collected) + else: + util.defer(get_data, callback=on_data_received) def run(self, plugins, context, callback=None, callback_args=[]): """Commence asynchronous tasks From dc1ca5e7c49ea088450ad221eb3ac3809c847f2e Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Thu, 6 Feb 2020 15:27:25 +0800 Subject: [PATCH 3/9] Show post collect order in GUI --- pyblish_qml/qml/delegates/ContextDelegate.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyblish_qml/qml/delegates/ContextDelegate.qml b/pyblish_qml/qml/delegates/ContextDelegate.qml index 8aa3af4a..305377a4 100644 --- a/pyblish_qml/qml/delegates/ContextDelegate.qml +++ b/pyblish_qml/qml/delegates/ContextDelegate.qml @@ -47,6 +47,10 @@ BaseDelegate { "key": "Targets", "value": object.targets }, + { + "key": "Post Collect", + "value": object.postCollectOrder + }, { "key": "Connected", "value": Date(Date.parse(object.connectTime)) From cbb6ea57e09f5f96399921f029402a28d26ce712 Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Thu, 6 Feb 2020 16:34:59 +0800 Subject: [PATCH 4/9] Format post collect order on reset --- pyblish_qml/ipc/formatting.py | 7 +++++++ pyblish_qml/ipc/service.py | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyblish_qml/ipc/formatting.py b/pyblish_qml/ipc/formatting.py index 2cf942e2..0cae2378 100644 --- a/pyblish_qml/ipc/formatting.py +++ b/pyblish_qml/ipc/formatting.py @@ -195,6 +195,13 @@ def format_context(context): } +def format_post_collect_order(order): + try: + return float(order) + except (TypeError, ValueError): + return float("NaN") + + def format_plugins(plugins): """Serialise multiple plug-in diff --git a/pyblish_qml/ipc/service.py b/pyblish_qml/ipc/service.py index e0687704..254f8b3a 100644 --- a/pyblish_qml/ipc/service.py +++ b/pyblish_qml/ipc/service.py @@ -28,6 +28,7 @@ def __init__(self): self._context = None self._plugins = None self._provider = None + self._post_collect = None self.reset() @@ -51,17 +52,18 @@ def reset(self): self._context = pyblish.api.Context() self._plugins = pyblish.api.discover() self._provider = pyblish.plugin.Provider() + self._post_collect = formatting.format_post_collect_order( + os.environ.get("PYBLISH_QML_POST_COLLECT")) def context(self): # Append additional metadata to context port = os.environ.get("PYBLISH_CLIENT_PORT", -1) hosts = ", ".join(reversed(pyblish.api.registered_hosts())) - post_collect = float(os.environ.get("PYBLISH_QML_POST_COLLECT", "NaN")) for key, value in {"host": hosts, "port": int(port), "user": getpass.getuser(), - "postCollectOrder": post_collect, + "postCollectOrder": self._post_collect, "connectTime": pyblish.lib.time(), "pyblishVersion": pyblish.version, "pythonVersion": sys.version}.items(): From 5b74960344ed9bd11613d18d9e9c4d2029b817b7 Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Thu, 6 Feb 2020 16:35:43 +0800 Subject: [PATCH 5/9] Put post collector plugins into section "Additional" --- pyblish_qml/control.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 6f34b957..b9db2633 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -843,6 +843,7 @@ def on_run(plugins): def on_discover(plugins, context): collectors = list() + model = self.data["models"]["item"] # For backwards compatibility check for existance of # "plugins_by_targets" method. @@ -850,7 +851,7 @@ def on_discover(plugins, context): plugins = pyblish.api.plugins_by_targets(plugins, self.targets) for plugin in plugins: - self.data["models"]["item"].add_plugin(plugin.to_json()) + model.add_plugin(plugin.to_json()) # Sort out which of these are Collectors if not pyblish.lib.inrange( @@ -859,6 +860,8 @@ def on_discover(plugins, context): continue if plugin.order >= context.data["postCollectOrder"]: + model.plugins[-1].verb = "Additional" + model.add_section("Additional") continue if not plugin.active: From 6ea64bd2979ef5250448d2503967a7d602d1320e Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Mon, 16 Mar 2020 16:47:17 +0800 Subject: [PATCH 6/9] Remove duplicated code --- pyblish_qml/control.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 48005145..9d1155de 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -905,8 +905,10 @@ def on_reset(): def post_collect(self, on_post_collected): def on_finished(plugins, context): + model = self.data["models"]["item"] + # Compute compatibility - for plugin in self.data["models"]["item"].plugins: + for plugin in model.plugins: if plugin.instanceEnabled: instances = pyblish.logic.instances_by_plugin(context, plugin) @@ -914,11 +916,11 @@ def on_finished(plugins, context): else: plugin.compatibleInstances = [context.id] - self.data["models"]["item"].reorder(context) - self.data["models"]["item"].update_compatibility() + model.reorder(context) + model.update_compatibility() # Hidden sections - for section in self.data["models"]["item"].sections: + for section in model.sections: if section.name in settings.HiddenSections: self.hideSection(True, section.name) From 975110641f917a8c27dece59195bb6b9eed0cdf4 Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Mon, 16 Mar 2020 18:17:16 +0800 Subject: [PATCH 7/9] Update plugins and context (instances) before run --- pyblish_qml/control.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 9d1155de..a69f78da 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -940,27 +940,32 @@ def on_post_collectors(collectors): callback_args=[plugins]) def post_collectors(): - plugins = self.host.cached_discover - context = self.host.cached_context + model = self.data["models"]["item"] + + host_plugins = dict((p.id, p) for p in self.host.cached_discover) + host_context = dict((i.id, i) for i in self.host.cached_context) + collectors = list() + instances = list() - for plugin in plugins: + for plugin in models.ItemIterator(model.plugins): # Sort out which of these are Post Collectors if not pyblish.lib.inrange( number=plugin.order, base=pyblish.api.Collector.order): continue - if plugin.order < context.data["postCollectOrder"]: + if plugin.order < post_collect_order: continue - if not plugin.active: - continue + collectors.append(host_plugins[plugin.id]) - collectors.append(plugin) + for instance in models.ItemIterator(model.instances): + instances.append(host_context[instance.id]) - return collectors + return collectors, instances + post_collect_order = self.host.cached_context.data["postCollectOrder"] util.defer(post_collectors, callback=on_post_collectors) def _use_post_collect(self): From a47c7ef32578c1df30eed471c5c971ec15fb3b65 Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Mon, 16 Mar 2020 18:18:34 +0800 Subject: [PATCH 8/9] Fix input arguments --- pyblish_qml/control.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index a69f78da..7cee6af2 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -904,7 +904,7 @@ def on_reset(): def post_collect(self, on_post_collected): - def on_finished(plugins, context): + def on_finished(context): model = self.data["models"]["item"] # Compute compatibility @@ -926,18 +926,13 @@ def on_finished(plugins, context): on_post_collected() - def on_run(plugins): + def on_run(): """Fetch instances in their current state, right after reset""" util.defer(self.host.context, - callback=lambda context: on_finished(plugins, context)) - - def on_post_collectors(collectors): - plugins = self.host.cached_discover - context = self.host.cached_context + callback=lambda context: on_finished(context)) - self.run(collectors, context, - callback=on_run, - callback_args=[plugins]) + def on_post_collectors(args): + self.run(*args, callback=on_run) def post_collectors(): model = self.data["models"]["item"] From a36bcfbf1baed546108043ac4d0acd6f8652d45c Mon Sep 17 00:00:00 2001 From: davidlatwe Date: Mon, 16 Mar 2020 18:24:23 +0800 Subject: [PATCH 9/9] Rename functions --- pyblish_qml/control.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyblish_qml/control.py b/pyblish_qml/control.py index 7cee6af2..617a6156 100644 --- a/pyblish_qml/control.py +++ b/pyblish_qml/control.py @@ -904,6 +904,8 @@ def on_reset(): def post_collect(self, on_post_collected): + post_collect_order = self.host.cached_context.data["postCollectOrder"] + def on_finished(context): model = self.data["models"]["item"] @@ -931,10 +933,11 @@ def on_run(): util.defer(self.host.context, callback=lambda context: on_finished(context)) - def on_post_collectors(args): + def on_data_received(args): self.run(*args, callback=on_run) - def post_collectors(): + def get_data(): + """Get post collector plugins and instances""" model = self.data["models"]["item"] host_plugins = dict((p.id, p) for p in self.host.cached_discover) @@ -960,8 +963,7 @@ def post_collectors(): return collectors, instances - post_collect_order = self.host.cached_context.data["postCollectOrder"] - util.defer(post_collectors, callback=on_post_collectors) + util.defer(get_data, callback=on_data_received) def _use_post_collect(self): context = self.host.cached_context