-
Notifications
You must be signed in to change notification settings - Fork 76
[SVCS-159] Fix Extension Names in Renderer and Exporter #320
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
Closed
cslzchen
wants to merge
2
commits into
CenterForOpenScience:develop
from
cslzchen:fix/fix-renderer-and-exporter-names
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,44 +98,46 @@ def make_renderer(name, metadata, file_path, url, assets_url, export_url): | |
| } | ||
| ) | ||
|
|
||
| def get_renderer_name(name): | ||
|
|
||
| def get_renderer_name(name: str) -> str: | ||
| """ Return the name of the renderer used for a certain file extension. | ||
|
|
||
| :param str name: The name of the extension to get the renderer name for. (.jpg, .docx, etc) | ||
|
|
||
| :rtype : `str` | ||
| """ | ||
|
|
||
| # This can give back empty tuples | ||
| try: | ||
| entry_attrs = pkg_resources.iter_entry_points(group='mfr.renderers', name=name) | ||
|
|
||
| # ep.attrs is a tuple of attributes. There should only ever be one or `None`. | ||
| # None case occurs when trying to render an unsupported file type | ||
| # entry_attrs is an iterable object, so we turn into a list to index it | ||
| return list(entry_attrs)[0].attrs[0] | ||
| # `ep_iterator` is an iterable object. Must convert it to a `list` for access. | ||
| # `list()` can only be called once because the iterator moves to the end after conversion. | ||
| ep_iterator = pkg_resources.iter_entry_points(group='mfr.renderers', name=name.lower()) | ||
| ep_list = list(ep_iterator) | ||
|
|
||
| # This means the file type is not supported. Just return the blank string so `make_renderers` | ||
| # can log a real exception with all the variables and names it has | ||
| except IndexError: | ||
| # Empty list indicates unsupported file type. | ||
| # Return a blank string and let `make_renderer()` handle it. | ||
| if len(ep_list) == 0: | ||
| return '' | ||
|
|
||
| def get_exporter_name(name): | ||
| # If file type is supported, there must be only one element in the list. | ||
| assert len(ep_list) == 1 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both exporter and renderer, use |
||
| return ep_list[0].attrs[0] | ||
|
|
||
|
|
||
| def get_exporter_name(name: str) -> str: | ||
| """ Return the name of the exporter used for a certain file extension. | ||
|
|
||
| :param str name: The name of the extension to get the exporter name for. (.jpg, .docx, etc) | ||
|
|
||
| :rtype : `str` | ||
| """ | ||
|
|
||
| # `make_renderer` should have already caught if an extension doesn't exist. | ||
|
|
||
| # should be a list of length one, since we don't have multiple entrypoints per group | ||
| entry_attrs = pkg_resources.iter_entry_points(group='mfr.exporters', name=name) | ||
| # `ep_iterator` is an iterable object. Must convert it to a `list` for access. | ||
| # `list()` can only be called once because the iterator moves to the end after conversion. | ||
| ep_iterator = pkg_resources.iter_entry_points(group='mfr.exporters', name=name.lower()) | ||
| ep_list = list(ep_iterator) | ||
|
|
||
| # ep.attrs is a tuple of attributes. There should only ever be one or `None`. | ||
| # For our case however there shouldn't be `None` | ||
| return list(entry_attrs)[0].attrs[0] | ||
| # `make_renderer()` is called before `make_exporter()` to ensure the file type is supported | ||
| assert len(ep_list) == 1 | ||
| return ep_list[0].attrs[0] | ||
|
|
||
|
|
||
| def sizeof_fmt(num, suffix='B'): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For both exporter and renderer, the primary functional change is
name=name.lower().