# NOTE: THIS FEATURE HAS BEEN DEPRECATED!
I know this is a little ahead as you haven’t been given a chance to play with DI yet, but for future discussion, I’ll pop this in here hoping there will be a time where we can have a discussion about it’s pros/cons.
Goal
To facilitate testing and to further decouple plug-ins from their environment by eliminating host-bound imports and enable imports of host-bound plug-ins from the outside and/or other hosts.
Implementation
It would look like this.
import pyblish.api
class SelectCharacters(pyblish.api.Selector):
def process(self, context, cmds):
for char in cmds.ls("*_char"):
context.create_instance(char)
In which case cmds
is a reference to maya.cmds
and is injected upon integration via the Maya extension.
userSetup.py
from maya import cmds
import pyblish.api
pyblish.api.register_service("cmds", cmds)
Still, the above is merely moving the import statement into the method signature, it’s not terribly unique. What is unique however is how we can design plug-ins to remain independent of a host even when it requires the use of host-specific modules, such as maya.cmds
.
import pyblish.api
class SelectCharacters(pyblish.api.Selector):
def process(self, context, host):
for char in host.ls("*_char"):
context.create_instance(char)
In which case host
represents maya.cmds
when the plug-in is used in the context of Maya, and nuke
when in Nuke etc.
The question then is, “won’t their interfaces differ?” and you are absolutely right. Maya will provide functions that differ from Nuke and Houdini and vice versa so it is unlikely that the feature will work everywhere.
But it might work in special and more important areas where reuse is more important.
To provide plug-ins with a common interface towards whatever host it supports, you do what you would normally do when you have multiple conflicting APIs that needs coordination; wrap them up into a common shared interface.
maya
from maya import cmds
class Host(object):
def list_items(self, query):
return cmds.ls(query)
import pyblish.api
pyblish.api.register_service("host", Host())
nuke
import nuke
class Host(object):
def list_items(self, query):
return nuke.allNodes(query)
import pyblish.api
pyblish.api.register_service("host", Host())
The end result is the possibility to now write a plug-in that works on-top of this interface.
import pyblish.api
class SelectCharacters(pyblish.api.Selector):
def process(self, context, host):
for char in host.list_items("*_char"):
context.create_instance(char)
Discussion
This is something you’ll be able to do right away upon the release of 1.1, but what this proposal is about is whether or not to make this a default, recommended behaviour.
The question is, is it worth pursuing, what advantage(s) does it provide, if any, and at what cost?