Python Desktop: Configuring and Modularizing
I've got a little desktop application I've been building in Python, and a few of the tools I've come across are helpful, so here's a short discussion of YAPSY, argparse, and ConfigParser.
ArgumentParser.add_argument_group(title, description).
That separates the commands per group when --help is invoked to give usage. But, the downside here is it doesn’t actually separate those commands in the parsed arguments. It’s a minor inconvenience to separate them. It also doesn’t magically namespace things for you, so coming up with a convention is important.
And that leads to the third component to discuss today: ConfigParser. ConfigParser lets you read from a configuration file.
This time, groups are no problem, as the file format is equivalent to a classic .ini file (ie, it has headed sections to it). But there’s still some work to handle the integration between arguments and configuration. There is some overlap, but there are some options that are found in one or the other, but not both.
For example, an option of which configuration file to use probably wouldn’t be specified in the configuration file itself, but only via the program arguments. Similarly, you wouldn’t want to have an argument for every option, so some options would only come from the configuration file.
Thus, having a single class that handles both configuration files and arguments is useful. First, it gets the data from both, then it unifies the overlap, providing all three sets of options to the program as a whole (some of which go to the program, some to the plugins).
By Sortie de Yapsy1.9 | tlog
From
[…] une mystérieuse application de bureau […]