-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 for ParamsDependency #4258
Conversation
dvc/dependency/param.py
Outdated
config = yaml.safe_load(fobj) | ||
except yaml.YAMLError as exc: | ||
if self.path_info.suffix == ".yaml": | ||
config = yaml.safe_load(fobj) |
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.
We use yaml
to load json as well.
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.
Could just try checking toml
suffix, and then fallback to yaml.safe_load
.
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.
I just force-pushed a check for suffix (use yaml.safe_load()
for json and yaml)
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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() |
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.
+1
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 ? |
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.
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.toml
looks something like this: