Browse Source

Merge pull request #198 from patacrep/yaml_extension

Everything should now be in yaml
pull/193/head
Louis 9 years ago
parent
commit
cabfce843e
  1. 2
      README.rst
  2. 19
      examples/example-all.sb
  3. 3
      examples/example-all.yaml
  4. 22
      examples/example-crepbook.sb
  5. 24
      examples/example-crepbook.yaml
  6. 22
      examples/example-layout.sb
  7. 22
      examples/example-songs.sb
  8. 24
      examples/example-songs.yaml
  9. 14
      examples/example-test.sb
  10. 14
      examples/example-test.yaml
  11. 21
      examples/example.sb
  12. 23
      examples/example.yaml
  13. 24
      examples/example_encoding.sb
  14. 32
      examples/example_encoding.yaml
  15. 10
      patacrep/build.py
  16. 6
      patacrep/content/__init__.py
  17. 2
      patacrep/content/cwd.py
  18. 10
      patacrep/songbook/__main__.py
  19. 2
      test/test_content/test_content.py
  20. 2
      test/test_songbook/content.yaml
  21. 0
      test/test_songbook/datadir.yaml
  22. 0
      test/test_songbook/languages.yaml
  23. 0
      test/test_songbook/syntax.yaml
  24. 10
      test/test_songbook/test_compilation.py
  25. 0
      test/test_songbook/unicode.yaml

2
README.rst

@ -55,7 +55,7 @@ Run
::
songbook <songbook_file.sb>
songbook <songbook_file.yaml>
<pdfreader> <songbook_file.pdf>
Look for existing songbook files in `patadata <http://github.com/patacrep/patadata>`_.

19
examples/example-all.sb

@ -1,19 +0,0 @@
{
"bookoptions" : [
"diagram",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"datadir": ["datadir2"],
"template" : "patacrep.tex",
"lang" : "fr",
"encoding": "utf8",
"authwords" : {
"sep" : ["and", "et"]
},
"datadir" : ".",
"content": [["sort"]]
}

3
examples/example-all.yaml.sb → examples/example-all.yaml

@ -13,7 +13,8 @@ authors:
separators:
- "and"
- "et"
content: {"sort"}
content:
- sort:
template:
patacrep.tex:

22
examples/example-crepbook.sb

@ -1,22 +0,0 @@
{
"template" : "patacrep.tex",
"bookoptions" : [
"importantdiagramonly",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"lang" : "fr",
"authwords" : {
"sep" : ["and", "et"]
},
"datadir" : ".",
"content" : [["section", "Traditional"],
"chevaliers_de_la_table_ronde.sg",
"greensleeves.sg",
"vent_frais.sg",
["section", "Example"],
"example-fr.sg",
"example-en.sg"]
}

24
examples/example-crepbook.yaml

@ -0,0 +1,24 @@
book:
lang: fr
encoding: utf8
template: patacrep.tex
datadir: "."
pictures: yes
chords:
show: yes
diagramreminder: important
repeatchords: yes
lilypond: yes
authors:
separators:
- "and"
- "et"
content:
- section: "Traditional"
- "chevaliers_de_la_table_ronde.tsg"
- "greensleeves.csg"
- "vent_frais.tsg"
- section: Example
- "example-fr.tsg"
- "example-en.tsg"

22
examples/example-layout.sb

@ -1,22 +0,0 @@
{
"template" : "layout.tex",
"bookoptions" : [
"importantdiagramonly",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"lang" : "fr",
"authwords" : {
"sep" : ["and", "et"]
},
"datadir" : ".",
"content" : [["section", "Traditional"],
"chevaliers_de_la_table_ronde.sg",
"greensleeves.sg",
"vent_frais.sg",
["section", "Example"],
"example-fr.sg",
"example-en.sg"]
}

22
examples/example-songs.sb

@ -1,22 +0,0 @@
{
"template" : "songs.tex",
"bookoptions" : [
"importantdiagramonly",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"lang" : "fr",
"authwords" : {
"sep" : ["and", "et"]
},
"datadir" : ".",
"content" : [["section", "Traditional"],
"chevaliers_de_la_table_ronde.sg",
"greensleeves.sg",
"vent_frais.sg",
["section", "Example"],
"example-fr.sg",
"example-en.sg"]
}

24
examples/example-songs.yaml

@ -0,0 +1,24 @@
book:
lang: fr
encoding: utf8
template: songs.tex
datadir: "."
pictures: yes
chords:
show: yes
diagramreminder: important
repeatchords: yes
lilypond: yes
authors:
separators:
- "and"
- "et"
content:
- section: "Traditional"
- "chevaliers_de_la_table_ronde.tsg"
- "greensleeves.csg"
- "vent_frais.tsg"
- section: Example
- "example-fr.tsg"
- "example-en.tsg"

14
examples/example-test.sb

@ -1,14 +0,0 @@
{
"bookoptions" : [
"diagram",
"repeatchords",
"lilypond",
"pictures"
],
"lang": "ERROR",
"booktype" : "chorded",
"template" : "patacrep.tex",
"encoding": "utf8",
"content": ["tests/*.csg", "tests/*.tsg"]
}

14
examples/example-test.yaml

@ -0,0 +1,14 @@
book:
lang: ERROR
encoding: utf8
template: patacrep.tex
datadir: "."
pictures: yes
chords:
show: yes
diagramreminder: all
repeatchords: yes
content:
- "tests/*.csg"
- "tests/*.tsg"

21
examples/example.sb

@ -1,21 +0,0 @@
{
"bookoptions" : [
"importantdiagramonly",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"lang" : "fr",
"authwords" : {
"sep" : ["and", "et"]
},
"datadir" : ".",
"content" : [["section", "Traditional"],
"chevaliers_de_la_table_ronde.sg",
"greensleeves.sg",
"vent_frais.sg",
["section", "Example"],
"example-fr.sg",
"example-en.sg"]
}

23
examples/example.yaml

@ -0,0 +1,23 @@
book:
lang: fr
encoding: utf8
datadir: "."
pictures: yes
chords:
show: yes
diagramreminder: important
repeatchords: yes
lilypond: yes
authors:
separators:
- "and"
- "et"
content:
- section: "Traditional"
- "chevaliers_de_la_table_ronde.tsg"
- "greensleeves.csg"
- "vent_frais.tsg"
- section: Example
- "example-fr.tsg"
- "example-en.tsg"

24
examples/example_encoding.sb

@ -1,24 +0,0 @@
{
"bookoptions" : [
"importantdiagramonly",
"repeatchords",
"lilypond",
"pictures"
],
"booktype" : "chorded",
"lang" : "fr",
"authwords" : {
"sep" : ["and", "et", "À"],
"ignore" : ["À"],
"after" : ["À"]
},
"titleprefixwords": ["À"],
"datadir" : ".",
"content" : [["section", "Traditional"],
"chevaliers_de_la_table_ronde.sg",
"greensleeves.sg",
"vent_frais.sg",
["section", "Example"],
"example-fr.sg",
"example-en.sg"]
}

32
examples/example_encoding.yaml

@ -0,0 +1,32 @@
book:
lang: fr
encoding: utf8
datadir: "."
pictures: yes
chords:
show: yes
diagramreminder: important
repeatchords: yes
lilypond: yes
authors:
separators:
- "and"
- "et"
- "À"
ignore:
- "À"
after:
- "À"
titles: # Comment sont analysés les titres
prefix:
- "À"
content:
- section: "Traditionàl"
- "chevaliers_de_la_table_ronde.tsg"
- "greensleeves.csg"
- "vent_frais.tsg"
- section: Exâmple
- "example-fr.tsg"
- "example-en.tsg"

10
patacrep/build.py

@ -1,4 +1,4 @@
"""Build a songbook, according to parameters found in a .sb file."""
"""Build a songbook, according to parameters found in a .yaml file."""
import codecs
import copy
@ -34,10 +34,10 @@ GENERATED_EXTENSIONS = [
# pylint: disable=too-few-public-methods
class Songbook:
"""Represent a songbook (.sb) file.
"""Represent a songbook (.yaml) file.
- Low level: provide a Python representation of the values stored in the
'.sb' file.
'.yaml' file.
- High level: provide some utility functions to manipulate these data.
"""
@ -159,7 +159,7 @@ class Songbook:
def requires_lilypond(self):
"""Tell if lilypond is part of the bookoptions"""
return 'lilypond' in iter_bookoptions(self._config)
return 'lilypond' in iter_bookoptions(self._raw_config)
def _log_pipe(pipe):
"""Log content from `pipe`."""
@ -183,7 +183,7 @@ class SongbookBuilder:
_called_functions = {}
def __init__(self, raw_songbook, basename):
# Representation of the .sb songbook configuration file.
# Representation of the .yaml songbook configuration file.
self.songbook = Songbook(raw_songbook, basename)
# Basename of the songbook to be built.
self.basename = basename

6
patacrep/content/__init__.py

@ -1,7 +1,7 @@
"""Content plugin management.
Content that can be included in a songbook is controlled by plugins. From the
user (or .sb file) point of view, each piece of content is introduced by a
user (or .yaml file) point of view, each piece of content is introduced by a
keyword. This keywold is associated with a plugin (a submodule of this very
module), which parses the content, and return a ContentList object, which is
little more than a list of instances of the ContentItem class.
@ -14,7 +14,7 @@ dictionary where:
- keys are keywords,
- values are parsers (see below).
When analysing the content field of the .sb file, when those keywords are
When analysing the content field of the .yaml file, when those keywords are
met, the corresponding parser is called.
# Keyword examples
@ -252,7 +252,7 @@ def process_content(content, config=None):
"""Process content, and return a list of ContentItem() objects.
Arguments are:
- content: the content field of the .sb file, which should be a nested list
- content: the content field of the .yaml file, which should be a nested list
and describe what is to be included in the songbook;
- config: the configuration dictionary of the current songbook.

2
patacrep/content/cwd.py

@ -28,7 +28,7 @@ def parse(keyword, config, argument):
for, and then processes the content.
The 'path' is added:
- first as a relative path to the *.sb file directory;
- first as a relative path to the *.yaml file directory;
- then as a relative path to every path already present in
config['songdir'].
"""

10
patacrep/songbook/__main__.py

@ -128,19 +128,19 @@ def main():
options = argument_parser(sys.argv[1:])
songbook_path = options.book[-1]
if os.path.exists(songbook_path + ".sb") and not os.path.exists(songbook_path):
songbook_path += ".sb"
if os.path.exists(songbook_path + ".yaml") and not os.path.exists(songbook_path):
songbook_path += ".yaml"
basename = os.path.basename(songbook_path)[:-3]
basename = os.path.basename(songbook_path)[:-len(".yaml")]
# Load the user songbook config
try:
with patacrep.encoding.open_read(songbook_path) as songbook_file:
user_songbook = yaml.load(songbook_file)
if 'encoding' in user_songbook:
if 'encoding' in user_songbook.get('book', []):
with patacrep.encoding.open_read(
songbook_path,
encoding=user_songbook['encoding']
encoding=user_songbook['book']['encoding']
) as songbook_file:
user_songbook = yaml.load(songbook_file)
except Exception as error: # pylint: disable=broad-except

2
test/test_content/test_content.py

@ -21,7 +21,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test of the content plugins.
For any given `foo.source`, it parses the content as a yaml "content"
argument of a .sb file.
argument of a .yaml file.
It controls that the generated file list is equal to the one in `foo.control`.
"""

2
test/test_songbook/content.sb → test/test_songbook/content.yaml

@ -12,7 +12,7 @@ content:
- sort:
- songsection: Test of song section
- cwd:
# relative to sb file
# relative to yaml songfile
path: content_datadir/content
content:
- "song.csg"

0
test/test_songbook/datadir.sb → test/test_songbook/datadir.yaml

0
test/test_songbook/languages.sb → test/test_songbook/languages.yaml

0
test/test_songbook/syntax.sb → test/test_songbook/syntax.yaml

10
test/test_songbook/test_compilation.py

@ -18,7 +18,7 @@ LOGGER = logging.getLogger(__name__)
class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Test of songbook compilation.
For any given `foo.sb`, it performs several checks:
For any given `foo.yaml`, it performs several checks:
- the corresponding tex file is generated;
- the generated tex file matches the `foo.tex.control` control file;
- the compilation (tex, pdf, indexes) works without errors.
@ -34,9 +34,9 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
"""Iterate over dynamically generated test methods."""
for songbook in sorted(glob.glob(os.path.join(
os.path.dirname(__file__),
'*.sb',
'*.yaml',
))):
base = songbook[:-len(".sb")]
base = songbook[:-len(".yaml")]
yield (
"test_latex_generation_{}".format(os.path.basename(base)),
cls._create_generation_test(base),
@ -52,7 +52,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
def test_generation(self):
"""Test that `base.tex` is correctly generated."""
songbook = "{}.sb".format(base)
songbook = "{}.yaml".format(base)
# Check tex generation
self.assertEqual(0, self.compile_songbook(songbook, "tex"))
@ -100,7 +100,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
def test_compilation(self):
"""Test that `base` is rendered to pdf."""
# Check compilation
songbook = "{}.sb".format(base)
songbook = "{}.yaml".format(base)
self.assertEqual(0, self.compile_songbook(songbook))
test_compilation.__doc__ = (

0
test/test_songbook/unicode.sb → test/test_songbook/unicode.yaml

Loading…
Cancel
Save