Skip to content

Commit

Permalink
Merge pull request #247 from mottosso/master
Browse files Browse the repository at this point in the history
Emitting "published", "validated", "extracted" and "integrated" events.
  • Loading branch information
mottosso committed Feb 7, 2016
2 parents 58ba367 + 139f65d commit 6c1a205
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 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.3.1
-------------

- Enhancement: pyblish.api.deregister_callback now throws an error on missing callback

Version 1.3.0
-------------

Expand Down
7 changes: 5 additions & 2 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,13 @@ def deregister_callback(signal, callback):
Arguments:
signal (string): Name of signal to deregister the callback with.
callback (func): Function to execute when a signal is emitted.
Raises:
KeyError on missing signal
ValueError on missing callback
"""

if callback in _registered_callbacks[signal]:
_registered_callbacks[signal].remove(callback)
_registered_callbacks[signal].remove(callback)


def deregister_all_callbacks():
Expand Down
29 changes: 20 additions & 9 deletions pyblish/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import warnings

# Local library
from . import logic, plugin
from . import logic, plugin, lib

log = logging.getLogger("pyblish.util")

Expand Down Expand Up @@ -92,31 +92,42 @@ def publish(context=None, plugins=None, **kwargs):
if error is not None:
print(error)

lib.emit("published", context=context)

return context


def select(*args, **kwargs):
def collect(*args, **kwargs):
"""Convenience function for selection"""
return _convenience(0.5, *args, **kwargs)
context = _convenience(0.5, *args, **kwargs)
lib.emit("collected", context=context)
return context


def validate(*args, **kwargs):
"""Convenience function for validation"""
return _convenience(1.5, *args, **kwargs)
context = _convenience(1.5, *args, **kwargs)
lib.emit("validated", context=context)
return context


def extract(*args, **kwargs):
"""Convenience function for extraction"""
return _convenience(2.5, *args, **kwargs)
context = _convenience(2.5, *args, **kwargs)
lib.emit("extracted", context=context)
return context


def conform(*args, **kwargs):
def integrate(*args, **kwargs):
"""Convenience function for conform"""
return _convenience(3.5, *args, **kwargs)
context = _convenience(3.5, *args, **kwargs)
lib.emit("integrated", context=context)
return context


collect = select
integrate = conform
# Backwards compatibility
select = collect
conform = integrate
run = publish # Alias


Expand Down
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 = 3
VERSION_PATCH = 0
VERSION_PATCH = 1

version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
Expand Down
38 changes: 38 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pyblish.api
import pyblish.util
from nose.tools import (
with_setup,
)
from . import lib


@with_setup(lib.setup_empty)
def test_published_event():
"""published is emitted upon finished publish"""

count = {"#": 0}

def on_published(context):
assert isinstance(context, pyblish.api.Context)
count["#"] += 1

pyblish.api.register_callback("published", on_published)
pyblish.util.publish()

assert count["#"] == 1, count


@with_setup(lib.setup_empty)
def test_validated_event():
"""validated is emitted upon finished validation"""

count = {"#": 0}

def on_validated(context):
assert isinstance(context, pyblish.api.Context)
count["#"] += 1

pyblish.api.register_callback("validated", on_validated)
pyblish.util.validate()

assert count["#"] == 1, count
10 changes: 10 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ def other_callback(data=None):

pyblish.plugin.deregister_callback("mySignal", my_callback)

assert_raises(
ValueError,
pyblish.plugin.deregister_callback,
"mySignal", my_callback)

assert_raises(
KeyError,
pyblish.plugin.deregister_callback,
"notExist", my_callback)

msg = "Deregistering a callback failed"
data = {"mySignal": []}
assert pyblish.plugin.registered_callbacks() == data, msg
Expand Down

0 comments on commit 6c1a205

Please sign in to comment.