diff --git a/hyde/plugin.py b/hyde/plugin.py index 01153c1..ad8a7d0 100644 --- a/hyde/plugin.py +++ b/hyde/plugin.py @@ -8,11 +8,12 @@ from hyde import loader from hyde.exceptions import HydeException from hyde.fs import File -from hyde.util import getLoggerWithNullHandler, first_match +from hyde.util import getLoggerWithNullHandler, first_match, discover_executable from hyde.model import Expando from functools import partial +import os import re import subprocess import traceback @@ -255,6 +256,13 @@ class CLTransformer(Plugin): raise self.template.exception_class( self.executable_not_found_message) + # Honour the PATH environment variable. + if not os.path.isabs(app_path): + app_path = discover_executable(app_path) + if app_path is None: + raise self.template.exception_class( + self.executable_not_found_message) + app = File(app_path) if not app.exists: diff --git a/hyde/util.py b/hyde/util.py index eff646e..0aced1b 100644 --- a/hyde/util.py +++ b/hyde/util.py @@ -2,6 +2,7 @@ Module for python 2.6 compatibility. """ import logging +import os import sys from itertools import ifilter, izip, tee @@ -122,3 +123,14 @@ def first_match(predicate, iterable): if predicate(item): return item return None + +def discover_executable(name): + """ + Finds an executable in the path list provided by the PATH + environment variable. + """ + for path in os.environ['PATH'].split(os.pathsep): + full_name = os.path.join(path, name) + if os.path.exists(full_name): + return full_name + return None