Try calling config.commit() after load_zcml(). - C
On Thu, 2011-02-17 at 20:22 -0800, Iain Duncan wrote: > Hey folks, not sure where this belongs, but it seems to be a fairly > under-the-hood question, so I'll try here first. > > I have some utilities that get registered in various packages in zcml. > The packages are included from the main apps configure.zml file with > > <include package="xornot.model" /> > > and in that packages configure.zcml file I have: > > <utility provides="xornot.model.interfaces.IResourceMappers" > component="xornot.model.mappers.model_mappers" name="model_mappers"/> > > The configure.zcml from xornot.model *is* definitely being parsed, > putting garbage in there stops app start up. Here's what I can figure > out, I have another a factory that looks up that utility from the > registry. In my app.py file where I set up the registry using the > Configurator object, I have the following code, *after* all > configuration is done: > > # instantiate ModelFactory, does all the SQLA startup housekeeping > model_factory = ModelFactory(registry=registry, **settings) > # register model factory as generic adapter of request to provide > model > registry.registerAdapter(model_factory, (IRequest,), Interface, > 'model') > > Now here's what's weird. The ModelFactory does not find that utility. > Looking at ._registered_utilities of the registry during ModelFactory > init shows no registration of my model mapper utility. But when I drop > into the debugger from the root factory, I can find that utility in > the registry. I want to set up the ModelFactory once and only once on > start up ( it makes SQLA mappers, which I believe are shared between > threads ). > > I can't figure out for the life of me why the utilities aren't in > there, it must be some innards thing I don't grok. I thought all > included zcml packages were loaded in during the config setup code. > Any help much appreciated. I will include my app code for ref: > > thanks > iain > > def app(global_config, **settings): > "return a wsgi app with a xornot ModelFactory in the registry" > > from xornot.model.interfaces import IAbstractModel > from xornot.model.factories import ModelFactory > > # allow ini file's to set the app package and configure.zcml file > app_package = settings.get('app_package', None) > zcml_file = settings.get('configure_zcml', 'configure.zcml') > > # we are using the zope global site manager > registry = getGlobalSiteManager() > > config = Configurator( registry=registry ) > config.include('pyramid_zcml') > config.setup_registry(settings=settings, root_factory=DefaultRoot, > request_factory=Request ) > > if app_package: > config.load_zcml("%s:%s" % (app_package, zcml_file) ) > else: > # load from current package > config.load_zcml(zcml_file) > > > # instantiate ModelFactory, does all the SQLA startup > housekeeping > # XXX: this guy is not finding utilities registered in included > packages! > model_factory = ModelFactory(registry=registry, **settings) > # register model factory as generic adapter of request to provide > model > registry.registerAdapter(model_factory, (IRequest,), Interface, > 'model') > > # get the base app and return it > app = config.make_wsgi_app() > > return app > -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.