From d945277793ce23f047564b55f70a6ffad9ecdc54 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Tue, 10 Nov 2015 18:22:23 +0100 Subject: [PATCH] Move the DEFAULT_CONFIG --- patacrep/build.py | 10 +--------- patacrep/songs/__init__.py | 14 +++++++++++++- patacrep/songs/convert/__main__.py | 2 +- test/test_chordpro/test_parser.py | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index 0526d5c2..33a91eee 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -11,7 +11,7 @@ from subprocess import Popen, PIPE, call, check_call from patacrep import authors, content, errors, files from patacrep.index import process_sxd from patacrep.templates import TexBookRenderer -from patacrep.songs import DataSubpath +from patacrep.songs import DataSubpath, DEFAULT_CONFIG LOGGER = logging.getLogger(__name__) EOL = "\n" @@ -27,14 +27,6 @@ GENERATED_EXTENSIONS = [ "_title.sbx", "_title.sxd", ] -DEFAULT_CONFIG = { - 'template': "default.tex", - 'lang': 'en', - 'content': [], - 'titleprefixwords': [], - 'encoding': None, - 'datadir': [], - } diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 2b1a5768..d7619096 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -12,6 +12,15 @@ from patacrep.authors import process_listauthors LOGGER = logging.getLogger(__name__) +DEFAULT_CONFIG = { + 'template': "default.tex", + 'lang': 'en', + 'content': [], + 'titleprefixwords': [], + 'encoding': None, + 'datadir': [], + } + def cached_name(datadir, filename): """Return the filename of the cache version of the file.""" fullpath = os.path.abspath(os.path.join(datadir, '.cache', filename)) @@ -93,7 +102,10 @@ class Song: "_version", ] - def __init__(self, subpath, config, *, datadir=None): + def __init__(self, subpath, config=None, *, datadir=None): + if config is None: + config = DEFAULT_CONFIG.copy() + if datadir is None: self.datadir = "" # Only songs in datadirs may be cached diff --git a/patacrep/songs/convert/__main__.py b/patacrep/songs/convert/__main__.py index 90276f7b..19d7041e 100644 --- a/patacrep/songs/convert/__main__.py +++ b/patacrep/songs/convert/__main__.py @@ -8,7 +8,7 @@ import logging import sys from patacrep import files -from patacrep.build import DEFAULT_CONFIG +from patacrep.songs import DEFAULT_CONFIG from patacrep.utils import yesno LOGGER = logging.getLogger(__name__) diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index cd38afcd..a0b5a288 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -9,7 +9,7 @@ import unittest from pkg_resources import resource_filename from patacrep import files -from patacrep.build import DEFAULT_CONFIG +from patacrep.songs import DEFAULT_CONFIG from patacrep.encoding import open_read from .. import disable_logging