Skip to content

Add labconfig.{save,load}_appconfig() #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

chrisjbillington
Copy link
Member

These functions save a dict as an .ini file and load a dict from an
ini file, respectively. Strings are converted with pprint.pformat and
ast.literal_eval, which round-trip for standard Python datatypes.

These are the semantics presently used by apps (except BLACS) to save
their configs, but they use the LabConfig class to do so. Since #45
removed auto-saving of labconfig and auto creation of sections upon
setting a value (essentially it made labconfig read-only) apps using
labconfig to save data now may fail (labscript-suite/lyse#64).

Apps may instead use save_appconfig() to save data. They may continue
to use labconfig to load data as they are presently, but could be
simplified by using load_appconfig() instead.

This change doesn't modify the format of app config files and so is
backward compatible with existing config files.

These functions save a dict as an `.ini` file and load a dict from an
ini file, respectively. Strings are converted with `pprint.pformat` and
`ast.literal_eval`, which round-trip for standard Python datatypes.

These are the semantics presently used by apps (except BLACS) to save
their configs, but they use the `LabConfig` class to do so. Since labscript-suite#45
removed auto-saving of labconfig and auto creation of sections upon
setting a value (essentially it made labconfig read-only) apps using
labconfig to save data now may fail (labscript-suite/lyse#64).

Apps may instead use `save_appconfig()` to save data. They may continue
to use labconfig to load data as they are presently, but could be
simplified by using `load_appconfig()` instead.

This change doesn't modify the format of app config files and so is
backward compatible with existing config files.
Disable auto lower-casing of keys. Apps set upper case keys, so we don't
want the dict they get back to have be lowercase or lookup will fail
(whereas lookup is case-insensitive for configparser generally).
This reproduces the behaviour of apps using LabConfig to read config
(which previously would create the file if it doesn't exist - we don't
do that but we don't crash either)
chrisjbillington added a commit to chrisjbillington/runmanager that referenced this pull request May 29, 2020
chrisjbillington added a commit to chrisjbillington/runviewer that referenced this pull request May 29, 2020
@chrisjbillington chrisjbillington merged commit dc7833a into labscript-suite:master May 30, 2020
@chrisjbillington chrisjbillington deleted the save-load-appconfig branch May 30, 2020 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant