Skip to content
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

Refactor configuration retrieval/writing #1102

Open
micahellison opened this issue Nov 28, 2020 · 3 comments
Open

Refactor configuration retrieval/writing #1102

micahellison opened this issue Nov 28, 2020 · 3 comments
Labels
enhancement New feature or request 📌 This can't go stale

Comments

@micahellison
Copy link
Member

Feature Request

Use Case/Motivation

Down the road, we'd like to allow users to modify the config from the command line (#330, #1068) but currently our configuration code is a bit finnicky.

We also currently have a process in our code that is constantly rewriting the config file, when it probably shouldn't be.

And it'd be very nice to support and preserve detailed default comments in the config file (#946).

And, as we come up with new config keys and deprecate old ones, it would be nice to have defaults for various keys that never need to be expressed in the config file, rather than constantly adding a "config stew" of keys.

To resolve this issues, we're probably going to want to:

  • Pick out a different YAML parsing library to read the config file
  • Create a class that represents config data
    • This class, or the code that reads the config data, should include defaults as necessary (even if the key wasn't found)
  • Ensure that all code reading config data uses this new class
  • Modify the existing code that writes to the config file
@micahellison
Copy link
Member Author

It looks pydantic could be promising for validating the config file when jrnl first loads.

@micahellison
Copy link
Member Author

For #946 to work using ruamel.yaml, we'll need to deal with two different representations of the configuration:

  • the actual YAML contents (including with comments), which can be treated more like a database context
  • the config values as read by the rest of jrnl, which can be treated more like a Plain Old Python Object (aka data transfer object)

One of the big innovations of ruamel seems to be around modifying just part of the YAML at once. We could take that approach, or keep loading the whole thing into memory then dumping it back. I don't think the performance implications are going to be significant either way so my impulse is to focus instead on maintainability wherever possible.

@micahellison
Copy link
Member Author

This refactor should also at least leave open the ability to read different versions of the config file, and probably some sort of versioning applied to the default values when they're not in the config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 📌 This can't go stale
Projects
None yet
Development

No branches or pull requests

2 participants