On Thursday 19 July 2007 8:02:53 pm Fernando Perez wrote: > - Consider a file called mpl.conf: > # Top-level > backend = "TkAgg" > interactive = False > > # Things that can only be set at init time, they become read-only > afterwards > [InitOnly] > numerix = "numpy" [...] > - Then, consider the following bit of Python code: [...] > This purely declarative code incorporates: > > * The types of all parameters acceptable in the file > * The nesting hierarchy for subobjects > * The default values hardcoded in the app if users don't provide any > * The valid values for those which are choices. > > An 'application' is defined via: > > class App(object): > """A trivial 'application' class to be initialized. > """ > def __init__(self,configClass,conf_filename): > conf = mkConfigObj(conf_filename) > self.rc = configClass(conf) > > > mpl = App(MPLConfig,'mpl.conf') > > This makes the App object load the .conf file, immediately giving > errors if any of the validation constraints implicit in the traits > spec are not met. The resulting mpl.rc object can be printed, > manipulated, modified (for non-read-only sections), even edited with a > GUI (limited at the moment to WX and not really working for > sub-sections, though that's easily fixed). For example: > > In [159]: mpl.rc > Out[159]: > # Dump of MPLConfig > > backend = 'TkAgg' > interactive = False > > [InitOnly] > numerix = 'numpy' > > [lines] > linewidth = 2.0 > linestyle = '-' > > [figure] > edgecolor = 'white' > figsize = [6.4000000000000004, 4.7999999999999998] > dpi = 100 > facecolor = 0.75 > > [[subplot]] > top = 0.90000000000000002 > right = 0.90000000000000002 > left = 0.125 > bottom = 0.10000000000000001 > > These objects are automatically self-representable in a valid > roundtrip format.
Damn, that is really cool. So you can generate default config files from the MPLConfig instance. We create a default matplotlibrc file from a template, setting default backend and numerix values based on what is available on the users system. It looks like it would be even easier with your scheme: import MPLConfig in setup.py, set the attributes, dump to a default config file. [...] > In summary, I'm fairly happy with the results, and I think the benefit > is enough to convince me of falling in the embrace of the gods of > Traits. It seems John is going for Traits as well, so perhaps we can > use this little config setup across our systems, and even make it > something that others use in the future. I think there's value for > end users in having common, uniform configuration systems across the > various parts of the scientific python 'ecosystem'. I agree. It looks really elegant. What about the circular dependencies you mentioned in a previous email, is that still a potential problem? Darren ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel