Permalink
Browse files

plugins: Add needs_static_build flag to toggle Makefile use.

Not every plugin needs to build static files. Instead of assuming they
do, the plugins will have to opt-in to having their Makefile called.
  • Loading branch information...
1 parent 4e3ca52 commit 78501dbf6d37eb5f5a99c7d83e8bf53f3480c0ec @spladug spladug committed Sep 2, 2012
Showing with 12 additions and 16 deletions.
  1. +5 −4 r2/Makefile.py
  2. +2 −3 r2/r2/lib/js.py
  3. +5 −9 r2/r2/lib/plugin.py
View
@@ -27,12 +27,13 @@
print 'POTFILE := ' + os.path.join(I18N_PATH, 'r2.pot')
-plugins = list(PluginLoader.available_plugins())
-print 'PLUGINS := ' + ' '.join(plugin.name for plugin in plugins)
+plugins = PluginLoader()
+print 'PLUGINS := ' + ' '.join(plugin.name for plugin in plugins
+ if plugin.needs_static_build)
for plugin in plugins:
- print 'PLUGIN_PATH_%s := %s' % (plugin.name, PluginLoader.plugin_path(plugin))
+ print 'PLUGIN_PATH_%s := %s' % (plugin.name, plugin.path)
-js.load_plugin_modules()
+js.load_plugin_modules(plugins)
modules = dict((k, m) for k, m in js.module.iteritems())
print 'JS_MODULES := ' + ' '.join(modules.iterkeys())
outputs = []
View
@@ -326,9 +326,8 @@ def use(self):
def use(*names):
return "\n".join(module[name].use() for name in names)
-def load_plugin_modules():
- from r2.lib.plugin import PluginLoader
- for plugin in PluginLoader():
+def load_plugin_modules(plugins):
+ for plugin in plugins:
plugin.add_js(module)
commands = {}
View
@@ -30,11 +30,16 @@ class Plugin(object):
js = {}
config = {}
live_config = {}
+ needs_static_build = False
def __init__(self, entry_point):
self.entry_point = entry_point
@property
+ def name(self):
+ return self.entry_point.name
+
+ @property
def path(self):
module = sys.modules[type(self).__module__]
return os.path.dirname(module.__file__)
@@ -104,15 +109,6 @@ def __getitem__(self, key):
def available_plugins(name=None):
return pkg_resources.iter_entry_points('r2.plugin', name)
- @staticmethod
- def plugin_path(plugin):
- if isinstance(plugin, str):
- try:
- plugin = pkg_resources.iter_entry_points("r2.plugin", name).next()
- except StopIteration:
- return None
- return os.path.join(plugin.dist.location, plugin.module_name)
-
def load_plugins(self):
g = config['pylons.g']
for plugin in self:

0 comments on commit 78501db

Please sign in to comment.