loading configuration files that are themselves python

Ben Finney ben+python at benfinney.id.au
Fri Jul 23 20:53:35 EDT 2010


Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:

> In message <7j8w5tylmw.fsf at rapun.sel.cam.ac.uk>, Matthew Vernon wrote:
>
> > Is there a more idiomatic way of loading in a configuration file
> > that's python code ...
>
> Is it really a good idea to have a configuration language that’s Turing-
> complete?

I think not. Configuration files should be read as data; they should be
declarative only, not executable languages. That way, a different
program can read and parse them without having to be a parser for an
entire programming language.

As illustration of this point, I present the chronic headaches of the
Python ‘setup.py’ file. It tries to be both setup program *and*
configuration file, with the consequence that in the general case it's
impossible to get configuration information without executing the setup
program.

Recent work (lots of it!) by the Distutils team has gone into separating
the concerns so that the configuration data is all in a non-executable
data file; that work is ongoing, and it's been a hard lesson to learn.

-- 
 \           “If [a technology company] has confidence in their future |
  `\      ability to innovate, the importance they place on protecting |
_o__)     their past innovations really should decline.” —Gary Barnett |
Ben Finney



More information about the Python-list mailing list