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

build: Add support for JSON configuration files #17

Closed
wants to merge 1 commit into from

Conversation

microhobby
Copy link
Contributor

Adding support also to JSON configuration files. This way users and other programs can easily read and write the configuration file. JSON is a widely used format and has support in many programming languages and tools sometimes even natively, not the case of YAML.

Adding support also to JSON configuration files. This way
users and other programs can easily read and write the
configuration file. JSON is a widely used format
and has support in many programming languages and tools
sometimes even natively, not the case of YAML.

Signed-off-by: Matheus Castello <[email protected]>
if config_path.endswith(".json"):
config = _load_config_file_json(config_path)
elif config_path.endswith(".yaml") or config_path.endswith(".yml"):
config = _load_config_file_yaml(config_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably provide a clean error message (and abort) if no supported extension was found. Now I think it will raise an exception for config being undefined.

error_exc = ParseError(getattr(ex, "msg", "parsing error"))
error_exc.set_source(file=config_path)
if hasattr(ex, "doc"):
error_exc.set_source(line=ex.doc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this use ex.doc as the line number? Seems that JSONDecodeError has lineno (and also colno) attributes: https://docs.python.org/3/library/json.html#json.JSONDecodeError

Copy link
Contributor

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a passerby here, but I noticed this PR and it looks interesting. I took a quick look, overall looks good, but I left some small comments inline. This probably also needs some documentation/example and tests, but docs probably live elsewhere and how to run (and write) tests is not really documented AFAICS, so that might be up to Toradex to add.

@commontorizon commontorizon closed this by deleting the head repository Dec 30, 2024
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.

3 participants