[Checkins] SVN: grokcore.component/branches/1.x/ Extend the ZCML directive to be able to customize the exclude filter.
Sylvain Viollon
sylvain at infrae.com
Tue May 25 07:00:25 EDT 2010
Log message for revision 112678:
Extend the ZCML directive to be able to customize the exclude filter.
Add testing to the list of default excluded names.
pep8 fixes.
Changed:
U grokcore.component/branches/1.x/CHANGES.txt
U grokcore.component/branches/1.x/README.txt
U grokcore.component/branches/1.x/setup.py
U grokcore.component/branches/1.x/src/grokcore/component/zcml.py
-=-
Modified: grokcore.component/branches/1.x/CHANGES.txt
===================================================================
--- grokcore.component/branches/1.x/CHANGES.txt 2010-05-25 10:57:30 UTC (rev 112677)
+++ grokcore.component/branches/1.x/CHANGES.txt 2010-05-25 11:00:25 UTC (rev 112678)
@@ -4,9 +4,12 @@
1.9 (unreleased)
----------------
-- Nothing changed yet.
+* Add ``testing`` to the default exclude_filter.
+* Add the possiblity to extend the exclude filter from the ZCML with
+ the attribute ``exclude``.
+
1.8 (2009-12-13)
----------------
@@ -27,7 +30,7 @@
* Add support for registering global adapters at module level::
grok.global_adapter(factory, (IAdapted1, IAdapted2,), IProvided, name=u"name")
-
+
Only 'factory' is required. If only a single interface is adapted, the
second argument may be a single interface instead of a tuple. If the
component has declared adapted/provided interfaces, the second and third
@@ -35,11 +38,11 @@
* Add support for an @provider decorator to let a function directly provide
an interface::
-
+
@grok.provider(IFoo, IBar)
def some_function():
...
-
+
This is equivalent to doing alsoProvides(some_function, IFoo, IBar).
* Add support for named adapters with the @adapter decorator::
@@ -78,7 +81,7 @@
1.4 (2008-06-11)
----------------
-* Ported class grokkers to make use of further improvements in Martian.
+* Ported class grokkers to make use of further improvements in Martian.
This requires Martian 0.10.
1.3 (2008-05-14)
Modified: grokcore.component/branches/1.x/README.txt
===================================================================
--- grokcore.component/branches/1.x/README.txt 2010-05-25 10:57:30 UTC (rev 112677)
+++ grokcore.component/branches/1.x/README.txt 2010-05-25 11:00:25 UTC (rev 112678)
@@ -170,22 +170,22 @@
class ISchema(Interface):
"""This schema will be used to power a z3c.form form"""
-
+
field = zope.schema.TextLine(title=u"Sample field")
-
+
...
label_override = z3c.form.widget.StaticWidgetAttribute(
u"Override label", field=ISchema['field'])
-
+
grokcore.component.global_adapter(label_override, name=u"label")
-
+
In the example above, the provided and adapted interfaces are deduced from the
object returned by the ``StaticWidgetAttribute`` factory. The full syntax
for global_adapter is::
global_adapter(factory, (IAdapted1, IAdapted2,), IProvided, name=u"name")
-
+
The factory must be a callable (the adapter factory). Adapted interfaces are
given as a tuple. You may use a single interface instead of a one-element
tuple for single adapters. The provided interface is given as shown. The name
@@ -342,3 +342,15 @@
registered as a subscriber for the event interface. In case of
object events, the event handler is registered as a subscriber for
the object type and the event interface.
+
+
+ZCML directive
+--------------
+
+``<grok:grok package="." exclude="mythings" />``
+
+ The ``grok`` directive located in the namespace
+ ``http://namespaces.zope.org/grok`` will grok the package pointed by
+ the ``package`` attribute. The optional ``exclude`` attribute can
+ specify a name of a package or module that if encountered won't be
+ grokked.
Modified: grokcore.component/branches/1.x/setup.py
===================================================================
--- grokcore.component/branches/1.x/setup.py 2010-05-25 10:57:30 UTC (rev 112677)
+++ grokcore.component/branches/1.x/setup.py 2010-05-25 11:00:25 UTC (rev 112678)
@@ -40,6 +40,7 @@
'zope.component',
'zope.configuration',
'zope.interface',
+ 'zope.schema',
'zope.testing',
],
tests_require=tests_require,
Modified: grokcore.component/branches/1.x/src/grokcore/component/zcml.py
===================================================================
--- grokcore.component/branches/1.x/src/grokcore/component/zcml.py 2010-05-25 10:57:30 UTC (rev 112677)
+++ grokcore.component/branches/1.x/src/grokcore/component/zcml.py 2010-05-25 11:00:25 UTC (rev 112678)
@@ -15,40 +15,57 @@
from zope.interface import Interface
from zope.configuration.fields import GlobalObject
-#from zope.configuration.config import ConfigurationMachine
+from zope.schema import TextLine
import martian
-#from martian import scan
-#from martian.error import GrokError
+
class IGrokDirective(Interface):
"""Grok a package or module."""
package = GlobalObject(
title=u"Package",
description=u"The package or module to be analyzed by grok.",
- required=False,
- )
+ required=False)
+ exclude = TextLine(
+ title=u"Exclude",
+ description=u"Name to exclude in the grokking process.",
+ required=False)
+
+
# add a cleanup hook so that grok will bootstrap itself again whenever
# the Component Architecture is torn down.
def resetBootstrap():
# we need to make sure that the grokker registry is clean again
the_module_grokker.clear()
+
from zope.testing.cleanup import addCleanUp
addCleanUp(resetBootstrap)
the_multi_grokker = martian.MetaMultiGrokker()
the_module_grokker = martian.ModuleGrokker(the_multi_grokker)
+
def skip_tests(name):
- return name in ['tests', 'ftests']
+ return name in ['tests', 'ftests', 'testing']
-def grokDirective(_context, package):
- do_grok(package.__name__, _context)
-def do_grok(dotted_name, config):
+def grokDirective(_context, package, exclude=None):
+ if not exclude:
+ exclude = None
+ do_grok(package.__name__, _context, extra_exclude=exclude)
+
+
+def do_grok(dotted_name, config, extra_exclude=None):
+ if extra_exclude is not None:
+
+ def exclude_filter(name):
+ return skip_tests(name) or extra_exclude == name
+
+ else:
+ exclude_filter = skip_tests
+
martian.grok_dotted_name(
- dotted_name, the_module_grokker, exclude_filter=skip_tests,
- config=config
- )
+ dotted_name, the_module_grokker, exclude_filter=exclude_filter,
+ config=config)
More information about the checkins
mailing list