From 0f36d2970c1f6b5a48b8e9408adb19f8afb82d1c Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Wed, 10 Jun 2015 10:04:48 +0100 Subject: [PATCH 1/7] Fixes #198 --- pyblish/logic.py | 2 +- tests/lib.py | 1 + tests/test_logic.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/pyblish/logic.py b/pyblish/logic.py index afafe449..accf372d 100644 --- a/pyblish/logic.py +++ b/pyblish/logic.py @@ -37,7 +37,7 @@ 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 1 <= order < 2: # Did any validators fail? return "failed validation" return diff --git a/tests/lib.py b/tests/lib.py index ef1c1ad2..8987049a 100644 --- a/tests/lib.py +++ b/tests/lib.py @@ -42,3 +42,4 @@ def teardown(): os.environ["PYBLISHPLUGINPATH"] = ENVIRONMENT pyblish.api.deregister_all_plugins() + pyblish.api.deregister_test() diff --git a/tests/test_logic.py b/tests/test_logic.py index 93b8500b..ffa829e7 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -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""" @@ -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""" @@ -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) From 44a05321d453e57db1fdb736607f8ecfa78cee39 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Wed, 10 Jun 2015 15:58:53 +0100 Subject: [PATCH 2/7] Implemented #199 --- pyblish/lib.py | 33 +++++++++++++++++++++++++++++++++ pyblish/logic.py | 4 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pyblish/lib.py b/pyblish/lib.py index 7171c057..fdfc0853 100644 --- a/pyblish/lib.py +++ b/pyblish/lib.py @@ -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 diff --git a/pyblish/logic.py b/pyblish/logic.py index accf372d..be254315 100644 --- a/pyblish/logic.py +++ b/pyblish/logic.py @@ -5,6 +5,7 @@ import traceback import pyblish +import lib class TestFailed(Exception): @@ -37,9 +38,8 @@ def default_test(**vars): if vars["nextOrder"] >= 2: # If validation is done for order in vars["ordersWithError"]: - if 1 <= order < 2: # Did any validators fail? + if lib.inrange(order, base=1, offset=0.5): return "failed validation" - return def process(func, plugins, context, test=None): From c1b34cf691605707db5a5834f86f31c1a25e8357 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Wed, 10 Jun 2015 15:59:32 +0100 Subject: [PATCH 3/7] Including printing of exceptions with pyblish.util.publish --- pyblish/util.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyblish/util.py b/pyblish/util.py index a91a7932..bc3e3ed6 100644 --- a/pyblish/util.py +++ b/pyblish/util.py @@ -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 From dd0138021ccad53af4627c9329f23a3724ebb804 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Wed, 10 Jun 2015 16:01:01 +0100 Subject: [PATCH 4/7] Version bump --- CHANGES | 6 ++++++ pyblish/version.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 6bfd1364..31d4f1ce 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------------- diff --git a/pyblish/version.py b/pyblish/version.py index e6504523..c18d85d5 100644 --- a/pyblish/version.py +++ b/pyblish/version.py @@ -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 From ed3ddd207df5c354afde6739ddf69765470ff84c Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 11 Jun 2015 13:37:26 +0100 Subject: [PATCH 5/7] Testing compatibility with Python 3.4 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f39fae2c..ce160712 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: - 2.6 - 2.7 +- 3.4 install: - pip install coveralls script: From c19b5ab62531de9135256e5e5bfc89371ebfd38d Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 11 Jun 2015 14:26:15 +0100 Subject: [PATCH 6/7] Python 3.4 compatibility takes some amount of work --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ce160712..f39fae2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python python: - 2.6 - 2.7 -- 3.4 install: - pip install coveralls script: From 583d74d7b9e83bc5000f44737b84840a37e673df Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 11 Jun 2015 14:26:32 +0100 Subject: [PATCH 7/7] Select -> Collect --- .../plugins/{select_current_date.py => collect_current_date.py} | 2 +- .../plugins/{select_current_user.py => collect_current_user.py} | 2 +- ...orking_directory.py => collect_current_working_directory.py} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename pyblish/plugins/{select_current_date.py => collect_current_date.py} (86%) rename pyblish/plugins/{select_current_user.py => collect_current_user.py} (83%) rename pyblish/plugins/{select_current_working_directory.py => collect_current_working_directory.py} (79%) diff --git a/pyblish/plugins/select_current_date.py b/pyblish/plugins/collect_current_date.py similarity index 86% rename from pyblish/plugins/select_current_date.py rename to pyblish/plugins/collect_current_date.py index f0b36965..fd0a3fbb 100644 --- a/pyblish/plugins/select_current_date.py +++ b/pyblish/plugins/collect_current_date.py @@ -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 = ['*'] diff --git a/pyblish/plugins/select_current_user.py b/pyblish/plugins/collect_current_user.py similarity index 83% rename from pyblish/plugins/select_current_user.py rename to pyblish/plugins/collect_current_user.py index f1ad49a8..66d915b5 100644 --- a/pyblish/plugins/select_current_user.py +++ b/pyblish/plugins/collect_current_user.py @@ -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 = ['*'] diff --git a/pyblish/plugins/select_current_working_directory.py b/pyblish/plugins/collect_current_working_directory.py similarity index 79% rename from pyblish/plugins/select_current_working_directory.py rename to pyblish/plugins/collect_current_working_directory.py index c72abc88..f1454d04 100644 --- a/pyblish/plugins/select_current_working_directory.py +++ b/pyblish/plugins/collect_current_working_directory.py @@ -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 = ['*']