-
Notifications
You must be signed in to change notification settings - Fork 1.3k
plots: load templates from package #6550
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
93559f5 to
d4ee1be
Compare
I was thinking that these two templates should be called "linear" and "simple" or "linear_simple" rather than calling either "default." I think it's more helpful to have descriptive names even for the default, and it's easy to document that the default is "linear." In fact, the current documentation is confusing in that it doesn't differentiate between "default" and "linear" even though they are different templates: https://dvc.org/doc/command-reference/plots#plot-templates. Thoughts?
I'm not sure what's best, or whether this should be included in this PR.
A couple other ideas that might help with this problem:
|
That makes more sense, I will do proper changes.
This was never discussed, I think the main reason to dump the templates was to make them easily accessible for users so that they can modify default ones, and start working on their own just by copying pre-existing ones.
Depends where. If it will be put into
Do I understand right? Include only
Makes sense, it would tie the plot to DVC version, and not the repository. I think that one more reason to get rid of the templates from repo is that it creates additional files that some users consider garbage. #6389 |
|
cc @skshetry |
π That's my suggestion. To my understanding, current issues are:
So I propose:
By the way, can templates be in Interested to hear what you and others think. @skshetry Do you think this makes sense for stage templates in @shcheklein Do you see any impacts for other products? |
|
It might affect a bit other products. It should be fine with Studio (since it's Python), it might not be as fine for VS Code. We might need an interface to access templates in some way (e.g. to determine if that template merges data or not). I think it's doable even if I think the point here is that by hiding them in the package we are indeed increasing complexity of people accessing them (manually, programmatically), so I would weight the benefits one more time to be honest. Not an obvious thing to do. |
|
@pared Even though it will not get automatically pushed to existing repos, can we merge the changes to those linear templates for now and discuss the template organization in a separate issue/PR? |
d4ee1be to
7247664
Compare
58a9918 to
369e129
Compare
|
@dberenbaum I added update to issue description. |
dvc/repo/plots/template.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.
Preserving previous behaviour of writing default templates to .dvc/plots. It will be removed in next change.
|
Thanks @pared! I meant that this PR could be limited to making the linear plot the default and renaming the current default. I didn't expect you to already move all the templates into json files in a pkg resources dir, but not sure it's worth reverting at this point. |
541cf4d to
f809486
Compare
|
@pmrowla, @dberenbaum, the PR is ready for review |
dvc/repo/plots/template.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.
Is this temporary for backwards compatibility or is intended that we will keep it long-term?
Plots included in pkg dir + being able to specify custom template path should be enough, and dropping TEMPLATES_DIR will ignore outdated templates in .dvc/plots.
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.
The problem here is what in a case when user modified hers/his plots in .dvc/plots? If we drop .dvc/plots user will need to specify the path. It's not a big problem but will be annoying. Also .dvc/plots seems like a good default place for users to put their own templates if they don't want to clutter their repo with templates dir. On the other hand, repos created pre-this-release will keep using outdated templates which is also not good.
We can always consider dropping .dvc/plots in 3.0
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.
Let's document how users with old repos can get updated templates by deleting the old ones. Also, are you planning a follow-up to dump the templates?
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, I didn't include it here to not clutter it anymore.
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 might be good to rename the PR since it seems to extend pretty far beyond the original title.
f809486 to
23fbce4
Compare
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.
The changes on the code side LGTM
c47ce6a to
4c98f0e
Compare
| templates = self._get_templates() | ||
| for template in templates: | ||
| content = ( | ||
| importlib_resources.files(__package__) |
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.
This Traversable thing with files() is giving me ideas to implement this for dvc.api for directories. π
|
@pared, you may also need to add files to the pyinstaller: https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-files-to-the-bundle |
|
@skshetry thanks, can confirm it's not working for the binary package, preparing a fix... |
β 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. π
Fixes #6513
Prerequisit to #6389
This change makes the default plot interactive. The previous default plot is now named "simple".
Since we are changing the default template, the repositories created before this change would not be affected by this change. In order to prevent that we remove dumping plots templates ondvc initand make dvc try to match template by name (same as we do in the case of non-dvc repositories).One drawback is that users lose the ability to edit default templates, as well as producing their own templates is harder since default ones are not simply under.dvc/plots. We could fix that by improving our docs with the "Create your custom template" example inplotsdocumentation.Marking as draft to not merge before appropriate docs update.
EDIT:
This change is moving the templates from within the code to package data. The order of looking for template when provided in case of
dvc plots show/diffiscwd->.dvc/plots->package_data.After this change the default plot will be
linear, and previousdefaultis renamed tosimple.In following change I will introduce command letting user dump the templates into
.dvc/plots