Skip to content

Commit

Permalink
Merge pull request #129 from mottosso/master
Browse files Browse the repository at this point in the history
Complementing Pyblish Frontend
  • Loading branch information
mottosso committed Dec 1, 2014
2 parents cc210ae + 8fceee4 commit b26e946
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ pyblish Changelog

This contains all major version changes between pyblish releases.

Version 1.0.11
--------------

- Added ability to process individual instances from within context

Version 1.0.10
--------------

Expand Down
8 changes: 7 additions & 1 deletion pyblish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ def log(cls):

module = cls.__module__
name = cls.__name__
logname = "%s.%s" % (module, name)

# Package name appended, for filtering of LogRecord instances
logname = "pyblish.%s.%s" % (module, name)
cls.log = logging.getLogger(logname)

# All messages are handled by root-logger
cls.log.propagate = True

return cls


Expand Down
27 changes: 21 additions & 6 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ def __str__(self):
def __repr__(self):
return u"%s.%s(%r)" % (__name__, type(self).__name__, self.__str__())

def process(self, context):
def process(self, context, instances=None):
"""Perform processing upon context `context`
Arguments:
context (Context): Context to process
instances (list): Limit which instances to process
.. note:: If an instance contains the data "publish" and that data is
`False` the instance will not be processed.
Injected data during processing:
- `__is_processed__`: Whether or not the instance was processed
- `__processed_by__`: Plugins which processed the given instance
Expand Down Expand Up @@ -176,13 +179,25 @@ def process(self, context):
for instance in compatible_instances:
if instance.has_data('publish'):
if instance.data('publish', default=True) is False:
self.log.info("Skipping %s" % instance)
self.log.info("Skipping %s, "
"publish-flag was false" % instance)
continue

elif not config['publish_by_default']:
self.log.info("Skipping %s" % instance)
self.log.info("Skipping %s, "
"no publish-flag was "
"set, and publishing "
"by default is False" % instance)
continue

# Limit instances to those specified in `instances`
if instances is not None:
if not instance.data("name") in instances:
self.log.info("Skipping %s, "
"not included in "
"exclusion list" % instance)
continue

self.log.info("Processing instance: \"%s\"" % instance)

# Inject data
Expand Down Expand Up @@ -972,11 +987,11 @@ def _isvalid(plugin):
"""Validate plugin"""

if plugin.order is None:
log.error("Plug-in must have an order")
log.error("Plug-in must have an order: %s" % plugin)
return False

if not isinstance(plugin.requires, basestring):
log.error("Plug-in requires must be of type string")
log.error("Plug-in requires must be of type string: %s" % plugin)
return False

# Helper functions
Expand Down
27 changes: 26 additions & 1 deletion pyblish/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import pyblish.lib
import pyblish.plugin

# from pyblish.vendor.nose.tools import raises
from pyblish.tests.lib import (
setup_full, teardown)
from pyblish.vendor.nose.tools import with_setup

# Setup
HOST = 'python'
Expand Down Expand Up @@ -62,5 +64,28 @@ def test_instance_equality():
assert inst2 == inst3


@with_setup(setup_full, teardown)
def test_limited_to_instances():
"""Only process instances specified in argument `instances`"""
ctx = pyblish.plugin.Context()

for name in ("Instance01", "Instance02", "Instance03"):
inst = ctx.create_instance(name=name)
inst.set_data("family", "full")

plugin = pyblish.plugin.discover(regex="ValidateInstance")[0]
assert plugin

for inst, err in plugin().process(ctx, instances=["Instance01",
"Instance03"]):
assert err is None

for inst in ctx:
name = inst.data("name")
if name in ["Instance01", "Instance03"]:
assert inst.data('validated', False) is True
if name == "Instance02":
assert inst.data('validated', False) is False

if __name__ == '__main__':
test_add_remove_instances()
2 changes: 1 addition & 1 deletion pyblish/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_PATCH = 10
VERSION_PATCH = 11

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

0 comments on commit b26e946

Please sign in to comment.