Storing settings for tools

Hi,

How are you guys storing settings along with your tools?

I’m thinking of use-cases similar to QSettings, maybe you’re even using QSettings. I’m looking to persistently store settings used in custom tools both locally but also centralised; similar to userSetup.py of Maya. Would you use a Python module, like userSetup.py? Or a JSON/YAML? Why, why not?

On a related note, how do you deal with defaults? E.g. when workspace.mel of Maya doesn’t exist, a default is created. Are you hosting defaults in code, or in another settings file - and if so, how do you solve the chicken or egg problem? If not, are you concerned about hard-coded values?

Best,
Marcus

I always use QSettings. The good thing is that you can always specify a default value if there is not a user value already. Also, by using this method it is OS agnostic.

we use JSON for our tool settings. It makes it readable by damn near anything

Thanks guys! As it happens, the question was asked simultaneously on the Maya-Python list - posting it here for the additional answers: Redirecting to Google Groups

Now, where do you store your settings? Something like this?

pythonpath/mypackage/settings.ini|yaml|json

Then what about a multi-user setup? Something like this?

/home/marcus/mypackage_settings.ini|yaml|json

Then what about a multi-site setup? Something like this?

//network/mypackage_settings.ini|yaml|json

Then what about when the network isn’t available, and what about slow networks/large configurations?

Also, by using this method it is OS agnostic.

Could you expand on this? Isn’t JSON and YAML and pretty much any file-based persistence also OS agnostic? What about the settings do you find OS-dependent? I could see how this is a benefit for things like C++ where I/O may differ per platform, but in Python I’m not so sure!

I’m may be living in the stone ages, but I still use optionVars, even for my QtGuis.

optionVars for maya stuff; json or yaml files in the user’s local appdata for everything else.

Last time I had to do this sort of thing, I used ConfigParser and associated files. It wasn’t great, because I spent of lot of time converting to the right data types from the strings passed. Next project is json.

my problem with opt vars is that it adds one more place to look for settings. Plus its a bitch to see what the values are.

i just use a lot of json, sometimes in maya i will use OptionVars. In the past for quick and dirty persistence i have used the pickle modual to just searlize a whole python object that carries my settings.

Thanks guys. For those not using QSettings, are multiple users accessing/modifying a single set of settings at any one time? If so, have you ever had issues with corruption?

QSettings is supposedly thread-safe and handles file-locking for you.
http://qt-project.org/doc/qt-4.8/qsettings.html#accessing-settings-from-multiple-threads-or-processes-simultaneously

QSettings also handles conversion between data types.

Thanks cgjedi. Would you mind posting an example of that? It might be the case that JSON and YAML also does this, but I’m not sure if I’m thinking of the same thing.

Always good to read straight from the source. http://qt-project.org/doc/qt-4.8/qsettings.html#details

Yes, thank you, I’m familiar with QSettings. My question was about whether or not you meant the same as JSON and YAML also does. :slight_smile: Sorry for the confusion!