diff --git a/patacrep/build.py b/patacrep/build.py index 7ec0d739..6c61583b 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -128,9 +128,9 @@ class Songbook: def iter_errors(self): """Iterate over errors of book and book content.""" yield from self._errors - content = self._config.get('content', list()) - yield from content.iter_errors() - for item in content: + contentlist = self._config.get('content', list()) + yield from contentlist.iter_errors() + for item in contentlist: if not hasattr(item, "iter_errors"): continue yield from item.iter_errors() diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index ef389bfd..1aaf5043 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -147,28 +147,38 @@ class ContentList: yield from self._content def extend(self, iterator): + """Extend content list with an iterator. + + If the argument is of the same type, the list of errors is + also extended. + """ self._content.extend(iterator) - if isinstance(iterator, self.__class__): - self._errors.extend(iterator._errors) + if isinstance(iterator, ContentList): + self._errors.extend(iterator.iter_errors()) def append(self, item): + """Append an item to the content list.""" return self._content.append(item) def __len__(self): return len(self._content) def append_error(self, error): + """Log and append an error to the error list.""" LOGGER.warning(error) self._errors.append(error) def extend_error(self, errors): + """Extend the error list with the argument, which is logged.""" for error in errors: self.append_error(error) def iter_errors(self): + """Iterate over errors.""" yield from self._errors class EmptyContentList(ContentList): + """Empty content list: contain only errors.""" def __init__(self, *, errors): super().__init__() for error in errors: diff --git a/patacrep/content/include.py b/patacrep/content/include.py index a972d5bf..92f060ab 100644 --- a/patacrep/content/include.py +++ b/patacrep/content/include.py @@ -6,7 +6,6 @@ songs in JSON format. import json import os -import sys import logging from patacrep.content import process_content, ContentError, ContentList diff --git a/patacrep/content/song.py b/patacrep/content/song.py index a2cce2c0..dbdbe6c8 100755 --- a/patacrep/content/song.py +++ b/patacrep/content/song.py @@ -91,8 +91,8 @@ def parse(keyword, argument, contentlist, config): extension = filename.split(".")[-1] if extension not in plugins: songlist.append_error(ContentError(message=( - 'I do not know how to parse "{}": name does ' - 'not end with one of {}. Ignored.' + 'I do not know how to parse "{}": name does ' + 'not end with one of {}. Ignored.' ).format( os.path.join(songdir.datadir, filename), ", ".join(["'.{}'".format(key) for key in plugins.keys()]), diff --git a/patacrep/content/songsection.py b/patacrep/content/songsection.py index 2a5ba2d5..c5fea4ab 100755 --- a/patacrep/content/songsection.py +++ b/patacrep/content/songsection.py @@ -41,7 +41,7 @@ def parse(keyword, argument, contentlist, config): CONTENT_PLUGINS = dict([ - (word, parse) - for word + (keyword, parse) + for keyword in KEYWORDS ]) diff --git a/patacrep/content/sorted.py b/patacrep/content/sorted.py index cdb0dcd2..9f9fded9 100755 --- a/patacrep/content/sorted.py +++ b/patacrep/content/sorted.py @@ -9,7 +9,7 @@ import logging import unidecode from patacrep import files -from patacrep.content import ContentError, ContentList, EmptyContentList +from patacrep.content import ContentError, EmptyContentList from patacrep.content import process_content from patacrep.content.song import OnlySongsError diff --git a/patacrep/content/tex.py b/patacrep/content/tex.py index efacb838..f32880cf 100755 --- a/patacrep/content/tex.py +++ b/patacrep/content/tex.py @@ -51,11 +51,12 @@ def parse(keyword, argument, contentlist, config): )) break if not checked_file: - filelist.append_error(ContentError( - keyword="tex", - message=errors.notfound(filename, basefolders), + filelist.append_error( + ContentError( + keyword="tex", + message=errors.notfound(filename, basefolders), + ) ) - ) continue filelist.append(LaTeX(checked_file)) diff --git a/patacrep/latex/syntax.py b/patacrep/latex/syntax.py index 890ca79c..edf9ceb1 100644 --- a/patacrep/latex/syntax.py +++ b/patacrep/latex/syntax.py @@ -3,11 +3,10 @@ import logging import ply.yacc as yacc -from patacrep.songs.syntax import Parser -from patacrep.latex.lexer import tokens, SimpleLexer, SongLexer from patacrep.latex import ast -from patacrep.errors import ParsingError from patacrep.latex.detex import detex +from patacrep.latex.lexer import tokens, SimpleLexer, SongLexer +from patacrep.songs.syntax import Parser LOGGER = logging.getLogger() @@ -126,8 +125,7 @@ class LatexParser(Parser): else: symbols[0] = [] - @staticmethod - def p_dictionary(symbols): + def p_dictionary(self, symbols): """dictionary : identifier EQUAL braces dictionary_next | identifier EQUAL error dictionary_next | empty diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 7fcf5d4b..8c17b3da 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -1,6 +1,5 @@ """ChordPro parser""" -import functools import logging import re