[Grok-dev] Re: big grok refactoring
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Wed Feb 7 09:32:25 EST 2007
> I spoke too fast, I just realized that grokking a package would also
> grok meta.py and this would re-grok the grokkers. It may not be harmful
> in operation as those grokkers would just be re-registered, but not pretty.
(reviving an older discussion)
It's not pretty indeed: now that my application defines its own
grokker, this grokker is registered twice: first while grokking my
meta.py (triggered from my meta.zcml) and then again during 'normal'
grok time. As a result, the component I'm grokking is doing its work
twice.
I wonder if the solution is not rather simple (but then again, I might
not see its implications). Here's a proposal for a small patch. Would
this work?
Index: src/grok/grokker.py
==============================================
--- src/grok/grokker.py (revision 72426)
+++ src/grok/grokker.py (working copy)
@@ -6,18 +6,18 @@
self.clear()
def clear(self):
- self._grokkers = []
+ self._grokkers = {}
# register the meta grokkers manually as we can't grok those
self.registerGrokker(ClassGrokkerGrokker())
self.registerGrokker(InstanceGrokkerGrokker())
self.registerGrokker(ModuleGrokkerGrokker())
def registerGrokker(self, grokker):
- self._grokkers.append(grokker)
+ self._grokkers[grokker.__class__] = grokker
def _getGrokkersInOrder(self):
# sort grokkers by priority
- grokkers = sorted(self._grokkers,
+ grokkers = sorted(self._grokkers.values(),
key=lambda grokker: grokker.priority)
# we want to handle high priority first
grokkers.reverse()
@@ -25,7 +25,7 @@
def scan(self, module_info):
components = {}
- for grokker in self._grokkers:
+ for grokker in self._grokkers.values():
if isinstance(grokker, grok.ModuleGrokker):
continue
components[grokker.component_class] = []
Tests pass, my grokker is only registered once and thus my components are too.
kind regards,
jw
--
Jan-Wijbrand Kolman
More information about the Grok-dev
mailing list