Pyblish for Windows 1.0.5
Version 1.0.5 is now available and includes the following submodules.
- Pyblish 1.1.1
- Pyblish QML 0.2.10
- Pyblish for Maya 1.0.14
- Pyblish for Nuke 1.0.3
- Pyblish for Houdini 1.1.0
- Pyblish RPC 0.1.0
- Pyblish Integration 0.1.0
Summary of new features
- Integrations
- Pyblish for Houdini added
- Core
- Feature: Dependency Injection (see #127)
- Feature: SimplePlugin (see #186)
- Feature: In-memory plug-ins (see #140)
- Feature: Custom test (see #183)
- Feature: create_instance(name, **kwargs) (see #187)
- Preview: Asset (see #188)
- GUI
- Feature: Override plug-in label (see #85
- Feature: Shared instance (see #96)
- Feature: Context visible in list of items (see #90)
- CLI
- Bugfixes
See here for a full list of changes.
Introduction
This release is focused on lowering the learning curve for newcomers, primarily via the core library, yet some of the changes have also found their way into the GUI.
The update is completely backwards compatible, but encourages you to update your plug-ins to the new DI-style detailed below.
Installation
For a new install.
- Download and run the installer.
- Or see manual installation instructions here
To update.
Between 1.0.3 and 1.0.4 there has been some refactoring that may affect your integration of Pyblish into your pipeline.
- The previous root
/python
directory has been renamed/pythonpath
- Pyblish Suite has been superseeded by Pyblish X which meansâŚ
- âŚthat the inner packages are now located within
/lib/pyblish-x/modules
instead of/lib/pyblish-suite
., such aspyblish-qml
.
Using the installer
Uninstall your existing copy (due to the refactoring) and then re-install.
Using the command-line
The update.bat
has been updated in this release, which means you canât run the one you have from 1.0.3.
Instead, you can:
- cd to
pyblish-win
- Copy/paste this into a terminal.
git checkout master
git reset --hard
git pull
git submodule update --init --recursive
git clean -xffd
Iâd recommend doing this locally first, before pushing things into production, due to the way file deletion/updating works with permissions and files being in use etc.
If you run into any issues, feel free to post below.
Transition Guide
In terms of mixing old- and new-style plug-ins, hereâs what you need to keep in mind.
- In cases where you have either
process_context
orprocess_instance
, a simple search-and-replace toprocess
will work fine. - In cases where you have both, see below.
- During the transition phase, the distinction is made internally by looking for the existence of a
process_context
orprocess_instance
method. - If either exist, the plug-in is deemed âold-styleâ and is processed using the current implementation.
- If both
process
and eitherprocess_context
orprocess_instance
is present, old-style wins andprocess
will not be called.
Processing logic
The manner in which process()
is called is roughly this.
______
| | incl. `instance`
| args |------------------
|______| |
| |
| not incl. `instance` |
| |
_____v_____ ______|_____
| | | |
| process() |<--------| for each |
|___________| |____________|
# If the arguments include `instance`, then `process()`
# will be called once every instance. Otherwise it is
# called once.
#
# Unless the plug-in is *limited* to a subset of families.
# E.g. `families = ["oneFamily"]` in which case nothing
# happens unless there is an `instance` of a supported
# family.
For a full look, see the source.
Both process_context
and process_instance
The current behaviour of this is for process_context
to be processed first, followed by process_instance
. This behaviour isnât possible anymore. You can however process both in the same function.
def process(self, context, process):
# do things
In case you do have both, process_instance
will overwrite process_context
due to your plug-in being re-written to a itâs Dependency Injection equivalent at run-time.
def process_context(self, context):
# I will not be called. :(
def process_instance(self, instance):
# Runs as usual
Old-first
The reason for looking for old-style methods before new-style is because of the newly introduced ability to use __init__
. In cases where __init__
is used, and process
not being implemented, the plug-in is still deemed new-style as __init__
is assumed to not have been in use.
Dependency Injection
The most prominent change is this.
Before illustrating how it works, itâs important to point out that this is the new way of writing plug-ins. It means that the current way of implementing plug-ins still works, but are to be considered deprecated and no longer supported.
Now, on to the fun stuff!
As Usual
import pyblish.api
class ValidateInstances(pyblish.api.Validator):
def process(self, instance):
pass
This does as you would expect. Which is to process once for every instance, regardless of family (see below for new family defaults).
import pyblish.api
class SelectInstances(pyblish.api.Selector):
def process(self, context):
pass
In the same spirit, this plug-in runs once and has access to the context. This is nothing new.
Plug-in Independency
What is new is that you can choose to process nothing.
import pyblish.api
class SimpleExtractScene(pyblish.api.Extractor):
def process(self):
cmds.file("myfile.mb", exportAll=True)
This plug-in runs once, as when processing the context
, but doesnât have access to either the current Instance
nor Context
. This can be useful for plug-ins that are completely independent of itâs environment and state.
Default Services
What is also new is that you can also request other so-called âservicesâ.
import pyblish.api
class CustomValidator(pyblish.api.Validator):
def process(self, user, time):
fname = "myfile_v001_%s_%s.mb" % (user, time())
cmds.file(fname, exportAll=True)
In which case the services user
and time
are injected into the plug-in right before itâs about to start processing. Each of which are default services that ship with the Pyblish base install.
Here are all of them.
register_service("user", getpass.getuser())
register_service("time", pyblish.lib.time)
register_service("config", pyblish.api.config)
-
user
is available by value, as it is not expected to change at run-time. -
time
is callable, as it provides unique values each time it is used -
config
is shorthand topyblish.api.config
User Defined Services
You can also register your own servicesâŚ
def say(something, yell=False):
print(something.upper() if yell else something)
pyblish.api.register_service(say)
âŚand then request them via your plug-ins.
import pyblish.api
class ValidateUniverse(pyblish.api.Validator):
def process(self, say):
say("I just wanted to say, Hello World!", yell=True)
Service Coordination
Services are shared amongst plug-ins.
datastore = {"softFailure": False}
pyblish.api.register_service("store", datastore)
Which means you can use it to communicate and pass information inbetween them.
class ValidatePrimary(pyblish.api.Validator):
def process(self, instance, store):
if instance.has_data("I'm kind of valid.."):
store["softFailure"] = True
class ValidateBackup(pyblish.api.Validator):
def process(self, instance, store):
if store["softFailure"] is True:
# Do alternate validation
Or to provide globally accessible data, such as a database connection.
import ftrack
import pyblish.api
proxy = ftrack.ServerProxy("http://myaddress.ftrack.com")
pyblish.api.register_service("ftrack", proxy)
Distributed Development
With services, you can defer development of a plug-in between more than a single developer allowing for faster iteration times and improved version control.
As a plug-in is developed, requirements may ariseâŚ
import pyblish.api
class ValidateSecretSauce(pyblish.api.Validator):
def process(self, instance, sauce):
if sauce.hot():
assert instance.has_data("hotCompatible"), "Sauce too hot!"
assert instance.data("tasty") == True, "Sauce not tasty!"
Which can later be developed.
import pyblish.api
import my_studio_tools
class Sauce(object):
def hot(self):
return my_studio_tools.hot_sauce()
pyblish.api.register_service("sauce", Sauce())
Testing
As a final and important piece to the puzzle, dependency injection makes testing easier and more controllable.
def test_plugin():
"""Testing of a host-dependent plug-in with DI"""
instances = list()
class SelectCharacters(pyblish.api.Validator):
def process(self, context, host):
for char in host.ls("*_char"):
instance = context.create_instance(char, family="character")
instance.add(host.listRelatives(char))
instances.append(instance.name)
class HostMock(object):
def ls(self, query):
return ["bobby_char", "rocket_char"]
def listRelatives(self, node):
if node == "bobby_char":
return ["arm", "leg"]
if node == "rocket_char":
return ["propeller"]
return []
pyblish.api.register_service("host", HostMock())
for result in pyblish.logic.process(
func=pyblish.plugin.process,
plugins=[SelectCharacters],
context=pyblish.api.Context()):
assert_equals(result["error"], None)
assert_equals(len(instances), 2)
assert_equals(instances, ["bobby_char", "rocket_char"])
Related
Simple Plug-in
A new type of plug-in has been introduced; the superclass of the currently available Selection, Validation, Extraction and Conform (SVEC) plug-ins - called simply Plugin
.
import pyblish.api
class MyPlugin(pyblish.api.Plugin):
def process(self):
self.log.info("I'm simple")
Simple plug-ins are just that, a simpler, less assuming variant of SVEC. Each inherit the exact same functionality and can be used in-place of any other plug-in, the only difference being a default order of -1
meaning they will run before any of itâs siblings.
Other than that, they are identical in every way. To make it into a Selector, simply assign it an appropriate order.
class MySelector(pyblish.api.Plugin):
order = pyblish.api.Selector.order
More importantly, simple plug-ins are meant as a stepping stone for beginners not yet familiar with SVEC, and as a bridge to unforseen use of Pyblish, allowing arbitrary use and boundless extensibility.
With this, Pyblish is now a generic automation framework with SVEC becoming a collection of best practices and recommended method of writing plug-ins.
Related
In-memory plug-ins
This new feature will allow you to debug, share and prototype plug-ins more quickly.
In-memory plug-ins come directly from the Python run-time and isnât dependent on a filesystem search, which means you can easily post a plug-in to someone else. Once registered, it will be processed like any other plug-in.
import pyblish.api
class SelectPrototypeInstance(pyblish.api.Selector):
def process(self, context):
instance = context.create_instance("Prototype Test")
instance.set_data("family", "prototype")
pyblish.api.register_plugin(SelectPrototypeInstance)
This can be done anytime prior to publishing, including whilst the GUI is open, which means you can do some pretty intense things to hunt down bugs.
import pyblish.api
data = {}
@pyblish.api.log
class MyPlugin(pyblish.api.Plugin):
def process(self):
data["key"] = "value"
pyblish.api.register_plugin(MyPlugin)
After publishing, data
will contain the key key
with value value
. This is an example of a plug-in reaching out into the current execution environment. Something not possible before.
Related functions
- GitHub Issue
- pyblish.api.register_plugin
- pyblish.api.deregister_plugin
- pyblish.api.deregister_all_plugins
- pyblish.api.registered_plugins
New Defaults for Families and Hosts
The attributes families
and hosts
now default to *
, which means that they process everything in sight, unless you tell it not to.
This is different from how it was before, which was to process nothing, unless you told it to.
This has no effect on your current plug-ins, as you were obligated to always provide a family if you wanted it to process, but does mean it is a non-reversible change. So, fingers crossed you like it!
Related
Custom Test
You can now take control over when publishing is cancelled.
Currently, every plug-in is processed, unless the next plug-in is of an order above 2 (i.e. not a Selector nor Validator) and no prior plug-in within the orders 1-2 (i.e. any Validator) have failed.
This is what that test looks like.
def default_test(**vars):
if vars["nextOrder"] >= 2: # If validation is done
for order in vars["ordersWithError"]:
if order < 2: # Were there any error before validation?
return "failed validation"
return
The test is run each time a new plug-in is about to process, and is given a dictionary vars
which is always up to date with the most recent information.
Currently, the only two members of the dictionary is nextOrder
and ordersWithError
, but as need arises more will most likely be added.
Related
create_instance(name, **kwargs)
You can now create instances and assign it a family in one go.
import pyblish.api
context = pyblish.api.Context()
# Before
instance = context.create_instance(name="MyInstance")
instance.set_data("family", "myFamily")
# After
instance = context.create_instance(name="MyInstance", family="myFamily")
And condense some otherwise repeated code into a more minimal variant.
import pyblish.api
context = pyblish.api.Context()
# Before
instance = context.create_instance("MyInstance")
instance.set_data("family", "myFamily")
instance.set_data("color", "blue")
instance.set_data("age", 35)
instance.set_data("height", 1.90)
# After
instance = context.create_instance(
name="MyInstance",
family="myFamily",
color="blue",
age=35,
height=1.90)
Related
Unified Logic
The order in which to process plug-ins, and whether or not to cancel a publish after a failed validation was previously implemented in each user-facing interface. Such as pyblish.util.publish()
, the command-line interface and graphical user interface.
In 1.1, logic has been centralised and is more likely to remain identical across interfaces.
Related
Asset
As a preview, Iâve also included an undocumented and unsupported method of using the term Asset
in place of Instance
, as discussed here.
It means you can give it a try and get a sense for whether or not it works for you. If it turns out to be a winner, it may potentially become the de-facto new standard of Pyblish.
An example, taken from the forum thread.
import pyblish.api
class SelectCharacters(pyblish.api.Selector):
def process(self, context):
for objset in cmds.ls(type="objectSet"):
name = cmds.getAttr(objset + ".name")
asset = context.create_asset(name)
asset.set_data("family", "character")
class ValidateColor(pyblish.api.Validator):
families = ["character"]
def process(self, asset):
assert asset.data("color") == "blue", "%s isn't blue" % asset
The same behaviour is replicated all across the board, including an alias for Instance
through the API.
>>> import pyblish.api
>>> assert pyblish.api.Instance == pyblish.api.Asset
Use with caution and expect it to vanish at any moment without warning.
GUI
Amongst the few GUI changes, the most prominent one is on the backend which is a new method of IPC communication via remote-procedure calls in place of the previous RESTful architecture.
The full motivation and reasoning behind this switch can be found here.
Visually, another thing youâll notice is that all plug-ins are now drawn with a warning label. The warning label will appear on any plug-in still implementing the pre-1.1 interface of process_context
or process_instance
.
Shared Instance
From now on, only a single instance of Pyblish QML can be running at once. This means that when the GUI is first launched from one host, it is then re-used in the next. Saving both time and memory.
Technically, a host registers interest with the GUI upon asking it to show. Upon having a new host register interest, the GUI then resets itself to visualise the environment of the newly registered host.
This is handled via the new Pyblish Integration project and isnât something you need to manage on your own.
Override label
Deprecation warning
Visualising plug-ins compatible with Context
Thatâs it! Enjoy!