-
Notifications
You must be signed in to change notification settings - Fork 12
Description
We want to fully integrate a class structure storing all input file options.
We can't just use boutdata.BoutOptionsFile though, because it uses boututils.DataFile in places, so it will need at least a partial rewrite to work with xBOUT.
I actually tried to see if there was a way to rewrite BoutOptionsFile completely (aiming for a much shorter, less home-grown implementation), but the unique structure of BOUT.inp files foiled me. BOUT.inp files are similar to .ini files and YAML files, but have distinguishing properties which make handling them with variations of standard python library config classes difficult:
-
Missing initial section header. This is annoying but solvable - you can still read and write
.inpfiles withconfigparser.ConfigParserbut you have to special-case the first line. -
Nested sections. This rules out easily subclassing
configparser.ConfigParser- I thought maybe you could overrideConfigParser.sections()with a recursive lookup method but asConfigParserinherits its structure fromcollections.MutableMappingI couldn't see any easy way to make this work. -
Specifying nesting in header names. The
[section:subsection]syntax isn't shared by any commonly-used config file structure I could find. I think this rules out usingconfigobj.ConfigObj, which is a shame because that one supports nesting (and nested substitution).
While trying out these things I did write some tests though, so we could use them (boutdata.BoutOptionsFile currently has no direct tests).
Therefore I suggest what we should do is:
-
Write some tests defining the expected behaviour of the options file class (I have some already, which I will submit later),
-
Copy over the basic parts of the
boutdata.BoutOptionsFilecode toxBOUT, -
Reimplement the methods which rely on
boututils.DataFile.
This should hopefully allow us to improve the boutdata.BoutOptionsFile code if needed but without breaking backwards compatibility.