This repository was archived by the owner on Jan 12, 2023. It is now read-only.
Add _format_download_uri_for_extension method#108
Merged
Conversation
Currently the GUTENBERG_MIRROR environment variable was only getting respected for CLI usage, not library usage. This change makes the handling of the environment variable consistent such that the default mirror can also be set via an environment variable when the project is used as a library.
The `load_etext` function currently throws an exception when there is no textual download candidate available for a given book. However, some users might want to use Gutenberg to download non-textual versions of books. All available formats of a book can already be looked up via the formaturi metadata extractor, so this change exposes a method to enable a client to format the download URL for an arbitrary extension. See #105
Contributor
|
Would it be better to instead call http://python3statement.org/practicalities/#unit-testing-and-documentation |
Owner
Author
|
Interesting, didn't know about that. Fixed in ee601ae. |
hugovk
approved these changes
Jun 26, 2018
hugovk
reviewed
Jun 26, 2018
| try: | ||
| from functools import lru_cache | ||
| except ImportError: | ||
| from functools32 import lru_cache |
Contributor
There was a problem hiding this comment.
Is this due to a Python 2/3 difference?
If so, commenting which is which will make dropping Python 2 easier in the near future.
Owner
Author
There was a problem hiding this comment.
Yes, functools.lru_cache was only added in Python 3. the functools32 package is a backport for Python 2.7 I'll add a comment.
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
In #105 we saw that there should be a method to leverage the URI building functionality of the Gutenberg library for non-text resources. This pull request implements
_format_download_uri_for_extensionwhich is a refactoring of our existing URI formatting logic that can take an arbitrary file extension like-pdf.pdf(as for example returned by theformaturimetadata call) and format the appropriate URL.This is not an official API (whence the underscore prefix) so no strict requirement to always maintain this function, but it's useful functionality to expose nevertheless given that we already have it in the code base.
When working on this change, I also noticed that we weren't correctly handling the case where the mirror root URL was changed in a single session so I also added a fix for that.
When verifying the refactor, I saw some odd behavior when running the tests locally, so this pull request also improves the developer experience for the tests:
requests.headcalls instead of doing it manually.python setup.py installto install the dependencies for the various runtimes since the setup file already knows how to load the correct pip dependencies for Python 2 vs Python 3. Previously on Travis we were always installing the Python 3 dependencies even when running the tests for Python 2 which could lead to odd behavior.