Skip to content

Commit

Permalink
Merge pull request #258 from tokejepsen/targets_workflow
Browse files Browse the repository at this point in the history
Targets workflow.
  • Loading branch information
tokejepsen authored Aug 28, 2017
2 parents 6668026 + 3721e6d commit 4d1024a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pyblish_qml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
)


def show(parent=None):
def show(parent=None, targets=[]):
from . import host
return host.show(parent)
return host.show(parent, targets)


_state = {}
Expand Down
7 changes: 7 additions & 0 deletions pyblish_qml/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ def cli():
parser.add_argument("--demo", action="store_true")
parser.add_argument("--aschild", action="store_true",
help="Run as child of another process")
parser.add_argument(
"--targets",
nargs="*",
help="Targets to run plugins against."
)

kwargs = parser.parse_args()
if kwargs.targets is None:
kwargs.targets = []

return app.main(**kwargs.__dict__)

Expand Down
10 changes: 5 additions & 5 deletions pyblish_qml/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Application(QtGui.QGuiApplication):
inFocused = QtCore.pyqtSignal()
outFocused = QtCore.pyqtSignal()

def __init__(self, source):
def __init__(self, source, targets=[]):
super(Application, self).__init__(sys.argv)

self.setWindowIcon(QtGui.QIcon(ICON_PATH))
Expand All @@ -83,7 +83,7 @@ def __init__(self, source):
engine.addImportPath(QML_IMPORT_DIR)

host = ipc.client.Proxy()
controller = control.Controller(host)
controller = control.Controller(host, targets=targets)
controller.finished.connect(lambda: window.alert(0))

context = engine.rootContext()
Expand Down Expand Up @@ -249,7 +249,7 @@ def _listen():
thread.start()


def main(demo=False, aschild=False):
def main(demo=False, aschild=False, targets=[]):
"""Start the Qt-runtime and show the window
Arguments:
Expand All @@ -260,7 +260,7 @@ def main(demo=False, aschild=False):
if aschild:
print("Starting pyblish-qml")
compat.main()
app = Application(APP_PATH)
app = Application(APP_PATH, targets)
app.listen()

print("Done, don't forget to call `show()`")
Expand All @@ -269,7 +269,7 @@ def main(demo=False, aschild=False):
else:
print("Starting pyblish-qml server..")
service = ipc.service.MockService() if demo else ipc.service.Service()
server = ipc.server.Server(service)
server = ipc.server.Server(service, targets=targets)

proxy = ipc.server.Proxy(server)
proxy.show(settings.to_dict())
Expand Down
7 changes: 6 additions & 1 deletion pyblish_qml/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ class Controller(QtCore.QObject):
resultModel = qtproperty(lambda self: self.data["models"]["result"])
resultProxy = qtproperty(lambda self: self.data["proxies"]["result"])

def __init__(self, host, parent=None):
def __init__(self, host, parent=None, targets=[]):
super(Controller, self).__init__(parent)

# Connection to host
self.host = host

self.targets = targets

self.data = {
"models": {
"item": models.ItemModel(),
Expand Down Expand Up @@ -737,6 +739,8 @@ def on_run(plugins):
def on_discover(plugins, context):
collectors = list()

plugins = pyblish.api.plugins_by_targets(plugins, self.targets)

for plugin in plugins:
self.data["models"]["item"].add_plugin(plugin.to_json())

Expand All @@ -757,6 +761,7 @@ def on_discover(plugins, context):

def on_context(context):
context.data["pyblishQmlVersion"] = version
context.data["targets"] = ", ".join(self.targets)

self.data["models"]["item"].add_context(context.to_json())
self.data["models"]["result"].add_context(context.to_json())
Expand Down
4 changes: 2 additions & 2 deletions pyblish_qml/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def uninstall():
sys.stdout.write("Pyblish QML shutdown successful.\n")


def show(parent=None):
def show(parent=None, targets=[]):
"""Attempt to show GUI
Requires install() to have been run first, and
Expand Down Expand Up @@ -109,7 +109,7 @@ def on_shown():

try:
service = ipc.service.Service()
server = ipc.server.Server(service)
server = ipc.server.Server(service, targets=targets)
except Exception:
# If for some reason, the GUI fails to show.
traceback.print_exc()
Expand Down
1 change: 1 addition & 0 deletions pyblish_qml/ipc/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def format_plugin(plugin):
"optional": plugin.optional,
"hosts": plugin.hosts,
"families": plugin.families,
"targets": plugin.targets,
"doc": inspect.getdoc(plugin),
"active": plugin.active,
"match": plugin.match,
Expand Down
21 changes: 21 additions & 0 deletions pyblish_qml/ipc/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,24 @@ def process(self, context):
self.log.info(context.data.get("comment", "No comment"))


class TargetedCollector(pyblish.api.ContextPlugin):
"""Target collector to "studio" target."""
order = pyblish.api.CollectorOrder
targets = ["studio"]

def process(self, context):
pass


class TargetedValidator(pyblish.api.ContextPlugin):
"""Target validator to "studio" target."""
order = pyblish.api.ValidatorOrder
targets = ["studio"]

def process(self, context):
pass


instances = [
{
"name": "Peter01",
Expand Down Expand Up @@ -661,6 +679,9 @@ def process(self, context):
InactiveInstanceCollectorPlugin,

CommentPlugin,

TargetedCollector,
TargetedValidator,
]

pyblish.api.sort_plugins(plugins)
Expand Down
6 changes: 5 additions & 1 deletion pyblish_qml/ipc/schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"type": "array",
"items": {"type": "string"}
},
"targets": {
"type": "array",
"items": {"type": "string"}
},
"order": {
"type": "number"
},
Expand Down Expand Up @@ -80,4 +84,4 @@
}
}
}
}
}
13 changes: 12 additions & 1 deletion pyblish_qml/ipc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Server(object):
"""

def __init__(self, service, python=None, pyqt5=None):
def __init__(self, service, python=None, pyqt5=None, targets=[]):
super(Server, self).__init__()
self.service = service
self.listening = False
Expand Down Expand Up @@ -161,6 +161,17 @@ def __init__(self, service, python=None, pyqt5=None):
# from opening an external terminal window.
kwargs["creationflags"] = CREATE_NO_WINDOW

# If no targets are passed to pyblish-qml, we assume that we want the
# default target and the registered targets. This is to facilitate
# getting all plugins on pyblish_qml.show().
import pyblish.api
if not targets:
targets = ["default"] + pyblish.api.registered_targets()
print("Targets: {0}".format(", ".join(targets)))

kwargs["args"].append("--targets")
kwargs["args"].extend(targets)

self.popen = subprocess.Popen(**kwargs)
self.listen()

Expand Down
6 changes: 5 additions & 1 deletion pyblish_qml/qml/delegates/ContextDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ BaseDelegate {
"key": "Host",
"value": object.host
},
{
"key": "Targets",
"value": object.targets
},
{
"key": "Connected",
"value": Date(Date.parse(object.connectTime))
Expand All @@ -68,4 +72,4 @@ BaseDelegate {
}
}
}
}
}
4 changes: 2 additions & 2 deletions pyblish_qml/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

VERSION_MAJOR = 1
VERSION_MINOR = 3
VERSION_PATCH = 1
VERSION_MINOR = 4
VERSION_PATCH = 0

version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
Expand Down

0 comments on commit 4d1024a

Please sign in to comment.