Browse Source

Function `compile_authwords()` no longer has side effects

Closes #185
pull/184/head
Louis 9 years ago
parent
commit
342ffe8919
  1. 22
      patacrep/authors.py
  2. 5
      patacrep/build.py

22
patacrep/authors.py

@ -5,8 +5,6 @@ import re
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
AUTHWORDS_KEYS = ["after", "ignore", "separators"]
RE_AFTER = r"^.*\b{}\b(.*)$" RE_AFTER = r"^.*\b{}\b(.*)$"
RE_SEPARATOR = r"^(.*)\b *{} *(\b.*)?$" RE_SEPARATOR = r"^(.*)\b *{} *(\b.*)?$"
@ -15,23 +13,17 @@ def compile_authwords(authwords):
This regexp will later be used to match these words in authors strings. This regexp will later be used to match these words in authors strings.
""" """
# Fill missing values return {
for key in AUTHWORDS_KEYS: 'ignore': authwords.get('ignore', []),
if key not in authwords: 'after': [
authwords[key] = []
# Compilation
authwords['after'] = [
re.compile(RE_AFTER.format(word), re.LOCALE) re.compile(RE_AFTER.format(word), re.LOCALE)
for word in authwords['after'] for word in authwords['after']
] ],
authwords['separators'] = [ 'separators': [
re.compile(RE_SEPARATOR.format(word), re.LOCALE) re.compile(RE_SEPARATOR.format(word), re.LOCALE)
for word in ([" %s" % word for word in authwords['separators']] + [',', ';']) for word in ([" %s" % word for word in authwords['separators']] + [',', ';'])
] ],
}
return authwords
def split_author_names(string): def split_author_names(string):
r"""Split author between first and last name. r"""Split author between first and last name.

5
patacrep/build.py

@ -1,7 +1,6 @@
"""Build a songbook, according to parameters found in a .sb file.""" """Build a songbook, according to parameters found in a .sb file."""
import codecs import codecs
import copy
import glob import glob
import logging import logging
import threading import threading
@ -85,9 +84,7 @@ class Songbook(object):
config['_template'] = renderer.get_all_variables(self.config.get('template', {})) config['_template'] = renderer.get_all_variables(self.config.get('template', {}))
config['_compiled_authwords'] = authors.compile_authwords( config['_compiled_authwords'] = authors.compile_authwords(config['authors'])
copy.deepcopy(config['authors'])
)
# Loading custom plugins # Loading custom plugins
config['_content_plugins'] = files.load_plugins( config['_content_plugins'] = files.load_plugins(

Loading…
Cancel
Save