python configuration file

I have the need for a python accessible configuration file - which, potentially, could become rather big. I would like it to be a human read-edit-able format (and xml doesn’t fall into that category in my book). The config file needs to support multiple instances of the same object (array, list, table,…) - although I don’t mind writing separate lines for each attribute.

I’ve only found xml being used in FC. Python’s own ConfigParser is not good for any type of list (I could probably make it work if I had to, but it ain’t gonna be pretty).

Any suggestions?

YAML and PyYAML may help
Maurice

YAML is indeed nice.

How do we deal with python package dependencies?

Yaml is easy. It’s already used by several add-on WB’s. It’s in the Win bundle and on Ubuntu we can easily add it to the Debian control file for the PPA.

Very good suggestion :slight_smile:

My build-system kung-fu is not strong enough. I cannot figure out what I should be doing where, neither for Windows nor for Debian. I thought if I go looking what was being done for numpy I could figure it out - but I haven’t found any trace of where it is being requested. In the Debian control file is a “python:Depends”, which seemed like the thing to add yaml to - except that I can’t figure out where it’s defined. :confused:

xml starts looking better by the hour - maybe I should start with that and later support both when yaml is available…

in windows PyYAML is already bundled
just do:

import yaml

Sorry for not being clear.
On Windows the package is located in " …PathtoFreeCAD/bin/Lib/site-packages". So just do as easy-fc suggests just import it in your code and it’s available.
For Debian(Ubuntu) install python-yaml with your package manager and do the same.
When it’s about to be a hard dependency for FreeCAD I will add it to Travis and the PPA (it’s just a packaging thing)

In your code you can put the import in a try/except block and inform the user they must install the package if it’s not installed already, this might be a good heads up for users of other distro’s, who’s packagers might not be immediately aware of the new dependency.

It might be good to double check with the main devs that a new dependency is OK. But as I said it’s easy to support and small, only about 450 MB installed.

Great - thanks for the info. For now we decided to stick with xml for practical reasons and once we can show the functionality to users check what they want for the configuration file and pick it up again at that time.