From 92b0ffbdf6bcd4568552586738a680e048212035 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Mon, 30 Mar 2015 15:01:33 +0100 Subject: [PATCH 1/3] Adding repair documentation and default implementations. Note that this may change how you currently detect whether a plug-in has implemented repair; if you did hasattr(plugin, "repair_instance") then this will no longer work, and you will instead need to compare superclass.repair_instance != subclass.repair_instance. --- CHANGES | 5 +++++ pyblish/plugin.py | 28 ++++++++++++++++++++++++++++ pyblish/util.py | 3 ++- pyblish/version.py | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 70647fe5..2f29e786 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,11 @@ pyblish Changelog This contains all major version changes between pyblish releases. +Version 1.0.15 +-------------- + +- API: Plugin.repair_* documented and implemented by default + Version 1.0.14 -------------- diff --git a/pyblish/plugin.py b/pyblish/plugin.py index 97dc5886..a4a2e485 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -273,6 +273,34 @@ def process_instance(self, instance): """ + def repair_instance(self, instance): + """Repair given `instance` + + Implement this method in your subclasses in order for + the given instance to be repaired. + + Returns: + None + + Raises: + Any error + + """ + + def repair_context(self, context): + """Repair given `context` + + Implement this method in your subclasses in order for + the context to be repaired. + + Returns: + None + + Raises: + Any error + + """ + def process_all(self, context): """Convenience method of the above :meth:`process` diff --git a/pyblish/util.py b/pyblish/util.py index d224430a..9749c7ef 100644 --- a/pyblish/util.py +++ b/pyblish/util.py @@ -49,7 +49,8 @@ 'extract', 'conform', 'publish', - 'publish_all'] + 'publish_all', + 'validate_all'] def publish(context=None, diff --git a/pyblish/version.py b/pyblish/version.py index 9fb6ce58..5f80284f 100644 --- a/pyblish/version.py +++ b/pyblish/version.py @@ -1,7 +1,7 @@ VERSION_MAJOR = 1 VERSION_MINOR = 0 -VERSION_PATCH = 14 +VERSION_PATCH = 15 version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) version = '%i.%i.%i' % version_info From a6129643fa875bae900e73ce7e8a2e8c7ade65ec Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Mon, 6 Apr 2015 11:16:44 +0100 Subject: [PATCH 2/3] Added lib.where --- pyblish/lib.py | 32 +++++++++++++++++++ .../tests/plugins/full/validate_instances.py | 2 +- pyblish/tests/test_lib.py | 10 ++++++ pyblish/tests/{test_main.py => test_util.py} | 10 ++++-- 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 pyblish/tests/test_lib.py rename pyblish/tests/{test_main.py => test_util.py} (90%) diff --git a/pyblish/lib.py b/pyblish/lib.py index bb2996ea..861fd096 100644 --- a/pyblish/lib.py +++ b/pyblish/lib.py @@ -207,3 +207,35 @@ def _resolve_name(name, package, level): __import__(name) return sys.modules[name] + + +def where(program): + r"""Parse PATH for executables + + Windows note: + PATHEXT yields possible suffixes, such as .exe, .bat and .cmd + + Usage: + >> where("python") + 'c:\\python27\\python.exe' + + """ + + suffixes = [""] + + try: + # Append Windows suffixes, such as .exe, .bat and .cmd + suffixes.extend(os.environ.get("PATHEXT").split(os.pathsep)) + except: + pass + + for path in os.environ["PATH"].split(os.pathsep): + + # A path may be empty. + if not path: + continue + + for suffix in suffixes: + full_path = os.path.join(path, program + suffix) + if os.path.isfile(full_path): + return full_path diff --git a/pyblish/tests/plugins/full/validate_instances.py b/pyblish/tests/plugins/full/validate_instances.py index f0323b0a..3b01f77a 100644 --- a/pyblish/tests/plugins/full/validate_instances.py +++ b/pyblish/tests/plugins/full/validate_instances.py @@ -3,7 +3,7 @@ @pyblish.api.log -class ValidateInstance(pyblish.api.Validator): +class ValidateInstances(pyblish.api.Validator): hosts = ['python'] families = ['full'] version = (0, 1, 0) diff --git a/pyblish/tests/test_lib.py b/pyblish/tests/test_lib.py new file mode 100644 index 00000000..83c690a6 --- /dev/null +++ b/pyblish/tests/test_lib.py @@ -0,0 +1,10 @@ +import sys +import pyblish.lib + +from pyblish.vendor.nose.tools import * + + +def test_where(): + """lib.where works fine""" + exe = pyblish.lib.where("python") + assert_equals(sys.executable.lower(), exe.lower()) diff --git a/pyblish/tests/test_main.py b/pyblish/tests/test_util.py similarity index 90% rename from pyblish/tests/test_main.py rename to pyblish/tests/test_util.py index a517aef7..b4df1bcc 100644 --- a/pyblish/tests/test_main.py +++ b/pyblish/tests/test_util.py @@ -12,8 +12,14 @@ @with_setup(setup_full, teardown) def test_publish_all(_): """publish() calls upon each convenience function""" - ctx = pyblish.plugin.Context() - pyblish.util.publish(context=ctx) + plugins = pyblish.plugin.discover() + + assert "ConformInstances" in [p.__name__ for p in plugins] + assert "SelectInstances" in [p.__name__ for p in plugins] + assert "ValidateInstances" in [p.__name__ for p in plugins] + assert "ExtractInstances" in [p.__name__ for p in plugins] + + ctx = pyblish.util.publish() for inst in ctx: assert inst.data('selected') is True From c29311d29cc27fdacb1a2490533a81fca3e81434 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Mon, 6 Apr 2015 14:39:32 +0100 Subject: [PATCH 3/3] Added .id attribute --- CHANGES | 2 ++ pyblish/lib.py | 8 ++++++++ pyblish/plugin.py | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGES b/CHANGES index 2f29e786..ffd277f3 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ Version 1.0.15 -------------- - API: Plugin.repair_* documented and implemented by default +- API: Added lib.where() +- API: Added `.id` attribute to instances and plug-ins Version 1.0.14 -------------- diff --git a/pyblish/lib.py b/pyblish/lib.py index 861fd096..0a0ac555 100644 --- a/pyblish/lib.py +++ b/pyblish/lib.py @@ -8,6 +8,14 @@ 'LPT1', 'LPT2', 'LPT3', 'PRN', 'NUL') +class classproperty(object): + def __init__(self, getter): + self.getter = getter + + def __get__(self, instance, owner): + return self.getter(owner) + + def log(cls): """Decorator for attaching a logger to the class `cls` diff --git a/pyblish/plugin.py b/pyblish/plugin.py index a4a2e485..b50d17df 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -152,6 +152,10 @@ def __str__(self): def __repr__(self): return u"%s.%s(%r)" % (__name__, type(self).__name__, self.__str__()) + @pyblish.lib.classproperty + def id(cls): + return cls.__name__ + def process(self, context, instances=None): """Perform processing upon context `context` @@ -595,6 +599,10 @@ def __repr__(self): def __str__(self): return self.name + @property + def id(self): + return self.name + def __init__(self, name, parent=None): super(Instance, self).__init__() assert isinstance(name, basestring)