Skip to content

Commit

Permalink
Added lib.where
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Apr 6, 2015
1 parent 92b0ffb commit a612964
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
32 changes: 32 additions & 0 deletions pyblish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit a612964

Please sign in to comment.