-
Notifications
You must be signed in to change notification settings - Fork 1.3k
plots: make templates generation explicit #7108
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
Conversation
2d22f8e to
82016e9
Compare
dberenbaum
left a comment
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.
So it seems like this has two uses:
- Make it easy to see and modify templates.
- Get updated templates if the ones currently in
.dvc/plotsare outdated.
Is that what you have in mind @pared?
dvc/command/plots.py
Outdated
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.
Does it make sense to be able to specify a different path to dump to? Maybe I am worried about overwriting what I have now, or I've made modifications to the defaults.
Also, can I dump just one template? This seems less necessary, but it might be nice to not have to generate all the templates if I only want one, especially if the number of templates grows.
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 think it makes sense to extend the functionality of templates, though it raises another questions.
- If we want to specify particular template, do we want any means of obtaining templates available for this particular repo? I think so, that would make the user experience much better than circling between terminal and docs.
- If we agree in 1, should
templateshave subcommands? eg (writeandlist)? That would make sense and be unified with our other commands.
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.
When dumping targets, I was thinking of the default templates, not any file, since otherwise it's just copying a file, right? Is there a use case you had in mind? I see that it works to do something like dvc plots template linear, but it's not that clear from the help description that targets doesn't have to specify existing files. If I already have linear.json in .dvc/plots, will dvc templates linear dump the internal version or the one on file?
Having a way to list templates seems great. Maybe --list can be an option to avoid subcommands?
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 think we should throw an exception if we are trying to dump a template that is different from the existing one under the given path. Do you want a new one? Fine, remove the old one manually. No chance of accidental removal of custom changes.
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 there a use case you had in mind?
Not exactly, just wanted to clarify
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.
Yes
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.
If I already have
linear.jsonin.dvc/plots, willdvc templates lineardump the internal version or the one on file?
So this will fail because it will overwrite .dvc/plots/linear.json, correct? What about dvc templates linear -o new_linear.json? Which template version will it dump?
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.
So this will fail because it will overwrite .dvc/plots/linear.json, correct?
It will fail only if the content of the template differs.
dvc templates linear -o new_linear.json?
About that, another question: do we want to specify particular file? Currently it is implemented that out is dir to dump templates to (to be able to dump few at once). But I guess it makes more sense to specify particular templates and particular paths.
Which template version will it dump?
The one that is loaded from DVC code, so the newest one.
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.
It will fail only if the content of the template differs.
Sounds good, although it also seems like more work for you to check if the contents are the same. It also seems fine to me to fail anytime a file would be overwritten.
do we want to specify particular file?
No, sorry, I got confused. No need to specify a particular file.
Which template version will it dump?
The one that is loaded from DVC code, so the newest one.
So will dvc plots templates always operate on the built-in templates? Maybe we should specify in the help description if so.
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.
No, sorry, I got confused. No need to specify a particular file.
I probably should explaining it in option description
So will dvc plots templates always operate on the built-in templates? Maybe we should specify in the help description if so.
Will do
|
What do we think about renaming |
f3d5ef0 to
671ced2
Compare
|
@pared @dberenbaum qq - how will the workflow with plots look like? how will this affect docs? |
|
I think you'll have to "dump" the templates first before you can use |
|
You should not have to dump the templates. The default templates are stored internally, so these should not be breaking changes. The goal is to provide a mechanism to update plots without breaking current functionality.
@pared Please correct any mistakes/oversights! |
|
@dberenbaum that's precisely what this change is about |
8d5d1e2 to
02d473c
Compare
"Internally" as in inside a DVC package installation directory? Something like /etc/dvc/plots ? oic
Wait. So the system-level plots templates are being updated compared to the repo-level ones as well? If so how will users know that there's newer templates available and why/how to get them? We could just tell them to Sorry, still unclear to me why you'd ever need to dump default templates if they're always available in the installation files. We should document the system plot templates location anyway, so people can just |
I guess as a helper to avoid figuring out the system file location on your platform? If we do keep this, maybe |
That was the initial plan, but it caused difficulties with packaging. Instead, they are composed within the code, and there's no path where the template exists as a JSON file.
Yup, you got it. As mentioned above, it's unfortunately difficult to keep copies of the templates in some easy-to-find system file location, so there's no way to see the templates without some command like this.
Yeah, this has been added as well. |
oic! No more doubts on my end. Except that I still wonder how/if we'll message users of existing projects on older DVC versions on how to upgrade and if so (or as docs in general) I suggest we recommend the |
Right, we were still working through this when the PR first opened. In fact, they will need to do this since However, if they (or users with new repos) want to see what the current templates look like (or to modify them), they will need this command. |
1e8f5f1 to
63b1db7
Compare
|
@dberenbaum The change is ready. |
dberenbaum
left a comment
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.
Looking good!
dvc/command/plots.py
Outdated
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.
Can we make the actual built-in templates as choices here? Right now, it dumps an empty directory if passed an invalid template. Ideally, it would fail.
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.
Sounds good, though I am not sure it will be able to handle all as default, I will see what I can do.
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 think it's fine to make nargs="?" (only allow one template) to simplify. What do you think? In that case, I would adjust the help text:
| help="Templates to write. Writes all templates by default.", | |
| help="Template to write. Writes all templates by default.", |
dvc/command/plots.py
Outdated
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.
If the built-in templates show up as choices above then we might not need this option at all, right?
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.
removed for now, check #7108 (comment) for my current proposition for this problem
5ddee73 to
0f04107
Compare
a4a03eb to
d0f1e8f
Compare
|
@pared What's the status for this? |
|
Got distracted with flexible plots and support, will try to finish it this week. |
d0f1e8f to
8b22406
Compare
8b22406 to
8863876
Compare
|
@dberenbaum I have been playing a bit with it and the nicest looking thing that I was able to make work is currently at the master:
(dvc3.8) β dvc git:(6389_optional_plots) β dvc plots templates 0.000s
Templates have been written into '.dvc/plots'.
(dvc3.8) β dvc git:(6389_optional_plots) β tree .dvc/plots 0.000s
.dvc/plots
βββ confusion.json
βββ confusion_normalized.json
βββ linear.json
βββ scatter.json
βββ simple.json
βββ smooth.json
0 directories, 6 files
(dvc3.8) β dvc git:(6389_optional_plots) β
(dvc3.8) β dvc git:(6389_optional_plots) dvc plots templates simple linear 0.000s
Templates have been written into '.dvc/plots'.
(dvc3.8) β dvc git:(6389_optional_plots) β tree .dvc/plots 0.000s
.dvc/plots
βββ linear.json
βββ simple.json
0 directories, 2 files
(dvc3.8) β dvc git:(6389_optional_plots) β
(dvc3.8) β dvc git:(6389_optional_plots) β dvc plots templates --help 0.000s
usage: dvc plots templates [-h] [-q | -v] [-o <path>]
[['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth']
[['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth'] ...]]
Write built-in plots templates to a directory (.dvc/plots by default).
Documentation: <https://man.dvc.org/plots/templates>
positional arguments:
['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth'] Templates to write. Writes all templates by default.
optional arguments:
-h, --help show this help message and exit
-q, --quiet Be quiet.
-v, --verbose Be verbose.
-o <path>, --out <path>
Directory to save templates to.
(dvc3.8) β dvc git:(6389_optional_plots) β
(dvc3.8) β dvc git:(6389_optional_plots) dvc plots templates wrong_template simple 0.000s
ERROR: argument ['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth']: Incorrect template name: 'wrong_template' not in 'simple, linear, confusion, confusion_normalized, scatter, smooth'
usage: dvc plots templates [-h] [-q | -v] [-o <path>]
[['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth']
[['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth'] ...]]
Write built-in plots templates to a directory (.dvc/plots by default).
Documentation: <https://man.dvc.org/plots/templates>
positional arguments:
['simple', 'linear', 'confusion', 'confusion_normalized', 'scatter', 'smooth'] Templates to write. Writes all templates by default.
optional arguments:
-h, --help show this help message and exit
-q, --quiet Be quiet.
-v, --verbose Be verbose.
-o <path>, --out <path>
Directory to save templates to.
(dvc3.8) β dvc git:(6389_optional_plots) |
tests/unit/command/test_plots.py
Outdated
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.
Had to add the names of the templates manually to avoid importing plots on every cmd use. This test has been created to make sure plots module and templates command are in sync.
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.
Ah, nice idea!
|
Looks good @pared! I was thinking in #7108 (comment) that if you only allow one template (which seems reasonable to me), then it could look like: I don't think that requires you to manually check for valid template names (although you still need Multiple choices not supported: Help: Wrong argument: Now that you have done it this way, I'm fine with either. Do you prefer keeping the option for multiple targets? |
|
Ok, so I guess my research was to shallow - as I mentioned earlier, providing |
|
@dberenbaum So I though (as per my previous comment) that we will be unable to use choices without adding |
f7491d2 to
4c3663b
Compare
4c3663b to
ed074f9
Compare
|
@dberenbaum not yet, creating |
Fixes: #6389
β I have followed the Contributing to DVC checklist.
π If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.
Thank you for the contribution - we'll try to review it as soon as possible. π
Changes in this PR:
.dvc/plotswill no longer be created upondvc initdvc plots templatesto create and populate.dvc/plotsTODO