From a6129643fa875bae900e73ce7e8a2e8c7ade65ec Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Mon, 6 Apr 2015 11:16:44 +0100 Subject: [PATCH] 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