Skip to content

Commit

Permalink
smaller compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Oct 26, 2018
1 parent 794455f commit ef23db5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/macrogen/__init__.py
@@ -0,0 +1,2 @@
from .graph import macrogenesis_graphs, BiblSource
from .uris import Reference, Witness, AmbiguousRef, Inscription
19 changes: 13 additions & 6 deletions src/macrogen/datings.py
Expand Up @@ -87,7 +87,7 @@ def _read_scores():
return scores


_bib_db = _parse_bibliography('https://raw.githubusercontent.com/faustedition/faust-gen-html/master/xslt/bibliography.xml')
bibliography = _parse_bibliography('https://raw.githubusercontent.com/faustedition/faust-gen-html/master/xslt/bibliography.xml')

_bib_labels = {
'faust://self': 'Faustedition',
Expand All @@ -112,7 +112,7 @@ def __init__(self, uri, detail=''):
if detail is None:
detail = ''
self.detail = detail
self.weight = _bib_db[uri].weight if uri in _bib_db else 1
self.weight = bibliography[uri].weight if uri in bibliography else 1

def __eq__(self, other):
if isinstance(other, BiblSource):
Expand Down Expand Up @@ -147,13 +147,20 @@ def citation(self):
Example:
Bohnenkamp 19994
"""
if self.uri in _bib_db:
return _bib_db[self.uri].citation
if self.uri in bibliography:
return bibliography[self.uri].citation
elif self.uri in _bib_labels:
return _bib_labels[self.uri]
else:
return self.filename

@property
def long_citation(self):
if self.uri in bibliography:
return bibliography[self.uri].reference
else:
return self.citation


class _AbstractDating(metaclass=ABCMeta):
"""
Expand Down Expand Up @@ -317,7 +324,7 @@ def add_to_graph(self, G: nx.MultiDiGraph) -> None:
ignore=self.ignore)


def _parse_file(filename: str) -> Generator[_AbstractDating]:
def _parse_file(filename: str) -> Generator[_AbstractDating, None, None]:
"""
Parses the given macrogenesis XML file and returns the datings from there.
Args:
Expand All @@ -336,7 +343,7 @@ def _parse_file(filename: str) -> Generator[_AbstractDating]:
logger.error(str(e))


def _parse_files() -> Generator[_AbstractDating]:
def _parse_files() -> Generator[_AbstractDating, None, None]:
"""
Parses the files in the macrogenesis folder and returns the datings from there.
Returns:
Expand Down
2 changes: 1 addition & 1 deletion src/macrogen/report.py
Expand Up @@ -154,7 +154,7 @@ def _format_row(self, row: Iterable, **rowattrs) -> str:
logger.exception('Error formatting row %s', row)
return f'<tr class="pure-alert pure-error"><td>Error formatting row {row}</td></tr>'

def _format_rows(self, rows: Iterable[Iterable]) -> Generator[str]:
def _format_rows(self, rows: Iterable[Iterable]) -> Generator[str, None, None]:
"""Formats the given rows."""
for row in rows:
yield self._format_row(row)
Expand Down

0 comments on commit ef23db5

Please sign in to comment.