From 9c5f1c380e19693532b426fa4a47cbeef1115b4a Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Mon, 4 Aug 2008 14:05:57 -0400 Subject: [PATCH] Allow plugins to inherit from other plugins When plugins inherit from other plugins, we need to simplify "bases" or else python may not be able to derive an acceptable MRO. --- yap/yap.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/yap/yap.py b/yap/yap.py index 7e79b25..7119f48 100644 --- a/yap/yap.py +++ b/yap/yap.py @@ -1154,20 +1154,30 @@ commits cannot be made. print >> sys.stderr, " valid commands: help init clone add rm stage unstage status revert commit uncommit log show diff branch switch point cherry-pick repo track push fetch update history resolved version" def yap_metaclass(name, bases, dct): - plugindir = os.path.join("~", ".yap", "plugins", "*.py") - plugins = [] + plugindir = os.path.join("~", ".yap", "plugins") + plugindir = os.path.expanduser(plugindir) + sys.path.insert(0, plugindir) + plugindir = os.path.join(plugindir, "*.py") + + plugins = set() for p in glob.glob(os.path.expanduser(plugindir)): - glbls = {} - execfile(p, glbls) - for k, cls in glbls.items(): + plugin = os.path.basename(p).replace('.py', '') + m = __import__(plugin) + for k in dir(m): + cls = m.__dict__[k] if not type(cls) == type: continue if not issubclass(cls, YapCore): continue if cls is YapCore: continue - plugins.append(cls) - bases = plugins + list(bases) + plugins.add(cls) + + p2 = plugins.copy() + for cls in plugins: + p2 -= set(cls.__bases__) + plugins = p2 + bases = list(plugins) + list(bases) return type(name, tuple(bases), dct) class Yap(YapCore): -- 2.11.4.GIT