Skip to content

Commit

Permalink
Merge pull request #200 from mottosso/master
Browse files Browse the repository at this point in the history
1.1.2
  • Loading branch information
mottosso committed Jun 25, 2015
2 parents 9290a8c + 583d74d commit 6c33320
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ pyblish Changelog

This contains all major version changes between pyblish releases.

Version 1.1.2
-------------

- Logic: Excluding SimplePlugin and Selectors from Default test (See #198)
- BACKWARDS INCOMPATIBLE order now supports being decremented (see #199)

Version 1.1.1
-------------

Expand Down
33 changes: 33 additions & 0 deletions pyblish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@
'LPT1', 'LPT2', 'LPT3', 'PRN', 'NUL')



def inrange(number, base, offset=0):
r"""Evaluate whether `number` is within `base` +- `offset`
Lower bound is *included* whereas upper bound is *excluded*
so as to allow for ranges to be stacked up against each other.
For example, an offset of 0.5 and a base of 1 evenly stacks
up against a base of 2 with identical offset.
Arguments:
number (float): Number to consider
base (float): Center of range
offset (float, optional): Amount of offset from base
Usage:
>>> inrange(0, base=1, offset=0.5)
False
>>> inrange(0.4, base=1, offset=0.5)
False
>>> inrange(1.4, base=1, offset=0.5)
True
>>> # Lower bound is included
>>> inrange(0.5, base=1, offset=0.5)
True
>>> # Upper bound is excluded
>>> inrange(1.5, base=1, offset=0.5)
False
"""

return base - offset <= number < base + offset


class MessageHandler(logging.Handler):
def __init__(self, records, *args, **kwargs):
# Not using super(), for compatibility with Python 2.6
Expand Down
4 changes: 2 additions & 2 deletions pyblish/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback

import pyblish
import lib


class TestFailed(Exception):
Expand Down Expand Up @@ -37,9 +38,8 @@ 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?
if lib.inrange(order, base=1, offset=0.5):
return "failed validation"
return


def process(func, plugins, context, test=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pyblish.api.log
class SelectCurrentDate(pyblish.api.Selector):
class CollectCurrentDate(pyblish.api.Collector):
"""Inject the current time into the Context"""

hosts = ['*']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pyblish.api.log
class SelectCurrentUser(pyblish.api.Selector):
class CollectCurrentUser(pyblish.api.Collector):
"""Inject the currently logged on user into the Context"""

hosts = ['*']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pyblish.api.log
class SelectCurrentWorkingDirectory(pyblish.api.Selector):
class CollectCurrentWorkingDirectory(pyblish.api.Collector):
"""Inject the current working directory into Context"""

hosts = ['*']
Expand Down
10 changes: 9 additions & 1 deletion pyblish/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ def publish(context=None, plugins=None, **kwargs):
context=context):

if isinstance(result, pyblish.logic.TestFailed):
log.error("Stopped due to: %s (%s)" % (result, result.vars))
log.error("Stopped due to: %s" % result)
break

elif isinstance(result, Exception):
log.error("An unexpected error happened: %s" % result)
break

error = result["error"]
if error is not None:
print(error)

return context


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 = 1
VERSION_PATCH = 1
VERSION_PATCH = 2

version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
Expand Down
1 change: 1 addition & 0 deletions tests/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ def teardown():

os.environ["PYBLISHPLUGINPATH"] = ENVIRONMENT
pyblish.api.deregister_all_plugins()
pyblish.api.deregister_test()
45 changes: 45 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,32 @@ def process(self, context):
assert_equals(count["#"], 0)


@with_setup(lib.setup_empty, lib.teardown)
def test_custom_test():
"""Registering a custom test works fine"""

count = {"#": 0}

def custom_test(**vars):
print "I accept anything"
return

class MyValidator(pyblish.api.Validator):
def process(self, context):
assert False, "I won't stop the extractor"

class MyExtractor(pyblish.api.Extractor):
def process(self, context):
print "I came, I saw, I extracted.."
count["#"] += 1

pyblish.api.register_plugin(MyValidator)
pyblish.api.register_plugin(MyExtractor)
pyblish.api.register_test(custom_test)

pyblish.util.publish()
assert_equals(count["#"], 1)


def test_logic_process():
"""logic.process works fine"""
Expand Down Expand Up @@ -222,6 +245,7 @@ def process(self, context):

assert_equals(len(context), 1)


@with_setup(lib.setup_empty, lib.teardown)
def test_active():
"""An inactive plug-in won't be processed by default logic"""
Expand Down Expand Up @@ -261,3 +285,24 @@ def process(self, instance):
assert not isinstance(result, pyblish.logic.TestFailed), result

assert_equals(count["#"], 201)


@with_setup(lib.setup_empty, lib.teardown)
def test_failing_selector():
"""Failing Selector should not abort publishing"""

count = {"#": 0}

class MySelector(pyblish.api.Selector):
def process(self, context):
assert False, "I shouldn't stop Extraction"

class MyExtractor(pyblish.api.Extractor):
def process(self):
count["#"] += 1

pyblish.api.register_plugin(MySelector)
pyblish.api.register_plugin(MyExtractor)

pyblish.util.publish()
assert_equals(count["#"], 1)

0 comments on commit 6c33320

Please sign in to comment.