Permalink
Browse files

prep for zope.configuration dependency removal in pyramid

  • Loading branch information...
1 parent f03167d commit 209cb31c8a2967fce553ffb556254a787e7ca505 @mcdonc mcdonc committed Sep 3, 2011
Showing with 80 additions and 15 deletions.
  1. +13 −0 CHANGES.txt
  2. +37 −13 pyramid_zcml/__init__.py
  3. +26 −0 pyramid_zcml/tests/test_units.py
  4. +3 −2 pyramid_zcml/tests/viewdecoratorapp/views/views.py
  5. +1 −0 setup.py
View
@@ -1,3 +1,16 @@
+Next release
+------------
+
+- Fix tests under 1.2a4+.
+
+- Depend explicitly on zope.configuration.
+
+- Use our a local PyramidConfigurationMachine when collecting ZCML actions,
+ and splice the locally collected actions onto the configurator context's
+ actions when ZCML processing is done. This provides Pyramid the freedom to
+ not rely on zope.configuration in the future, and somewhat futureproofs
+ ``pyramid_zcml`` from changes to action processing in Pyramid.
+
0.5 (2011-08-24)
----------------
@@ -8,6 +8,8 @@
from zope.configuration.fields import GlobalInterface
from zope.configuration.fields import GlobalObject
from zope.configuration.fields import Tokens
+from zope.configuration.xmlconfig import registerCommonDirectives
+from zope.configuration.config import ConfigurationMachine
from zope.interface import Interface
from zope.interface import implementedBy
@@ -28,7 +30,6 @@
from pyramid.threadlocal import get_current_registry
from zope.configuration import xmlconfig
-from zope.configuration.config import GroupingContextDecorator
###################### directives ##########################
@@ -370,7 +371,7 @@ def set_authentication_policy(config, policy):
# smooth over differences between pyramid 1.2dev and older
if hasattr(config, 'set_authentication_policy'):
config.set_authentication_policy(policy)
- else:
+ else: # pragma: no cover
config._set_authentication_policy(policy)
class IRepozeWho1AuthenticationPolicyDirective(Interface):
@@ -457,7 +458,7 @@ def aclauthorizationpolicy(_context):
if hasattr(config, 'set_authorization_policy'):
# pyramid 1.2dev
config.set_authorization_policy(policy)
- else:
+ else: # pragma: no cover
config._set_authorization_policy(policy)
class IRendererDirective(Interface):
@@ -816,12 +817,6 @@ def load_zcml(self, spec='configure.zcml', lock=threading.Lock()):
__import__(package_name)
package = sys.modules[package_name]
- registry = self.registry
- self.manager.push({'registry':registry, 'request':None})
- context = self._ctx
- if context is None:
- context = self._ctx = self._make_context(self.autocommit)
-
# To avoid breaking people's expectations of how ZCML works, we
# cannot autocommit ZCML actions incrementally. If we commit actions
# incrementally, configuration outcome will be controlled purely by
@@ -831,19 +826,48 @@ def load_zcml(self, spec='configure.zcml', lock=threading.Lock()):
# execute=self.autocommit to xmlconfig.file below, which will cause
# the actions implied by the ZCML that was parsed to be committed
# right away once parsing is finished if autocommit is True.
- context = GroupingContextDecorator(context)
- context.autocommit = False
+ context = PyramidConfigurationMachine()
+ context.registry = self.registry
+ context.autocommit = False
+ context.route_prefix = getattr(self, 'route_prefix', None)
+ context.package = package
+ registerCommonDirectives(context)
+
+ self.manager.push({'registry':self.registry, 'request':None})
lock.acquire()
+
try:
- context.package = package
xmlconfig.file(filename, package, context=context,
execute=self.autocommit)
finally:
lock.release()
self.manager.pop()
- return registry
+ _ctx = self._ctx
+ if _ctx is None:
+ _ctx = self._ctx = self._make_context(self.autocommit)
+ _ctx.actions.extend(context.actions)
+
+ return self.registry
+
+class PyramidConfigurationMachine(ConfigurationMachine):
+ autocommit = False
+ route_prefix = None
+
+ def processSpec(self, spec):
+ """Check whether a callable needs to be processed. The ``spec``
+ refers to a unique identifier for the callable.
+
+ Return True if processing is needed and False otherwise. If
+ the callable needs to be processed, it will be marked as
+ processed, assuming that the caller will procces the callable if
+ it needs to be processed.
+ """
+ if spec in self._seen_files:
+ return False
+ self._seen_files.add(spec)
+ return True
# note that ``options`` is a b/w compat alias for ``settings`` and
# ``Configurator`` is a testing dep inj
@@ -1129,6 +1129,16 @@ def test_load_zcml_default(self):
from pyramid_zcml.tests.fixtureapp.models import IFixture
self.failUnless(registry.queryUtility(IFixture)) # only in c.zcml
+ def test_load_zcml_without_autocommit(self):
+ from pyramid_zcml.tests.fixtureapp.models import IFixture
+ import pyramid_zcml.tests.fixtureapp
+ config = self._makeOne(package=pyramid_zcml.tests.fixtureapp,
+ autocommit=False)
+ registry = config.load_zcml()
+ self.failIf(registry.queryUtility(IFixture)) # only in c.zcml
+ config.commit()
+ self.failUnless(registry.queryUtility(IFixture)) # only in c.zcml
+
def test_load_zcml_routesapp(self):
from pyramid.interfaces import IRoutesMapper
config = self._makeOne(autocommit=True)
@@ -1257,6 +1267,22 @@ def test_it_with_custom_configure_zcml(self):
Configurator=DummyConfigurator)
self.assertEqual(app.zcml_file, '2.zcml')
+class TestPyramidConfigurationMachine(unittest.TestCase):
+ def _makeOne(self):
+ from pyramid_zcml import PyramidConfigurationMachine
+ m = PyramidConfigurationMachine()
+ return m
+
+ def test_ctor(self):
+ m = self._makeOne()
+ self.assertEqual(m.autocommit, False)
+ self.assertEqual(m.route_prefix, None)
+
+ def test_processSpec(self):
+ m = self._makeOne()
+ self.assertTrue(m.processSpec('foo'))
+ self.assertFalse(m.processSpec('foo'))
+
class Dummy:
pass
@@ -4,8 +4,9 @@
def first(request):
return {'result':'OK1'}
-@view_config(renderer='pyramid.tests.viewdecoratorapp.views:templates/foo.mak',
- name='second')
+@view_config(
+ renderer='pyramid_zcml.tests.viewdecoratorapp.views:templates/foo.mak',
+ name='second')
def second(request):
return {'result':'OK2'}
View
@@ -26,6 +26,7 @@
install_requires=[
'pyramid>=1.0b1', # autktauthenticationpolicy wild_domain
+ 'zope.configuration',
]
if platform.system() == 'Java':

0 comments on commit 209cb31

Please sign in to comment.