Jun-27-2024, 09:10 PM
(This post was last modified: Jul-08-2024, 01:58 PM by Gribouillis.)
I uploaded a new module in Github, it is named « configoose ». It is not yet in Pypi and it is at an early stage of its life, but you can already install it as described on the Github page.
It is not yet documented, but I'll give you here an idea and a small example of what it does (changed! documentation now at https://configoose.readthedocs.io/en/latest/index.html)
I wrote this module because when I write a program that needs configuration files, I want to be free as a user to store these files anywhere in my file system, and perhaps in more exotic places such as inside a zip file or a database or on the web etc.
The problem is: how can the program or the module find its configuration files if they can be anywhere on the file system?
The solution is: the program uses an abstract 'address' for the configuration file and it asks someone to find the configuration
file registered with that address. This someone is the configoose module.
Here is a small example of how it works with a program configured with configparser (this is called a protocol in configoose's jargon)
I first create a configuration file for the configparser protocol by running the command
Now I register my configuration file in the configoose system so that other modules can find it
The next step for me in the next days is to develop the basic documentation.
Play with the module, enjoy and post feedback!
It is not yet documented, but I'll give you here an idea and a small example of what it does (changed! documentation now at https://configoose.readthedocs.io/en/latest/index.html)
I wrote this module because when I write a program that needs configuration files, I want to be free as a user to store these files anywhere in my file system, and perhaps in more exotic places such as inside a zip file or a database or on the web etc.
The problem is: how can the program or the module find its configuration files if they can be anywhere on the file system?
The solution is: the program uses an abstract 'address' for the configuration file and it asks someone to find the configuration
file registered with that address. This someone is the configoose module.
Here is a small example of how it works with a program configured with configparser (this is called a protocol in configoose's jargon)
I first create a configuration file for the configparser protocol by running the command
Output:python -m configoose template configoose.protocol.configparser.Protocol > paillasse/tmp/french.cfg
Now I edit the configuration file and populate itOutput:{
"address" : "s8dzw5y5anduiodmrdrxdgxaa",
"protopath" : "configoose.protocol.configparser.Protocol",
}
[spam]
ham =
slice A
slice B
slice C
[more]
eggs = 1000
It is a normal configparser file except that there is a small python dictionary at the beginning called a « preamble ». I don't touch this preamble.Now I register my configuration file in the configoose system so that other modules can find it
Output:python -m configoose moor -a s8dzw5y5anduiodmrdrxdgxaa initial paillasse/tmp/french.cfg
It remains to write a module that uses this configuration. Here is onefrom configoose import Configurator cfg = Configurator("s8dzw5y5anduiodmrdrxdgxaa") @cfg.add_protocol("configoose.protocol.configparser.Protocol") def handler(ap, preamble, parser): s = parser["spam"]["ham"] ham = [y.strip() for y in s.strip().split("\n") if y.strip()] print('ham = ', ham) print(f"There are {parser['more']['eggs']} eggs!") cfg.run()Here the handler function receives a ConfigParser instance among other arguments, which read the configuration file. Here is the output
Output:λ python paillasse/tmp/frenchman.py
ham = ['slice A', 'slice B', 'slice C']
There are 1000 eggs!
There are a huge amount of details to be explained about configoose. It is an infinitely extensible module. Arbitrary configuration protocols can be defined (3 are included by default) and there is potentially no limit as to where the configuration files can be stored.The next step for me in the next days is to develop the basic documentation.
Play with the module, enjoy and post feedback!

« We can solve any problem by introducing an extra level of indirection »