# HG changeset patch # User Denis Laxalde # Date 1487694916 -3600 # Node ID b282ef22b5abd3babd3c0690638d65ea2fa98e38 # Parent 2fb941d12d74e8353d2567456db50a2a502546b9 [pyramid] Make it possible to setup CubicWeb instance from an existing repo in includeme() diff -r 2fb941d12d74 -r b282ef22b5ab cubicweb/pyramid/__init__.py --- a/cubicweb/pyramid/__init__.py Tue Feb 21 17:42:46 2017 +0100 +++ b/cubicweb/pyramid/__init__.py Tue Feb 21 17:35:16 2017 +0100 @@ -26,6 +26,7 @@ from cubicweb.cwconfig import CubicWebConfiguration as cwcfg from pyramid.config import Configurator +from pyramid.exceptions import ConfigurationError from pyramid.settings import asbool, aslist try: @@ -178,6 +179,12 @@ The CubicWeb instance can be set in several ways: + - Provide an already loaded CubicWeb repository in the registry: + + .. code-block:: python + + config.registry['cubicweb.repository'] = your_repo_instance + - Provide an already loaded CubicWeb config instance in the registry: .. code-block:: python @@ -187,8 +194,24 @@ - Provide an instance name in the pyramid settings with :confval:`cubicweb.instance`. + A CubicWeb repository is instantiated and attached in + 'cubicweb.repository' registry key if not already present. + + The CubicWeb instance registry is attached in 'cubicweb.registry' registry + key. """ cwconfig = config.registry.get('cubicweb.config') + repo = config.registry.get('cubicweb.repository') + + if repo is not None: + if cwconfig is None: + config.registry['cubicweb.config'] = cwconfig = repo.config + elif cwconfig is not repo.config: + raise ConfigurationError( + 'CubicWeb config instance (found in "cubicweb.config" ' + 'registry key) mismatches with that of the repository ' + '(registry["cubicweb.repository"])' + ) if cwconfig is None: debugmode = asbool( @@ -197,7 +220,8 @@ config.registry.settings['cubicweb.instance'], debugmode=debugmode) config.registry['cubicweb.config'] = cwconfig - config.registry['cubicweb.repository'] = repo = cwconfig.repository() + if repo is None: + repo = config.registry['cubicweb.repository'] = cwconfig.repository() config.registry['cubicweb.registry'] = repo.vreg if asbool(config.registry.settings.get('cubicweb.defaults', True)):