diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-07-02 17:20:31 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-07-02 17:20:31 +0000 |
| commit | b5104e12d5f4e8618b6bc21bf7a0da2bce62d8cb (patch) | |
| tree | ed2df319cfb894bf2ea501b5efa42a5412956af1 | |
| parent | 5e19ddda73d5792fe27a6710319c16860373c589 (diff) | |
| download | pyramid-b5104e12d5f4e8618b6bc21bf7a0da2bce62d8cb.tar.gz pyramid-b5104e12d5f4e8618b6bc21bf7a0da2bce62d8cb.tar.bz2 pyramid-b5104e12d5f4e8618b6bc21bf7a0da2bce62d8cb.zip | |
Allow ``zcml_configure`` value to override the package.
| -rw-r--r-- | CHANGES.txt | 7 | ||||
| -rw-r--r-- | docs/narr/environment.rst | 11 | ||||
| -rw-r--r-- | repoze/bfg/router.py | 25 | ||||
| -rw-r--r-- | repoze/bfg/tests/fixtureapp/subpackage/__init__.py | 1 | ||||
| -rw-r--r-- | repoze/bfg/tests/fixtureapp/subpackage/yetanother.zcml | 8 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_router.py | 13 |
6 files changed, 53 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 21189d0c0..6baa006cd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,9 +6,10 @@ Features - Allow a Paste config file (``configure_zcml``) value or an environment variable (``BFG_CONFIGURE_ZCML``) to name a ZCML file - that will be used to bootstrap the application. Previously, the - integrator could not influence which ZCML file was used to do the - boostrapping (only the original application developer could do so). + (optionally package-relative) that will be used to bootstrap the + application. Previously, the integrator could not influence which + ZCML file was used to do the boostrapping (only the original + application developer could do so). Documentation ------------- diff --git a/docs/narr/environment.rst b/docs/narr/environment.rst index 48553940a..abca73433 100644 --- a/docs/narr/environment.rst +++ b/docs/narr/environment.rst @@ -54,7 +54,16 @@ application-specific configuration settings. | | | this is a relative filename, it will | | | | be considered relative to the | | | | ``package`` passed to ``make_app`` | -| | | by the application. | +| | | by the application. It may also | +| | | take the form of a resource | +| | | "specification" which names both the | +| | | package name and a package-relative | +| | | filename, e.g. | +| | | ``dotted.package.name:path/to.zcml``. | +| | | If it is a resource specification, | +| | | both the *package* and the | +| | | *filename* passed to ``make_app`` are | +| | | overridden with the implied values. | +---------------------------------+-----------------------------+----------------------------------------+ Examples diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index 3b9b12cb7..5addef933 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -225,17 +225,21 @@ def make_app(root_factory, package=None, filename='configure.zcml', ``package`` is a Python module representing the application's package. It is optional, defaulting to ``None``. ``package`` may - be ``None``. If ``package`` is ``None``, either the ``filename`` - passed or the value in the ``options`` dictionary named - ``configure_zcml`` must be an absolute pathname to a ZCML file - that represents the application's configuration. + be ``None``. If ``package`` is ``None``, the ``filename`` passed + or the value in the ``options`` dictionary named + ``configure_zcml`` must be a) absolute pathname to a ZCML file + that represents the application's configuration *or* b) a + 'specification' in the form + ``dotted_package_name:relative/file/path.zcml``. ``filename`` is the filesystem path to a ZCML file (optionally relative to the package path) that should be parsed to create the - application registry. It defaults to ``configure.zcml``. Note - that if any value for ``configure_zcml`` is passed within the - ``options`` dictionary, the value passed as ``filename`` will be - ignored, replaced with the ``configure_zcml`` value. + application registry. It defaults to ``configure.zcml``. It can + also be a 'specification' in the form + ``dotted_package_name:relatve/file/path.zcml``. Note that if any + value for ``configure_zcml`` is passed within the ``options`` + dictionary, the value passed as ``filename`` will be ignored, + replaced with the ``configure_zcml`` value. ``authentication_policy`` should be an object that implements the ``repoze.bfg.interfaces.IAuthenticationPolicy`` interface (e.g. @@ -277,6 +281,11 @@ def make_app(root_factory, package=None, filename='configure.zcml', settings = Settings(get_options(options)) filename = settings['configure_zcml'] + if ':' in filename: + package, filename = filename.split(':', 1) + __import__(package) + package = sys.modules[package] + if registry is None: regname = filename if package: diff --git a/repoze/bfg/tests/fixtureapp/subpackage/__init__.py b/repoze/bfg/tests/fixtureapp/subpackage/__init__.py new file mode 100644 index 000000000..d3173e636 --- /dev/null +++ b/repoze/bfg/tests/fixtureapp/subpackage/__init__.py @@ -0,0 +1 @@ +#package diff --git a/repoze/bfg/tests/fixtureapp/subpackage/yetanother.zcml b/repoze/bfg/tests/fixtureapp/subpackage/yetanother.zcml new file mode 100644 index 000000000..464163477 --- /dev/null +++ b/repoze/bfg/tests/fixtureapp/subpackage/yetanother.zcml @@ -0,0 +1,8 @@ +<configure xmlns="http://namespaces.repoze.org/bfg"> + + <include package="repoze.bfg.includes" /> + + <include package="repoze.bfg.tests.fixtureapp" file="another.zcml"/> + +</configure> + diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py index cd88f8971..e3b200c57 100644 --- a/repoze/bfg/tests/test_router.py +++ b/repoze/bfg/tests/test_router.py @@ -703,6 +703,19 @@ class MakeAppTests(unittest.TestCase): self.assertEqual(app.registry.__name__, 'repoze.bfg.tests.fixtureapp') from repoze.bfg.tests.fixtureapp.models import IFixture self.failIf(app.registry.queryUtility(IFixture)) # only in c.zcml + + def test_fixtureapp_explicit_specification_in_options(self): + manager = DummyRegistryManager() + rootpolicy = DummyRootFactory(None) + from repoze.bfg.tests import fixtureapp + zcmlfile = 'repoze.bfg.tests.fixtureapp.subpackage:yetanother.zcml' + app = self._callFUT(rootpolicy, fixtureapp, filename='configure.zcml', + options={'configure_zcml':zcmlfile}, + manager=manager) + self.assertEqual(app.registry.__name__, + 'repoze.bfg.tests.fixtureapp.subpackage') + from repoze.bfg.tests.fixtureapp.models import IFixture + self.failIf(app.registry.queryUtility(IFixture)) # only in c.zcml def test_event(self): manager = DummyRegistryManager() |
