[Libre-soc-dev] config file parsing

Jacob Lifshay programmerjake at gmail.com
Wed Sep 9 18:08:13 BST 2020


On Wed, Sep 9, 2020, 02:26 Luke Kenneth Casson Leighton <lkcl at lkcl.net>
wrote:

> On Wed, Sep 9, 2020 at 4:14 AM Jacob Lifshay <programmerjake at gmail.com>
> wrote:
> >
> > today:
> > still working on budget-sync in utils.git, I just finished writing a
> > config file parser. Sample config file:
>
> you know there's a python module been in there since 1998 called
> configparser.py ? :)
>
> it was added very early because windows config .ini file format was
> very popular back then (still is)


I'm using the toml package, since toml is like .ini but standardized and
extended to be able to represent all of json (assuming the top-level thing
is a table) except for null and with date/time types added.

All of the work after calling toml.load[s] is for extracting the proper
fields from the parsed toml, checking types, and making sure they are
consistent (like making sure people don't share aliases or have one person
claim to have another person's name as an alias).

I also added thorough unit tests, making sure to hit every error condition
in my code. I also discovered a bug in the toml package:
https://github.com/uiri/toml/issues/314

more than half of the work would go away had I been writing it in Rust,
since serde is awesome! it automatically extracts the proper fields into
your structs and type checks and can call your custom conversion code for
you. it also works with non-toml formats.

Jacob


More information about the Libre-soc-dev mailing list