From b39464ac639029e55f59adede830af83cabec92a Mon Sep 17 00:00:00 2001 From: Lakshmi Vyasarajan Date: Wed, 9 Nov 2011 17:53:30 +0530 Subject: [PATCH] Issue #100: Minor fixes to the nice /Users/lakshmivyas/.environments/hyde/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin based exec discovery by @nud --- CHANGELOG.rst | 3 +-- hyde/ext/plugins/less.py | 6 ++++-- hyde/ext/plugins/uglify.py | 6 ++++-- hyde/plugin.py | 20 ++++++++++++++------ hyde/tests/ext/test_less.py | 4 ---- hyde/tests/ext/test_uglify.py | 23 ++--------------------- hyde/util.py | 2 +- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7f077991..e1bed1e6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,8 +3,7 @@ Version 0.8.4c16 Thanks to @nud -* Bug Fix: Fix class name of `test_stylus` (Issue #97) - +* Bug Fix: Fix class name of `test_stylus` (Issue #97) Version 0.8.4c15 ============================================================ diff --git a/hyde/ext/plugins/less.py b/hyde/ext/plugins/less.py index d3c745af..f7242814 100644 --- a/hyde/ext/plugins/less.py +++ b/hyde/ext/plugins/less.py @@ -15,11 +15,13 @@ class LessCSSPlugin(CLTransformer): The plugin class for less css """ - default_app_path = "lessc" - def __init__(self, site): super(LessCSSPlugin, self).__init__(site) + @property + def executable_name(self): + return "lessc" + def begin_site(self): """ Find all the less css files and set their relative deploy path. diff --git a/hyde/ext/plugins/uglify.py b/hyde/ext/plugins/uglify.py index 298adfdd..e6a26645 100644 --- a/hyde/ext/plugins/uglify.py +++ b/hyde/ext/plugins/uglify.py @@ -11,11 +11,13 @@ class UglifyPlugin(CLTransformer): The plugin class for Uglify JS """ - default_app_path = "uglifyjs" - def __init__(self, site): super(UglifyPlugin, self).__init__(site) + @property + def executable_name(self): + return "uglifyjs" + @property def plugin_name(self): """ diff --git a/hyde/plugin.py b/hyde/plugin.py index a4034faa..e016b8a9 100644 --- a/hyde/plugin.py +++ b/hyde/plugin.py @@ -18,7 +18,6 @@ import subprocess import traceback - logger = getLoggerWithNullHandler('hyde.engine') class PluginProxy(object): @@ -207,6 +206,8 @@ class CLTransformer(Plugin): def plugin_name(self): """ The name of the plugin. Makes an intelligent guess. + + This is used to lookup the settings for the plugin. """ return self.__class__.__name__.replace('Plugin', '').lower() @@ -221,10 +222,11 @@ def defaults(self): return {} @property - def default_app_path(self): + def executable_name(self): """ - Default command line application path. Can be overridden - by specifying it in config. + The executable name for the plugin. This can be overridden in the + config. If a configuration option is not provided, this is used + to guess the complete path of the executable. """ return self.plugin_name @@ -237,7 +239,10 @@ def executable_not_found_message(self): return ("%(name)s executable path not configured properly. " "This plugin expects `%(name)s.app` to point " - "to the `%(name)s` executable." % {"name": self.plugin_name}) + "to the full path of the `%(exec)s` executable." % + { + "name":self.plugin_name, "exec": self.executable_name + }) @property def settings(self): @@ -256,12 +261,15 @@ def settings(self): def app(self): """ Gets the application path from the site configuration. + + If the path is not configured, attempts to guess the path + from the sytem path environment variable. """ try: app_path = getattr(self.settings, 'app') except AttributeError: - app_path = self.default_app_path + app_path = self.executable_name # Honour the PATH environment variable. if app_path is not None and not os.path.isabs(app_path): diff --git a/hyde/tests/ext/test_less.py b/hyde/tests/ext/test_less.py index f1cb12e2..b92042b6 100644 --- a/hyde/tests/ext/test_less.py +++ b/hyde/tests/ext/test_less.py @@ -29,10 +29,6 @@ def tearDown(self): def test_can_execute_less(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.less.LessCSSPlugin'] - paths = ['/usr/local/share/npm/bin/lessc'] - for path in paths: - if File(path).exists: - s.config.less = Expando(dict(app=path)) source = TEST_SITE.child('content/media/css/site.less') target = File(Folder(s.config.deploy_root_path).child('media/css/site.css')) gen = Generator(s) diff --git a/hyde/tests/ext/test_uglify.py b/hyde/tests/ext/test_uglify.py index 43a593ec..7ee91eff 100644 --- a/hyde/tests/ext/test_uglify.py +++ b/hyde/tests/ext/test_uglify.py @@ -22,7 +22,7 @@ def setUp(self): JS = TEST_SITE.child_folder('content/media/js') JS.make() UGLIFY_SOURCE.copy_contents_to(JS) - + def tearDown(self): TEST_SITE.delete() @@ -31,10 +31,6 @@ def test_can_uglify(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" - paths = ['/usr/local/share/npm/bin/uglifyjs'] - for path in paths: - if File(path).exists: - s.config.uglify = Expando(dict(app=path)) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) @@ -49,14 +45,7 @@ def test_uglify_with_extra_options(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "production" - paths = ['/usr/local/share/npm/bin/uglifyjs', '~/local/bin/uglifyjs', - '/usr/bin/uglifyjs', '~/bin/uglifyjs'] - uglify = [path for path in paths if File(path).exists] - if not uglify: - assert False, "Cannot find the uglify executable" - - uglify = uglify[0] - s.config.uglify = Expando(dict(app=uglify, args={"nc":""})) + s.config.uglify = Expando(dict(args={"nc":""})) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) @@ -72,14 +61,6 @@ def test_no_uglify_in_dev_mode(self): s = Site(TEST_SITE) s.config.plugins = ['hyde.ext.plugins.uglify.UglifyPlugin'] s.config.mode = "dev" - paths = ['/usr/local/share/npm/bin/uglifyjs', '~/local/bin/uglifyjs', - '/usr/bin/uglifyjs', '~/bin/uglifyjs'] - uglify = [path for path in paths if File(path).exists] - if not uglify: - assert False, "Cannot find the uglify executable" - - uglify = uglify[0] - s.config.uglify = Expando(dict(app=path)) source = TEST_SITE.child('content/media/js/jquery.js') target = File(Folder(s.config.deploy_root_path).child('media/js/jquery.js')) gen = Generator(s) diff --git a/hyde/util.py b/hyde/util.py index 0aced1b9..5305553e 100644 --- a/hyde/util.py +++ b/hyde/util.py @@ -133,4 +133,4 @@ def discover_executable(name): full_name = os.path.join(path, name) if os.path.exists(full_name): return full_name - return None + return None \ No newline at end of file