Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Merge 35f2a65 into 1f2f85a
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w committed Apr 28, 2017
2 parents 1f2f85a + 35f2a65 commit 3652097
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 29 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Expand Up @@ -20,17 +20,16 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then pip install unittest2; fi
- pip install -r requirements.pip
- pip install -r requirements-py3.pip
- pip install coverage
- pip install -r requirements-dev.pip

script: coverage run --source=gutenberg -m nose
script:
- coverage run --source=gutenberg -m nose
- if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then flake8 gutenberg; fi

after_success:
- coverage report
- pip install coveralls
- coveralls
- pip install pyflakes pep8
- pyflakes . | tee >(wc -l)
- pep8 --statistics --count .

deploy:
provider: pypi
Expand Down
7 changes: 3 additions & 4 deletions gutenberg/_domain_model/types.py
Expand Up @@ -21,10 +21,9 @@ def validate_etextno(etextno):


def rdf_bind_to_string(rdf_type):
"""
Python2/3 compatibility wrapper around rdflib.term.bind that binds a term to
the approrpiate string type.
"""Python2/3 compatibility wrapper around rdflib.term.bind that binds a
term to the appropriate string type.
"""
string_type = unicode if sys.version_info < (3,) else str
string_type = unicode if sys.version_info < (3,) else str # noqa
bind(rdf_type, string_type)
5 changes: 4 additions & 1 deletion gutenberg/_util/decorators.py
Expand Up @@ -2,7 +2,10 @@


def execute_only_once(func):
"""Decorator that will only allow a function to be executed the first time it's called"""
"""Decorator that will only allow a function to be executed the first time
it's called
"""
def call_once(*args, **kwargs):
if not call_once._called:
try:
Expand Down
8 changes: 4 additions & 4 deletions gutenberg/_util/url.py
Expand Up @@ -2,10 +2,10 @@


try:
from urllib2 import urlopen
from urllib2 import urlopen # noqa
except ImportError:
from urllib.request import urlopen
from urllib.request import urlopen # noqa
try:
from urllib import pathname2url
from urllib import pathname2url # noqa
except ImportError:
from urllib.request import pathname2url
from urllib.request import pathname2url # noqa
9 changes: 5 additions & 4 deletions gutenberg/acquire/metadata.py
Expand Up @@ -150,7 +150,8 @@ def _metadata_is_invalid(fact):
"""Determines if the fact is not well formed.
"""
return any(isinstance(token, URIRef) and ' ' in token for token in fact)
return any(isinstance(token, URIRef) and ' ' in token
for token in fact)

@classmethod
def _iter_metadata_triples(cls, metadata_archive_path):
Expand Down Expand Up @@ -231,9 +232,9 @@ def _is_graph_add_exception_acceptable(cls, ex):
"""Checks if a graph-add exception can be safely ignored.
"""
# integrity errors due to violating unique constraints should be safe to
# ignore since the only unique constraints in rdflib-sqlalchemy are on
# index columns
# integrity errors due to violating unique constraints should be safe
# to ignore since the only unique constraints in rdflib-sqlalchemy are
# on index columns
return 'UNIQUE constraint failed' in text_type(ex)


Expand Down
25 changes: 14 additions & 11 deletions gutenberg/acquire/text.py
Expand Up @@ -21,12 +21,12 @@


def _etextno_to_uri_subdirectory(etextno):
"""
Returns the subdirectory that an etextno will be found in a gutenberg mirror. Generally, one
finds the subdirectory by separating out each digit of the etext number, and uses it for
a directory. The exception here is for etext numbers less than 10, which are prepended with a
0 for the directory traversal.
"""Returns the subdirectory that an etextno will be found in a gutenberg
mirror. Generally, one finds the subdirectory by separating out each digit
of the etext number, and uses it for a directory. The exception here is for
etext numbers less than 10, which are prepended with a 0 for the directory
traversal.
>>> _etextno_to_uri_subdirectory(1)
'0/1'
>>> _etextno_to_uri_subdirectory(19)
Expand All @@ -45,10 +45,11 @@ def _etextno_to_uri_subdirectory(etextno):
def _check_mirror_exists(mirror):
response = requests.head(mirror)
if not response.ok:
error = "Could not reach Gutenberg mirror '{0:s}'. Try setting a different mirror " \
"(https://www.gutenberg.org/MIRRORS.ALL) for --mirror flag or " \
"GUTENBERG_MIRROR environment variable.".format(mirror)
raise UnknownDownloadUriException(error)
raise UnknownDownloadUriException(
'Could not reach Gutenberg mirror "{0:s}". Try setting a '
'different mirror (https://www.gutenberg.org/MIRRORS.ALL) for '
'--mirror flag or GUTENBERG_MIRROR environment variable.'
.format(mirror))


def _format_download_uri(etextno, mirror=None):
Expand All @@ -73,7 +74,9 @@ def _format_download_uri(etextno, mirror=None):
response = requests.head(uri)
if response.ok:
return uri
raise UnknownDownloadUriException('Failed to find {0} on {1}.'.format(etextno, uri_root))

raise UnknownDownloadUriException('Failed to find {0} on {1}.'
.format(etextno, uri_root))


def load_etext(etextno, refresh_cache=False, mirror=None):
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.pip
@@ -0,0 +1,2 @@
coverage
flake8

0 comments on commit 3652097

Please sign in to comment.