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

Add toml support #5

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Add toml support #5

merged 2 commits into from
Oct 23, 2023

Conversation

luator
Copy link
Member

@luator luator commented Oct 17, 2023

TOML files are read to dictionaries just like JSON or YAML, so to support them as well.
TOML doesn't allow duplicate keys as per its standard, so no explicit check is needed for that.

The tomllib package was added in Python 3.11. For older versions, the third-party package tomli can be used as replacement (tomllib is actually based on tomli, so they should be pretty compatible).

Also fixes a bug: load_raw_dict_from_file() now raises an error if an unsupported file type is passed.

How I Tested

In combination with cluster_utils (converting an existing json config file to toml and running with that file).

Do not merge before

@luator luator self-assigned this Oct 17, 2023
if filename.endswith(".json"):
with open(filename, "r") as f:
data = json.load(f, object_pairs_hook=NoDuplicateDict)
return data
elif filename.endswith(".yaml"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does not fit this PR, but as you are touching the file anyways: could you also make it select YAML if the file ends on .yml? This has been bugging me for some time.

Copy link
Member Author

Choose a reason for hiding this comment

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

added :)

@mseitzer
Copy link
Collaborator

Looks good, no objections!

Base automatically changed from fkloss/black to master October 23, 2023 07:31
TOML files are read to dictionaries just like JSON or YAML, so to
support them as well.
TOML doesn't allow duplicate keys as per its standard, so no explicit
check is needed for that.

The `tomllib` package was added in Python 3.11.  For older versions, the
third-party package `tomli` can be used as replacement (`tomllib` is
actually based on `tomli`, so they should be pretty compatible).
@luator luator merged commit eb7331f into master Oct 23, 2023
1 check passed
@luator luator deleted the fkloss/toml branch October 23, 2023 07:38
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.

2 participants