Skip to content

Commit

Permalink
Merge pull request #169 from mottosso/master
Browse files Browse the repository at this point in the history
Maintenance update
  • Loading branch information
mottosso committed Apr 7, 2015
2 parents 7ff8f0c + c29311d commit c1be153
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ pyblish Changelog

This contains all major version changes between pyblish releases.

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
--------------

Expand Down
40 changes: 40 additions & 0 deletions pyblish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -207,3 +215,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
36 changes: 36 additions & 0 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -273,6 +277,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`
Expand Down Expand Up @@ -567,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)
Expand Down
2 changes: 1 addition & 1 deletion pyblish/tests/plugins/full/validate_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions pyblish/tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -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())
10 changes: 8 additions & 2 deletions pyblish/tests/test_main.py → pyblish/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyblish/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'extract',
'conform',
'publish',
'publish_all']
'publish_all',
'validate_all']


def publish(context=None,
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 = 0
VERSION_PATCH = 14
VERSION_PATCH = 15

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

0 comments on commit c1be153

Please sign in to comment.