EuroPi
EuroPi copied to clipboard
Treat `europi_config` keys like named constants
Proposal based on Discord suggestions. Instead of using a raw dict
for the static configuration settings, create a wrapper object that creates named-constant-like attributes with the same values as the underlying keys. This exposes the configuration settings with the dir
function, and should help make it clear that values in experimental_config
and europi_config
are to be treated as constants in contrib
scripts (and elsewhere).
Marked as a draft since this is just a proposal at this stage, and it seemed easiest to create a full MR to show what I meant, rather than code snippets.
I merged the updates to the JSON read/write functions & rebased this MR to the latest main
.
After the discussions here & on Discord, I'm going to remove the draft
tag; I think we're all generally in agreement that this is a positive change to how configuration files work.
To add my 2 cents, as mentioned by @mjaskula in a previous comment, this is a specific implementation of everything being used (JSON formatting etc) so I think it's fine to deviate from the norm when it comes to professional usage, if it works in favour of making this specific implementation simpler, which I think capitalised names across the board (including in the JSON file) would do. It would make the documentation a lot simpler to say 'The maximum output voltage config value is called "MAX_OUTPUT_VOLTAGE"' and know that it applies everywhere it's referenced.
I accept the court's ruling and have migrated everything to use all-caps for JSON keys. Documentation has been updating accordingly.