add toml support for ParamsDependency#4258
Conversation
There was a problem hiding this comment.
We use yaml to load json as well.
There was a problem hiding this comment.
Could just try checking toml suffix, and then fallback to yaml.safe_load.
There was a problem hiding this comment.
I just force-pushed a check for suffix (use yaml.safe_load() for json and yaml)
There was a problem hiding this comment.
Still this misses the yml. So, it's better to just:
if suffix == "toml":
# toml load
else:
# yaml load
There was a problem hiding this comment.
Is it actually safe for us to guess the file format from the suffix here? It seems like we'll potential to run into issues where users have params filenames with unexpected capitalization on case-sensitive filesystems, or where they are using .yml instead of .yaml.
It seems to me we should maybe just try to load as yaml (and json) first, then try toml if that fails, then error out?
There was a problem hiding this comment.
I added a loader map which is based on the lowercase file suffix, which defaults to yaml.safe_load for unknown suffixes. I also updated _read_params
There was a problem hiding this comment.
I also agree with @pmrowla , it is better to just try to load and catch yaml formatting error than only trying to judge by the extension.
There was a problem hiding this comment.
In the last force-push I ended up using another approach (default to yaml.safe_load, use toml if lowercase suffix matches) because I felt a nested try/catch a bit awkward, especially if there are other loaders different from yaml/json and toml (not that I think there's much more, these 3 alone probably cover most of the use cases).
What is your preference?
Also, I saw that the Travis build fails on Windows and Mac (probably due to misconfiguration?) is there anything I need to do about that? Thanks
There was a problem hiding this comment.
Makes sense, let's keep it. 👍
06fd02a to
2900649
Compare
2900649 to
edebcb4
Compare
| res[str(config)] = yaml.safe_load(fobj) | ||
| except yaml.YAMLError: | ||
| res[str(config)] = ParamsDependency.PARAMS_FILE_LOADERS[ | ||
| config.suffix.lower() |
|
Please, don't forget to update the docs after this is merged. |
Codecov Report
@@ Coverage Diff @@
## master #4258 +/- ##
==========================================
- Coverage 91.77% 91.30% -0.48%
==========================================
Files 173 173
Lines 11743 11772 +29
==========================================
- Hits 10777 10748 -29
- Misses 966 1024 +58
Continue to review full report at Codecov.
|
|
@dtrifiro Could you please submit a docs PR for https://dvc.org/doc/command-reference/run ? |
skshetry
left a comment
There was a problem hiding this comment.
Looks good. It'd be great if you could move these logics to somewhere else, like dvc/repo/params/utils.py as load_params(path_info), but I'm fine with it for now though.
|
|
@dtrifiro Thank you so much! 🙏 |
We've been testing DVC with a few of our projects and for some of those we use a toml config to store parameters.
This PR adds support for parameters file in toml format. Example:
Where
params.tomllooks something like this: