EuroPi icon indicating copy to clipboard operation
EuroPi copied to clipboard

Treat `europi_config` keys like named constants

Open chrisib opened this issue 1 year ago • 1 comments

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.

chrisib avatar Feb 17 '24 22:02 chrisib

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.

chrisib avatar Mar 04 '24 02:03 chrisib

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.

roryjamesallen avatar Mar 05 '24 18:03 roryjamesallen

I accept the court's ruling and have migrated everything to use all-caps for JSON keys. Documentation has been updating accordingly.

chrisib avatar Mar 05 '24 19:03 chrisib