[IPython-dev] Python-based configuration system

Ville Vainio vivainio at kolumbus.fi
Wed Jun 30 07:56:24 EDT 2004


Apparently replacing the current configuration system with a 
python-based one should not be too much work:

class Configuration:

   def parsefile(file):
     " execute the file in self.confdict namespace "

   def getdict():
     " return the underlying dict "

   def pushopts(optdict):
     self.confdict.update(optdict)

   class RcProxy
     " a Struct-like proxy for dict "

   def getrcstruct():
     " return RcProxy object "

The RcProxy instance given by getrcstruct would just implement 
getattr/setattr to return the corresponding item in confdict, and 
delegate non-existing key lookups to the confdict as such.

Implementation of Configuration methods is trivial, and RcProxy is 
mostly copy-paste from here (delegation recipe):

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295
 
Then we just put the RcProxy instance to the rc attrbute of the 
interpreter, and nothing would need to be changed in interpreter class 
and other classes that might use interpreter.rc.

Configuration could/should really be that simple, I've implemented such 
a system in many seperate projects and there has never been any real 
problems (most importantly, there has never been a need for more 
sophisticated conflict resolution than "last evaluation wins". The 
"seed" configuration file containing all the defaults (that is executed 
first) could be in /etc/ipython-defaults (or whatever) and other 
user/system config files would just be executed in the same 
Configuration object after it.




More information about the IPython-dev mailing list