Browse Source

Function `compile_authwords()` no longer has side effects

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

30
patacrep/authors.py

@ -5,8 +5,6 @@ import re
LOGGER = logging.getLogger(__name__)
AUTHWORDS_KEYS = ["after", "ignore", "separators"]
RE_AFTER = 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.
"""
# Fill missing values
for key in AUTHWORDS_KEYS:
if key not in authwords:
authwords[key] = []
# Compilation
authwords['after'] = [
re.compile(RE_AFTER.format(word), re.LOCALE)
for word in authwords['after']
]
authwords['separators'] = [
re.compile(RE_SEPARATOR.format(word), re.LOCALE)
for word in ([" %s" % word for word in authwords['separators']] + [',', ';'])
]
return authwords
return {
'ignore': authwords.get('ignore', []),
'after': [
re.compile(RE_AFTER.format(word), re.LOCALE)
for word in authwords['after']
],
'separators': [
re.compile(RE_SEPARATOR.format(word), re.LOCALE)
for word in ([" %s" % word for word in authwords['separators']] + [',', ';'])
],
}
def split_author_names(string):
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."""
import codecs
import copy
import glob
import logging
import threading
@ -85,9 +84,7 @@ class Songbook(object):
config['_template'] = renderer.get_all_variables(self.config.get('template', {}))
config['_compiled_authwords'] = authors.compile_authwords(
copy.deepcopy(config['authors'])
)
config['_compiled_authwords'] = authors.compile_authwords(config['authors'])
# Loading custom plugins
config['_content_plugins'] = files.load_plugins(

Loading…
Cancel
Save