diff --git a/patacrep/content/include.py b/patacrep/content/include.py index 45540db9..dcc969a9 100644 --- a/patacrep/content/include.py +++ b/patacrep/content/include.py @@ -13,6 +13,7 @@ import logging from patacrep.content import process_content, ContentError from patacrep import encoding +from patacrep import errors LOGGER = logging.getLogger(__name__) @@ -26,8 +27,10 @@ def load_from_datadirs(path, config=None): if os.path.exists(filepath): return filepath # File not found - raise ContentError("include", "The file '{0}' was not found in the " - "datadirs.".format(path)) + raise ContentError( + "include", + errors.notfound(path, config.get("datadir", [])), + ) #pylint: disable=unused-argument def parse(keyword, config, argument, contentlist): diff --git a/patacrep/content/song.py b/patacrep/content/song.py index d2c30008..bff18bb1 100755 --- a/patacrep/content/song.py +++ b/patacrep/content/song.py @@ -9,7 +9,7 @@ import logging import os from patacrep.content import Content, process_content, ContentError -from patacrep import files +from patacrep import files, errors from patacrep.songs import Song LOGGER = logging.getLogger(__name__) @@ -86,9 +86,11 @@ def parse(keyword, argument, contentlist, config): break if len(songlist) == before: # No songs were added - LOGGER.warning( - "Expression '{}' did not match any file".format(elem) - ) + LOGGER.warning(errors.notfound( + elem, + [item.fullpath for item in config['_songdir']], + message='Ignoring "{name}": did not match any file in {paths}.', + )) return songlist diff --git a/patacrep/content/tex.py b/patacrep/content/tex.py index 030287b1..5f80fcfc 100755 --- a/patacrep/content/tex.py +++ b/patacrep/content/tex.py @@ -6,7 +6,7 @@ import logging import os -from patacrep import files +from patacrep import files, errors from patacrep.content import Content LOGGER = logging.getLogger(__name__) @@ -51,13 +51,8 @@ def parse(keyword, argument, contentlist, config): )) break if not checked_file: - LOGGER.warning( - ('Cannot find file "{}" in {}. Compilation may fail ' - 'later.').format( - filename, - ", ".join( - ['"{}"'.format(folder) for folder in basefolders] - )) + LOGGER.warning("{} Compilation may fail later.".format( + errors.notfound(filename, basefolders)) ) continue filelist.append(LaTeX(checked_file)) diff --git a/patacrep/errors.py b/patacrep/errors.py index a945a2ee..ff3d210d 100644 --- a/patacrep/errors.py +++ b/patacrep/errors.py @@ -84,3 +84,14 @@ class UnknownStep(SongbookError): def __str__(self): return """Compilation step "{step}" unknown.""".format(step=self.step) +def notfound(filename, paths, message=None): + """Return a string saying that file was not found in paths.""" + if message is None: + message = 'File "{name}" not found in directories {paths}.' + unique_paths = [] + #pylint: disable=expression-not-assigned + [unique_paths.append(item) for item in paths if item not in unique_paths] + return message.format( + name=filename, + paths=", ".join(['"{}"'.format(item) for item in unique_paths]), + ) diff --git a/patacrep/templates.py b/patacrep/templates.py index 02b14c42..ec8ad99c 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -100,10 +100,18 @@ class TexRenderer(object): try: self.template = self.texenv.get_template(template) except TemplateNotFound as exception: + # Only works if all loaders are FileSystemLoader(). + paths = [ + item + for loader in self.texenv.loader.loaders + for item in loader.searchpath + ] raise errors.TemplateError( exception, - """Template "{template}" not found.""".format( - template=exception.name + errors.notfound( + exception.name, + paths, + message='Template "{name}" not found in {paths}.' ), )