-
Notifications
You must be signed in to change notification settings - Fork 76
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
user API for export plot plugin #1657
Conversation
Codecov ReportBase: 87.11% // Head: 87.07% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1657 +/- ##
==========================================
- Coverage 87.11% 87.07% -0.05%
==========================================
Files 95 95
Lines 9891 9902 +11
==========================================
+ Hits 8617 8622 +5
- Misses 1274 1280 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
AFAIK this will pop up a file dialog regardless. Are you able to overwrite the filename the dialog prompts you via API? I don't remember. It's been a while since #929 |
Right, it should overwrite the default name in the file dialog, but the file dialog is still raised. Hopefully we can eventually fix #929 and this will then just take the user input from the API without the need for the dialog. |
Should test coverage be added here or is that blocked because of the dialog popup? (Note the uncovered lines were uncovered before, now they've just been moved around a little to be available without the |
It is impossible to test due to the pop up. It pops up and will hold the CI until it times out.
|
""" | ||
if filetype is None: | ||
if filename is not None: | ||
filetype = filename.split('.')[-1] |
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.
Sometimes people just give the name without suffix because they are used to other software attaching suffix for them.
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.
Maybe the code to auto populate the filename should be its own private function, so at least we can test that part. The only thing we cannot test is viewer.figure.save_png()
call.
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.
that's fine, this logic should handle that scenario as expected, right? I guess the only problem would be if they did filename='blah.randomextension'
which would raise a NotImplementedError
instead of saving to blah.randomextension.png
.
Should I instead only apply the filetype if its either png or svg and otherwise default to png? But then filename='blah.jpeg'
would silently write to blah.jpeg.png
.
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.
Silent fallback means they still get the image, better than error from trying to save to an unsupported extension? Unless you want upstream to deal with that instead?
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 always prefer (helpful) errors than unexpected magic/fallbacks myself 🤷
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 I don't give file extension to Photoshop, it doesn't crash. It saves my stuff in some default format. I think users might be looking for similar established behaviors. 🤷
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.
Works for me
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.
done (default to png when no extension is provided in the filename by checking for '.' in filename
)
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.
By the way, would mimetypes be useful for your purpose? https://docs.python.org/3/library/mimetypes.html
In [10]: mimetypes.guess_type('dummy_gwcs.png')
Out[10]: ('image/png', None)
In [11]: mimetypes.guess_type("test_spec")
Out[11]: (None, None)
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.
interesting idea. I think it might be overkill here since we're passing to one of two backend calls... but maybe if we generalize that in the future to avoid the file dialog, this would be a good direction to take.
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.
Just minor comments, otherwise LGTM. Thanks!
Still need a change log. FYI. |
Yes, I'll add the change log between approval and merge (since there are still a few outstanding API PRs that touch the same change log entry and cause constant conflicts otherwise) |
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.
LGTM
a9bcbb4
to
d3c8b0b
Compare
Description
This pull request extends on #1401 and provides user-API access to the export plot plugin.
Plugin User API docs
TODO:
Change log entry
CHANGES.rst
? If you want to avoid merge conflicts,list the proposed change log here for review and add to
CHANGES.rst
before merge.Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
trivial
label.