-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for config files in TOML and YAML formats #73
Add support for config files in TOML and YAML formats #73
Conversation
🎉 All dependencies have been resolved ! |
This pull request now has conflicts with the target branch. Please resolve these conflicts and force push the updated branch. |
d01805a
to
6c2e815
Compare
This pull request now has conflicts with the target branch. Please resolve these conflicts and force push the updated branch. |
Python 3.11 and later includes support for reading TOML files. Add support for reading TOML based configuration to sambacc. Signed-off-by: John Mulligan <[email protected]>
Signed-off-by: John Mulligan <[email protected]>
The YAML format is extremely popular and much easier to write by hand than JSON. Add support for YAML based configuration files to sambacc. Signed-off-by: John Mulligan <[email protected]>
Signed-off-by: John Mulligan <[email protected]>
In versions of python prior to 3.11, we can fall back to the tomli library for toml support. Signed-off-by: John Mulligan <[email protected]>
Skip the toml related test cases only if neither tomli or tomllib are available. Signed-off-by: John Mulligan <[email protected]>
The toml extra declares we optionally depend on tomli on python versions older than Python 3.11. The yaml extra declares we optionally depend on PyYAML. Signed-off-by: John Mulligan <[email protected]>
Signed-off-by: John Mulligan <[email protected]>
Signed-off-by: John Mulligan <[email protected]>
I'm confident that the python packages available on fedora 37, and presumably later versions, support all the deps we need for all our extras. Thus this change adds RPM Recommends for our extras but only for fedora 37 and later. Signed-off-by: John Mulligan <[email protected]>
6c2e815
to
52f8bd2
Compare
Mention that sambacc support yaml and toml and give brief examples of both. Signed-off-by: John Mulligan <[email protected]>
95ae94b
to
70239cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sambacc/config.py
Outdated
if fname.endswith(".toml"): | ||
return ConfigFormat.TOML | ||
return ConfigFormat.JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but I would prefer using splitext and compare with any of valid enum values of ConfigFormat
. Just an idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks! good to move away from json as the only config format imho.
Depends on: #69
JSON is great in that it is standardized, tons of languages support it, and it's pretty simple to parse and work with. It is pretty terrible to edit by hand though. This PR adds support for both TOML and YAML as formats for our sambacc configuration. The intent here is to make writing a config by hand simpler and thus using samba-container directly without management by the operator, for example, easier.
TOML is probably the nicest to work with once you memorize the rules around brackets (tables vs. arrays of tables). This module is included in python, however, the python version must be 3.11 or later.
YAML is a superset of JSON that is much easier to write and is extremely popular, if a bit over-complicated.
The file format to use is selected based on the file name's extension. To use TOML the file name must end with ".toml". To use YAML the file name must end with either ".yml" or ".yaml".
These changes build upon the work to use jsonschema. Despite the name the jsonschema can be applied to both these formats as it's really describing the underlying strucutre of the data (not the formatting) and both new formats are largely json-compatible, with similar structural and basic data types.
TODO: