From 7cc7d3bbdb40e3ad691dabd6e35c7ad9859c5809 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 24 Feb 2016 22:57:09 +0100 Subject: [PATCH 1/6] Do not raise error if the 'after' author word is not set --- patacrep/authors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/authors.py b/patacrep/authors.py index c8b65361..11d1df60 100644 --- a/patacrep/authors.py +++ b/patacrep/authors.py @@ -17,7 +17,7 @@ def compile_authwords(authwords): 'ignore': authwords.get('ignore', []), 'after': [ re.compile(RE_AFTER.format(word), re.LOCALE) - for word in authwords['after'] + for word in authwords.get('after') ], 'separators': [ re.compile(RE_SEPARATOR.format(word), re.LOCALE) From 33319b0b2589a302eb07df20b1e57b51d5ba4b15 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 25 Feb 2016 21:36:10 +0100 Subject: [PATCH 2/6] Initial setcounter plugin (not working) --- patacrep/content/setcounter.py | 48 ++++++++++++++++++++++++++ test/test_content/setcounter.control | 4 +++ test/test_content/setcounter.source | 7 ++++ test/test_content/test_content.py | 5 ++- test/test_songbook/content.tex.control | 3 ++ test/test_songbook/content.yaml | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 patacrep/content/setcounter.py create mode 100644 test/test_content/setcounter.control create mode 100644 test/test_content/setcounter.source diff --git a/patacrep/content/setcounter.py b/patacrep/content/setcounter.py new file mode 100755 index 00000000..41729b52 --- /dev/null +++ b/patacrep/content/setcounter.py @@ -0,0 +1,48 @@ +"""Allows to set an arbitrary value to any LaTeX counter (like `songnum`).""" + +from patacrep.content import ContentItem, ContentList, validate_parser_argument + +class CounterSetter(ContentItem): + """Set a counter.""" + # pylint: disable=too-few-public-methods + + def __init__(self, name, value): + self.name = name + self.value = value + + def render(self, __context): + """Set the value of the counter.""" + return r'\setcounter{{{}}}{{{}}}'.format(self.name, self.value) + +#pylint: disable=unused-argument +@validate_parser_argument(""" +type: //any +of: + - //nil + - //int + - type: //rec + optional: + name: //str + value: //int +""") +def parse(keyword, argument, config): + """Parse the counter setter. + + Arguments: + - nothing + reset the "songnum" counter to 1 + - an int + reset the "songnum" counter to this value + - a dict: + - name ("songnum"): the counter to set; + - value: value to set the counter to; + """ + if argument is None: + argument = {} + if isinstance(argument, int): + argument = {'value': argument} + name = argument.get('name', 'songnum') + value = argument.get('value', 1) + return ContentList([CounterSetter(name, value)]) + +CONTENT_PLUGINS = {'setcounter': parse} diff --git a/test/test_content/setcounter.control b/test/test_content/setcounter.control new file mode 100644 index 00000000..dff14be1 --- /dev/null +++ b/test/test_content/setcounter.control @@ -0,0 +1,4 @@ +- setcounter{songnum}{101} +- setcounter{songnum}{1} +- setcounter{songnum}{5} +- setcounter{counter_name}{-1} \ No newline at end of file diff --git a/test/test_content/setcounter.source b/test/test_content/setcounter.source new file mode 100644 index 00000000..d1987d66 --- /dev/null +++ b/test/test_content/setcounter.source @@ -0,0 +1,7 @@ +- setcounter: + value: 101 +- setcounter: +- setcounter: 5 +- setcounter: + name: counter_name + value: -1 diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index 221a3212..af6dec57 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -10,7 +10,7 @@ import yaml from pkg_resources import resource_filename from patacrep import content, files -from patacrep.content import song, section, songsection, tex +from patacrep.content import song, section, setcounter, songsection, tex from patacrep.songbook import prepare_songbook from .. import logging_reduced @@ -89,6 +89,9 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): elif isinstance(elem, tex.LaTeX): return files.path2posix(elem.filename) + elif isinstance(elem, setcounter.CounterSetter): + return elem.render(None)[1:] + else: raise Exception(elem) diff --git a/test/test_songbook/content.tex.control b/test/test_songbook/content.tex.control index 4120642f..a431c2db 100644 --- a/test/test_songbook/content.tex.control +++ b/test/test_songbook/content.tex.control @@ -122,6 +122,9 @@ guitar, \songsection{Test of song section} + +\setcounter{songnum}{101} + \begin{songs}{titleidx,authidx} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% content_datadir/content/song.csg diff --git a/test/test_songbook/content.yaml b/test/test_songbook/content.yaml index 15b06a91..2585a91f 100644 --- a/test/test_songbook/content.yaml +++ b/test/test_songbook/content.yaml @@ -11,6 +11,7 @@ content: - section: Test of section - sort: - songsection: Test of song section + - setcounter: 101 - cwd: # relative to yaml songfile path: content_datadir/content From f5afb56989e62a642a898a7e7257ef696d579f80 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Thu, 25 Feb 2016 21:37:48 +0100 Subject: [PATCH 3/6] [wip] Trick to manually prevent the songs package from resetting the counter --- patacrep/data/latex/songs.sty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/data/latex/songs.sty b/patacrep/data/latex/songs.sty index 4773d47c..c41f1bfb 100644 --- a/patacrep/data/latex/songs.sty +++ b/patacrep/data/latex/songs.sty @@ -2957,7 +2957,7 @@ \gdef\SB@indexlist{#1}% \SB@chkidxlst% \stepcounter{SB@songsnum}% - \setcounter{songnum}{1}% + %\setcounter{songnum}{1}% \let\SB@sgroup\@empty% \ifinner\else\ifdim\pagetotal>\z@% \null\nointerlineskip% From 522b0ed0d1d887765fe0f0f9f7e4fbb6f3f26199 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 27 Feb 2016 10:59:51 +0100 Subject: [PATCH 4/6] Override songs enviroonment to prevent number reset --- patacrep/data/latex/patacrep.sty | 17 +++++++++++++++++ patacrep/data/latex/songs.sty | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/patacrep/data/latex/patacrep.sty b/patacrep/data/latex/patacrep.sty index 3dc6c7bf..5ed071c2 100644 --- a/patacrep/data/latex/patacrep.sty +++ b/patacrep/data/latex/patacrep.sty @@ -443,4 +443,21 @@ \def\@void[#1]{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Prevent numbering reset on new 'songs' environment +\newcounter{tempsongnum} + +\let\oldsongs\songs +\let\endoldsongs\endsongs + +\renewenvironment{songs}[1]{% + \setcounter{tempsongnum}{\thesongnum}% + \oldsongs{#1}% + \setcounter{songnum}{\thetempsongnum}% +}{% + \endoldsongs\ignorespacesafterend% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \endinput diff --git a/patacrep/data/latex/songs.sty b/patacrep/data/latex/songs.sty index c41f1bfb..4773d47c 100644 --- a/patacrep/data/latex/songs.sty +++ b/patacrep/data/latex/songs.sty @@ -2957,7 +2957,7 @@ \gdef\SB@indexlist{#1}% \SB@chkidxlst% \stepcounter{SB@songsnum}% - %\setcounter{songnum}{1}% + \setcounter{songnum}{1}% \let\SB@sgroup\@empty% \ifinner\else\ifdim\pagetotal>\z@% \null\nointerlineskip% From 82ac39fd875176fe3a6d46f451a3b6977cd9b923 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Sat, 27 Feb 2016 11:09:31 +0100 Subject: [PATCH 5/6] Factorize content checking --- test/test_content/test_content.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index af6dec57..dbf6926a 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -76,22 +76,22 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): @classmethod def _clean_path(cls, elem): """Shorten the path relative to the `songs` directory""" - if isinstance(elem, song.SongRenderer): - songpath = os.path.join(os.path.dirname(__file__), 'datadir', 'songs') - return files.path2posix(files.relpath(elem.song.fullpath, songpath)) - elif isinstance(elem, section.Section): + latex_command_classes = ( + section.Section, + songsection.SongSection, + setcounter.CounterSetter, + ) + if isinstance(elem, latex_command_classes): return elem.render(None)[1:] - elif isinstance(elem, songsection.SongSection): - return elem.render(None)[1:] + elif isinstance(elem, song.SongRenderer): + songpath = os.path.join(os.path.dirname(__file__), 'datadir', 'songs') + return files.path2posix(files.relpath(elem.song.fullpath, songpath)) elif isinstance(elem, tex.LaTeX): return files.path2posix(elem.filename) - elif isinstance(elem, setcounter.CounterSetter): - return elem.render(None)[1:] - else: raise Exception(elem) From 68d33f401a7e5c02d4cceec71a0b8f2c0eb5e969 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Wed, 2 Mar 2016 07:37:56 +0100 Subject: [PATCH 6/6] Correct lyric option --- patacrep/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/templates.py b/patacrep/templates.py index 7c410c8a..90509369 100644 --- a/patacrep/templates.py +++ b/patacrep/templates.py @@ -275,7 +275,7 @@ def iter_bookoptions(config): if config['chords']['show']: yield 'chorded' else: - yield 'lyrics' + yield 'lyric' book_equivalents = { 'pictures': 'pictures',