New configuration module released
Dan Perl
danperl at rogers.com
Wed Nov 3 11:24:33 EST 2004
Vinay,
I'm posting some opinions I have on your module and on the topic in general
in this newsgroup, instead of using the links you have on your web page
(your email and a wiki) because I would like to see a wider discussion.
My experience with python in general and configuration in python in
particular is rather short (a few months), but I have been working on a
personal, open-source project during this time and configuration was one of
the biggest issues I had. I did look at configParser early on, but I
decided it was not giving me enough. At the top level, I had only a few
values (4 at present, but even less in the beginning) and these values were
however fairly complex. I ended up implementing the configuration mechanism
as plain python modules which are imported by my application. This created
a mechanism that was relatively difficult to understand and that needed
users to actually code in python for configuration. I think the problem of
configuration in my project is much smaller now, because I also added a GUI
tool that allows configuration to be done through a graphical interface.
Enough about my project, but I meant to give a context for what I am about
to discuss next.
I looked only at the documentation for your module and I haven't actually
tried it. Please forgive me if I am missing anything. With this
information though, I don't see enough reasons to replace my own custom-made
configuration mechanism with your module.
First, some small issues. The syntax for your configuration is still fairly
close to the python syntax and it involves quite a bit of learning for both
python users and non-python users. Your module would save me a little bit
of work in parsing when loading a configuration (remember, I am loading
configurations by importing them as a module) and a little more work than
that in formatting when saving a configuration. That work is not very
significant though and having my own mechanism also has its advantages.
Now, here is the biggest issue I have and what I would be extremely
interested in seeing in a configuration module. I don't see from your
documentation how I could programmatically create a configuration from
scratch. In my project I have a set of handlers and each handler has a
special configuration. Each such special configuration is defined by a
structure of metadata (with information like name, type, description) that I
implemented myself. That way, my GUI tool can load a handler dynamically,
read its configuration metadata, dynamically create a frame for the
handler's configuration, and save the new configuration to a file.
Again, I only read your documentation, but I haven't seen anything like my
configuration metadata, that would allow me to dynamically create a
configuration from scratch. Please correct me if I'm wrong and point me to
something that your module has for this purpose.
I definitely appreciate your effort though and I hope that you continue
working on this configuration module. Like I said, configuration has been a
big issue in my project and I would like to have a generic configuration
that would satisfy all my needs instead of creating (and now evolving and
maintaining) my own, custom-made configuration mechanism. Something like
the configuration metadata that I described is a very important feature for
me. I hope I described it clearly enough. And again, my apologies if you
already have such a feature and I only missed it.
Dan
"Vinay Sajip" <vinay_sajip at yahoo.co.uk> wrote in message
news:2e37dc1.0411030650.ff44840 at posting.google.com...
> I've just made available the first general release of a configuration
> module for Python. It has grown out of the need to make configuration
> easier and more powerful (for developers and end users) than
> ConfigParser.
>
> It's one of the implementations which could be considered in the
> ConfigParser shootout, mentioned on the Python Wiki at
>
> http://www.python.org/moin/ConfigParserShootout
>
> What Does It Do?
> ================
> The config module allows you to implement a hierarchical configuration
> scheme with support for mappings and sequences, cross-references
> between one part of the configuration and another, the ability to
> flexibly access real Python objects, facilities for configurations to
> include and cross-reference one another, simple expression evaluation
> and the ability to change, save, cascade and merge configurations.
>
> This module has been developed on python 2.3 but should work on
> version 2.2 or greater. A test suite using unittest is included in the
> distribution.
>
> A very simple configuration file (simple.cfg):
>
> # starts here
> message: Hello, world!
> #ends here
>
> a very simple program to use it:
>
> from config import Config
>
> cfg = Config(file('simple.cfg'))
> print cfg.message
>
> results in:
>
> Hello, world!
>
> Configuration files are key-value pairs, but the values can be
> containers that contain further values
> A simple example - with the example configuration file:
>
> messages:
> [
> {
> stream : `sys.stderr`
> message: 'Welcome'
> name: 'Harry'
> }
> {
> stream : `sys.stdout`
> message: 'Welkom'
> name: 'Ruud'
> }
> {
> stream : $messages[0].stream
> message: 'Bienvenue'
> name: Yves
> }
> ]
>
> a program to read the configuration would be:
>
> from config import Config
>
> f = file('simple.cfg')
> cfg = Config(f)
> for m in cfg.messages:
> s = '%s, %s' % (m.message, m.name)
> try:
> print >> m.stream, s
> except IOError, e:
> print e
>
> which, when run, would yield the console output:
>
> Welcome, Harry
> Welkom, Ruud
> Bienvenue, Yves
>
> The above example just scratches the surface. There's more information
> about this module available at
>
> http://www.red-dove.com/python_config.html
>
> Comprehensive API documentation is available at
>
> http://www.red-dove.com/config/index.html
>
> As always, your feedback is most welcome (especially bug reports,
> patches and suggestions for improvement). Enjoy!
>
> Cheers
>
> Vinay Sajip
> Red Dove Consultants Ltd.
More information about the Python-list
mailing list