[Web-SIG] Generic configuration

Alex Morega alex at grep.ro
Wed Mar 17 10:51:05 CET 2010


On 17 Mar 2010, at 0:24, Manlio Perillo wrote:

> Alex Morega ha scritto:
>> Hello,
>> 
>> This is not really a WSGI question, it's more into general configuration, but I don't know of a better place to ask it.
>> 
>> Paster config files allow you to hook up WSGI applications, middleware, and a server, plus some (undocumented?) magic configuration of the logging module. But what about random components, like a database? Ideally I'd like to specify a factory for database connections and give it some parameters; this would return a reference to a new database connection. I could then pass this reference to my wsgi app or middleware.
>> 
>> Apparently the pattern is to perform this database configuration as part of a wsgi middleware, but that feels unnatural. Or one could do this outside of the paste configuration file, but that just splits the configuration needlessly into several pieces. Am I missing something obvious?
>> 
> 
> I use YAML with custom constructors:
> http://hg.mperillo.ath.cx/wsgix/file/tip/wsgix/conf/loader.py
> 
> There is a middleware:
>  http://hg.mperillo.ath.cx/wsgix/file/tip/wsgix/conf/middleware.py
> that reads a list of configuration files to load from the WSGI environ
> (I set this in the Nginx mod_wsgi) configuration, and merge all the
> configuration in the WSGI environ.
> 
> Using custom YAML constructors it is possible to do something like:
>  http://hg.mperillo.ath.cx/wsgix/examples/file/tip/dbview/settings.yml
> 
> It is also possible to configure the global python logging, create
> temporary files and so on.

That's still configuring a piece of WSGI middleware or application. I'm thinking about something along these lines:

=========================
[daemon]
factory = egg:PasteScript#wsgiutils
host = 127.0.0.1
port = 8000
app = my_site

[my_site]
factory = egg:Paste#composite
urlmap = my_urlmap

[my_urlmap]
factory = egg:Paste#urlmap
/blog = blog_app
/media = media_app

[media_app]
factory = egg:Paste#static
document_root = %(here)s/static_media

[blog_app]
factory = python:my.package.blog:app_factory
db = my_db

[my_db]
factory = python:my.package.db:conenction_factory
host = localhost
port = 3333
=========================

Every section has a factory (in the same way every section in Paste config files has "use=" and every part in buildout has "recipe="); the factories get called with the rest of the parameters from their section, using e.g. keyword arguments. The goal is to configure components independently, and tie them together into an application/service/daemon/whatever. Only the "daemon" and "factory" names have magical meaning, everything else is either looked up, or sent as a parameter string.

As far as I'm aware, it's somewhat possible to do this from within a framework, using a predefined set of pieces; I'd like to use arbitrary factories and entry points.

Cheers,
-- Alex



More information about the Web-SIG mailing list