c-w / gutenberg

A simple interface to the Project Gutenberg corpus.
Apache License 2.0
320 stars 60 forks source link

Add _format_download_uri_for_extension method #108

Closed c-w closed 6 years ago

c-w commented 6 years ago

In https://github.com/c-w/gutenberg/issues/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_extension which is a refactoring of our existing URI formatting logic that can take an arbitrary file extension like -pdf.pdf (as for example returned by the formaturi metadata 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:

hugovk commented 6 years ago

python setup.py install to install the correct dependencies is a good idea.

Would it be better to instead call pip install . for the reasons given here?

http://python3statement.org/practicalities/#unit-testing-and-documentation

c-w commented 6 years ago

Interesting, didn't know about that. Fixed in ee601ae.