Skip to content

Instantly share code, notes, and snippets.

@mottosso
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mottosso/e2244ab4b5c82ed66459 to your computer and use it in GitHub Desktop.
Save mottosso/e2244ab4b5c82ed66459 to your computer and use it in GitHub Desktop.
Pyblish Search Engine

Pyblish Search

Demonstration of plug-ins for Pyblish being exposed to a search engine via customisable keywords.

How it works

Each plug-in is associated with a series of keywords, the keywords are then browsed via plain-text search.

class MyPlugin(...):
   tags = ["keyword1", "keyword2"]

The discovered plug-ins are then dynamically added to Pyblish at run-time such that publishing occurs relative to what was searched for.

For example, the search term might include "games character geometry" which would mine the collection of plug-ins available for any that matched any of the included tags, "games", "character" or "geometry".

How it is useful

Picture having access to 1500 validations, some developed by peers within your company and some provided externally through a cloud-service. You have a number of criterias that your asset must fulfill, but aren't interested in the technicalities of how to actually validate anything; you just care about what's right.

From here, you could conjure up a series of keywords relevant to your requirements and pass it off to the search engine. It would then ensure that every validation passes prior to the asset being shipped.

Limitations

With this naive approach, keywords are bound to be quite specific.

For example, you might want to validate for the height of an asset. Keywords may include "<=1.5m" or ">=200m" in which case these exact keywords must exist to facilitate this exact requirement.

What would be better, is for there to be a single "MaximumHeight" validation that could be customised to whichever height was sought after.

import pyblish.api
import pyblish.util
disk = {}
class ValidateMeshDensity(pyblish.api.Validator):
tags = ["geometry", "character", "film"]
def process(self, instance):
assert True
class ValidateEntropy(pyblish.api.Validator):
tags = ["geometry", "character", "film", "game", "tv"]
def process(self, instance):
assert True
class ValidateUVOverlap(pyblish.api.Validator):
tags = ["geometry", "uv", "film", "game", "tv"]
def process(self, instance):
assert True
class ValidateDefaultPose(pyblish.api.Validator):
tags = ["rigging", "animation"]
def process(self, instance):
assert True
class CollectInstances(pyblish.api.Collector):
def process(self, context):
context.create_instance("MyInstance", family="rig")
class ExtractCharacter(pyblish.api.Extractor):
def process(self, instance):
disk["data"] = True
# Database of all available validators
validators = [
ValidateMeshDensity,
ValidateEntropy,
ValidateUVOverlap,
ValidateDefaultPose,
]
def search(queries):
"""Search engine, based on tags
Arguments:
queries (list): Individual tags, e.g. "film" and "games"
"""
return list(
v for v in validators
if any(t in v.tags for t in queries)
)
def setup(query):
"""Register plug-ins based on search query
Arguments:
query (str): Space-separated search query, e.g. "film games"
"""
validators = search(queries=query.split())
pyblish.api.deregister_all_plugins()
for plugin in validators + [CollectInstances, ExtractCharacter]:
pyblish.api.register_plugin(plugin)
setup("geometry rigging")
context = pyblish.util.publish()
for result in context.data("results"):
if result["instance"] is None:
continue
print("{instance.id} + {plugin.id} = {success}".format(**result))
# MyInstance + ValidateUVOverlap = True
# MyInstance + ValidateMeshDensity = True
# MyInstance + ValidateEntropy = True
# MyInstance + ValidateDefaultPose = True
# MyInstance + ExtractCharacter = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment