Browse Source

Merge branch 'master' into useless_arguments

pull/147/head
Louis 9 years ago
parent
commit
b3e9d04597
  1. 50
      .appveyor.yml
  2. 2
      examples/songs/chevaliers_de_la_table_ronde.sg
  3. 2
      examples/songs/example-en.sg
  4. 2
      examples/songs/example-fr.sg
  5. 2
      examples/songs/greensleeves.sg
  6. 2
      examples/songs/vent_frais.sg
  7. 3
      patacrep/__init__.py
  8. 20
      patacrep/build.py
  9. 2
      patacrep/content/song.py
  10. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_chord
  11. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_chordlist
  12. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_comment
  13. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_define
  14. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_endofline
  15. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_error
  16. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment
  17. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_image
  18. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_line
  19. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_newline
  20. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_partition
  21. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_space
  22. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_tablature
  23. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_verse
  24. 0
      patacrep/data/ast_templates/chordpro/chordpro/content_word
  25. 0
      patacrep/data/ast_templates/chordpro/chordpro/song
  26. 0
      patacrep/data/ast_templates/chordpro/chordpro/song_body
  27. 14
      patacrep/data/ast_templates/chordpro/chordpro/song_header
  28. 0
      patacrep/data/ast_templates/chordpro/html/content_chord
  29. 0
      patacrep/data/ast_templates/chordpro/html/content_chordlist
  30. 0
      patacrep/data/ast_templates/chordpro/html/content_comment
  31. 0
      patacrep/data/ast_templates/chordpro/html/content_define
  32. 0
      patacrep/data/ast_templates/chordpro/html/content_define_list
  33. 0
      patacrep/data/ast_templates/chordpro/html/content_endofline
  34. 0
      patacrep/data/ast_templates/chordpro/html/content_error
  35. 0
      patacrep/data/ast_templates/chordpro/html/content_guitar_comment
  36. 0
      patacrep/data/ast_templates/chordpro/html/content_image
  37. 0
      patacrep/data/ast_templates/chordpro/html/content_line
  38. 0
      patacrep/data/ast_templates/chordpro/html/content_metadata_cover
  39. 0
      patacrep/data/ast_templates/chordpro/html/content_newline
  40. 0
      patacrep/data/ast_templates/chordpro/html/content_partition
  41. 0
      patacrep/data/ast_templates/chordpro/html/content_space
  42. 0
      patacrep/data/ast_templates/chordpro/html/content_tablature
  43. 0
      patacrep/data/ast_templates/chordpro/html/content_verse
  44. 0
      patacrep/data/ast_templates/chordpro/html/content_word
  45. 0
      patacrep/data/ast_templates/chordpro/html/song
  46. 0
      patacrep/data/ast_templates/chordpro/html/song_body
  47. 0
      patacrep/data/ast_templates/chordpro/html/song_header
  48. 0
      patacrep/data/ast_templates/chordpro/latex/content_chord
  49. 0
      patacrep/data/ast_templates/chordpro/latex/content_chordlist
  50. 0
      patacrep/data/ast_templates/chordpro/latex/content_comment
  51. 0
      patacrep/data/ast_templates/chordpro/latex/content_define
  52. 0
      patacrep/data/ast_templates/chordpro/latex/content_endofline
  53. 0
      patacrep/data/ast_templates/chordpro/latex/content_error
  54. 0
      patacrep/data/ast_templates/chordpro/latex/content_guitar_comment
  55. 2
      patacrep/data/ast_templates/chordpro/latex/content_image
  56. 0
      patacrep/data/ast_templates/chordpro/latex/content_line
  57. 0
      patacrep/data/ast_templates/chordpro/latex/content_newline
  58. 6
      patacrep/data/ast_templates/chordpro/latex/content_partition
  59. 0
      patacrep/data/ast_templates/chordpro/latex/content_space
  60. 0
      patacrep/data/ast_templates/chordpro/latex/content_tablature
  61. 0
      patacrep/data/ast_templates/chordpro/latex/content_verse
  62. 0
      patacrep/data/ast_templates/chordpro/latex/content_word
  63. 14
      patacrep/data/ast_templates/chordpro/latex/song
  64. 0
      patacrep/data/ast_templates/chordpro/latex/song_body
  65. 2
      patacrep/data/latex/patacrep.sty
  66. 12
      patacrep/errors.py
  67. 0
      patacrep/songbook/__init__.py
  68. 15
      patacrep/songs/chordpro/__init__.py
  69. 31
      patacrep/songs/chordpro/ast.py
  70. 6
      patacrep/songs/chordpro/data/latex/content_partition
  71. 7
      setup.py
  72. 2
      test/test_chordpro/greensleeves.sgc
  73. 2
      test/test_chordpro/greensleeves.tex
  74. 1
      test/test_chordpro/invalid_directive.sgc
  75. 2
      test/test_chordpro/invalid_directive.source
  76. 10
      test/test_chordpro/invalid_directive.tex
  77. 2
      test/test_chordpro/metadata.sgc
  78. 2
      test/test_chordpro/metadata.tex
  79. 5
      test/test_chordpro/tags.sgc
  80. 4
      test/test_chordpro/tags.source
  81. 10
      test/test_chordpro/tags.tex
  82. 8
      test/test_compilation/datadir.tex.control
  83. 2
      test/test_compilation/datadir_datadir/songs/datadir.sg
  84. 2
      test/test_compilation/datadir_datadir/songs/datadir2.sg
  85. 2
      test/test_compilation/datadir_datadir/songs/relative.sg
  86. 2
      test/test_compilation/datadir_datadir/songs/subdir/subdir.sg
  87. 18
      test/test_compilation/test_compilation.py
  88. 18
      texlive_packages.txt
  89. 2
      tox.ini

50
.appveyor.yml

@ -0,0 +1,50 @@
environment:
matrix:
- PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.x" # currently 3.4.3
PYTHON_ARCH: "32"
install:
# Download setup scripts and unzip
- ps: "wget https://github.com/cloudify-cosmo/appveyor-utils/archive/master.zip -OutFile ./master.zip"
- "7z e master.zip */appveyor/* -oappveyor"
# Install Python (from the official .msi of http://python.org) and pip when
# not already installed.
- "powershell ./appveyor/install.ps1"
# Prepend newly installed Python to the PATH of this build (this cannot be
# done from inside the powershell script as it would require to restart
# the parent CMD process).
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
# Check that we have the expected version and architecture for Python
- "python --version"
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
# Download miktex portable (if not cached)
- ps: "If (!(Test-Path miktex-portable.exe)){wget http://mirrors.ctan.org/systems/win32/miktex/setup/miktex-portable-2.9.5719.exe -OutFile ./miktex-portable.exe}"
# Unzip miktex portable
- "7z x miktex-portable.exe * -aot -omiktex > nul"
# Let the binaries be directly callable
- cmd: set PATH=%PATH%;C:\projects\patacrep\miktex\miktex\bin
# Update fonts
- cmd: luaotfload-tool.exe --update
# Manually install required texlive packages
- cmd: mpm.exe --install-some texlive_packages.txt
build: false # Not a C# project, build stuff at the test step instead.
before_test:
- "pip install tox"
test_script:
- "tox"
# Cache Miktex Portable file
cache:
- C:\projects\patacrep\miktex-portable.exe

2
examples/songs/chevaliers_de_la_table_ronde.sg

@ -1,7 +1,7 @@
\selectlanguage{french}
\songcolumns{2}
\beginsong{Chevaliers de la table ronde}
[by={Traditionnel},cov={traditionnel},album={France}]
[by={Traditionnel},cover={traditionnel},album={France}]
\cover
\gtab{C}{X32010}

2
examples/songs/example-en.sg

@ -24,7 +24,7 @@
% traditionnel : the file "8-bit-lagerfeuer.jpg" that corresponds to the album art
% 8 bit lagerfeuer : the album whose song is extracted from
\beginsong{Sad robot}
[by={Pornophonique},cov={traditionnel},album={8 bit lagerfeuer}]
[by={Pornophonique},cover={traditionnel},album={8 bit lagerfeuer}]
% inserts the album art (8-bit-lagerfeuer.jpg)
\cover

2
examples/songs/example-fr.sg

@ -26,7 +26,7 @@
% traditionnel : le fichier "8-bit-lagerfeuer.jpg" correspondant à la pochette de l'album
% 8 bit lagerfeuer : le nom de l'album dont la chanson est extraite
\beginsong{Sad robot}
[by={Pornophonique},cov={traditionnel},album={8 bit lagerfeuer}]
[by={Pornophonique},cover={traditionnel},album={8 bit lagerfeuer}]
% insère la pochette de l'album (8-bit-lagerfeuer.jpg)
\cover

2
examples/songs/greensleeves.sg

@ -1,7 +1,7 @@
\selectlanguage{english}
\songcolumns{2}
\beginsong{Greensleeves}
[by={Traditionnel},cov={traditionnel},album={Angleterre}]
[by={Traditionnel},cover={traditionnel},album={Angleterre}]
\cover
\gtab{Am}{X02210}

2
examples/songs/vent_frais.sg

@ -1,7 +1,7 @@
\selectlanguage{french}
\songcolumns{2}
\beginsong{Vent frais}
[by={Traditionnel},cov={traditionnel},album={France}]
[by={Traditionnel},cover={traditionnel},album={France}]
\cover
\gtab{Dm}{XX0231}

3
patacrep/__init__.py

@ -17,3 +17,6 @@ __version__ = '.'.join([str(number) for number in __TUPLE_VERSION__])
# etc.)
__DATADIR__ = os.path.abspath(resource_filename(__name__, 'data'))
def pkg_datapath(*path):
"""Return the package data path"""
return os.path.join(__DATADIR__, *path)

20
patacrep/build.py

@ -6,7 +6,7 @@ import glob
import logging
import threading
import os.path
from subprocess import Popen, PIPE, call
from subprocess import Popen, PIPE, call, check_call
from patacrep import __DATADIR__, authors, content, errors, files
from patacrep.index import process_sxd
@ -213,13 +213,27 @@ class SongbookBuilder(object):
LOGGER.info("Building '{}.pdf'".format(self.basename))
self._run_once(self._set_latex)
compiler = "lualatex"
# Test if the LaTeX compiler is accessible
try:
check_call(
[compiler, "--version"],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
universal_newlines=True,
)
except Exception as error:
raise errors.ExecutableNotFound(compiler)
# Perform compilation
try:
process = Popen(
["lualatex"] + self._lualatex_options + [self.basename],
[compiler] + self._lualatex_options + [self.basename],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
env=os.environ,
universal_newlines=True,
)
except Exception as error:

2
patacrep/content/song.py

@ -42,7 +42,7 @@ class SongRenderer(Content):
{song}
""").format(
separator="%"*80,
path=self.song.subpath,
path=files.path2posix(self.song.subpath),
song=self.song.render(output=context['filename']),
)

0
patacrep/songs/chordpro/data/chordpro/content_chord → patacrep/data/ast_templates/chordpro/chordpro/content_chord

0
patacrep/songs/chordpro/data/chordpro/content_chordlist → patacrep/data/ast_templates/chordpro/chordpro/content_chordlist

0
patacrep/songs/chordpro/data/chordpro/content_comment → patacrep/data/ast_templates/chordpro/chordpro/content_comment

0
patacrep/songs/chordpro/data/chordpro/content_define → patacrep/data/ast_templates/chordpro/chordpro/content_define

0
patacrep/songs/chordpro/data/chordpro/content_endofline → patacrep/data/ast_templates/chordpro/chordpro/content_endofline

0
patacrep/songs/chordpro/data/chordpro/content_error → patacrep/data/ast_templates/chordpro/chordpro/content_error

0
patacrep/songs/chordpro/data/chordpro/content_guitar_comment → patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment

0
patacrep/songs/chordpro/data/chordpro/content_image → patacrep/data/ast_templates/chordpro/chordpro/content_image

0
patacrep/songs/chordpro/data/chordpro/content_line → patacrep/data/ast_templates/chordpro/chordpro/content_line

0
patacrep/songs/chordpro/data/chordpro/content_newline → patacrep/data/ast_templates/chordpro/chordpro/content_newline

0
patacrep/songs/chordpro/data/chordpro/content_partition → patacrep/data/ast_templates/chordpro/chordpro/content_partition

0
patacrep/songs/chordpro/data/chordpro/content_space → patacrep/data/ast_templates/chordpro/chordpro/content_space

0
patacrep/songs/chordpro/data/chordpro/content_tablature → patacrep/data/ast_templates/chordpro/chordpro/content_tablature

0
patacrep/songs/chordpro/data/chordpro/content_verse → patacrep/data/ast_templates/chordpro/chordpro/content_verse

0
patacrep/songs/chordpro/data/chordpro/content_word → patacrep/data/ast_templates/chordpro/chordpro/content_word

0
patacrep/songs/chordpro/data/chordpro/song → patacrep/data/ast_templates/chordpro/chordpro/song

0
patacrep/songs/chordpro/data/chordpro/song_body → patacrep/data/ast_templates/chordpro/chordpro/song_body

14
patacrep/songs/chordpro/data/chordpro/song_header → patacrep/data/ast_templates/chordpro/chordpro/song_header

@ -14,16 +14,20 @@
(*- for author in authors -*)
{artist: (( author[1] )) (( author[0] ))}
(* endfor *)
(* endfor -*)
(*- for key in ['album', 'copyright', 'tag'] *)
(*- for key in ['album', 'copyright'] *)
(* if key in metadata -*)
{(( key )): (( metadata[key] ))}
(* endif *)
(* endfor *)
(* if 'cov' in metadata -*)
{(( 'cov' )): (( metadata['cov'].argument|search_image ))}
(* endif *)
(* if 'cover' in metadata -*)
{(( 'cover' )): (( metadata['cover'].argument|search_image ))}
(* endif -*)
(* for tag in metadata.get("tag", [])|sortargs -*)
{tag: (( tag.argument ))}
(* endfor -*)
(*- for key in metadata.morekeys -*)
{key: (( key.keyword )): (( key.argument ))}

0
patacrep/songs/chordpro/data/html/content_chord → patacrep/data/ast_templates/chordpro/html/content_chord

0
patacrep/songs/chordpro/data/html/content_chordlist → patacrep/data/ast_templates/chordpro/html/content_chordlist

0
patacrep/songs/chordpro/data/html/content_comment → patacrep/data/ast_templates/chordpro/html/content_comment

0
patacrep/songs/chordpro/data/html/content_define → patacrep/data/ast_templates/chordpro/html/content_define

0
patacrep/songs/chordpro/data/html/content_define_list → patacrep/data/ast_templates/chordpro/html/content_define_list

0
patacrep/songs/chordpro/data/html/content_endofline → patacrep/data/ast_templates/chordpro/html/content_endofline

0
patacrep/songs/chordpro/data/html/content_error → patacrep/data/ast_templates/chordpro/html/content_error

0
patacrep/songs/chordpro/data/html/content_guitar_comment → patacrep/data/ast_templates/chordpro/html/content_guitar_comment

0
patacrep/songs/chordpro/data/html/content_image → patacrep/data/ast_templates/chordpro/html/content_image

0
patacrep/songs/chordpro/data/html/content_line → patacrep/data/ast_templates/chordpro/html/content_line

0
patacrep/songs/chordpro/data/html/content_metadata_cover → patacrep/data/ast_templates/chordpro/html/content_metadata_cover

0
patacrep/songs/chordpro/data/html/content_newline → patacrep/data/ast_templates/chordpro/html/content_newline

0
patacrep/songs/chordpro/data/html/content_partition → patacrep/data/ast_templates/chordpro/html/content_partition

0
patacrep/songs/chordpro/data/html/content_space → patacrep/data/ast_templates/chordpro/html/content_space

0
patacrep/songs/chordpro/data/html/content_tablature → patacrep/data/ast_templates/chordpro/html/content_tablature

0
patacrep/songs/chordpro/data/html/content_verse → patacrep/data/ast_templates/chordpro/html/content_verse

0
patacrep/songs/chordpro/data/html/content_word → patacrep/data/ast_templates/chordpro/html/content_word

0
patacrep/songs/chordpro/data/html/song → patacrep/data/ast_templates/chordpro/html/song

0
patacrep/songs/chordpro/data/html/song_body → patacrep/data/ast_templates/chordpro/html/song_body

0
patacrep/songs/chordpro/data/html/song_header → patacrep/data/ast_templates/chordpro/html/song_header

0
patacrep/songs/chordpro/data/latex/content_chord → patacrep/data/ast_templates/chordpro/latex/content_chord

0
patacrep/songs/chordpro/data/latex/content_chordlist → patacrep/data/ast_templates/chordpro/latex/content_chordlist

0
patacrep/songs/chordpro/data/latex/content_comment → patacrep/data/ast_templates/chordpro/latex/content_comment

0
patacrep/songs/chordpro/data/latex/content_define → patacrep/data/ast_templates/chordpro/latex/content_define

0
patacrep/songs/chordpro/data/latex/content_endofline → patacrep/data/ast_templates/chordpro/latex/content_endofline

0
patacrep/songs/chordpro/data/latex/content_error → patacrep/data/ast_templates/chordpro/latex/content_error

0
patacrep/songs/chordpro/data/latex/content_guitar_comment → patacrep/data/ast_templates/chordpro/latex/content_guitar_comment

2
patacrep/songs/chordpro/data/latex/content_image → patacrep/data/ast_templates/chordpro/latex/content_image

@ -1,5 +1,5 @@
(* block image *)
(* set image = content.argument|search_image *)
(* set image = content.argument|search_image|path2posix *)
(* if image *)
\image{(( image ))}
(*- endif *)

0
patacrep/songs/chordpro/data/latex/content_line → patacrep/data/ast_templates/chordpro/latex/content_line

0
patacrep/songs/chordpro/data/latex/content_newline → patacrep/data/ast_templates/chordpro/latex/content_newline

6
patacrep/data/ast_templates/chordpro/latex/content_partition

@ -0,0 +1,6 @@
(* block partition *)
(* set partition = content.argument|search_partition|path2posix *)
(* if partition *)
\lilypond{ ((- partition -)) }
(*- endif -*)
(*- endblock -*)

0
patacrep/songs/chordpro/data/latex/content_space → patacrep/data/ast_templates/chordpro/latex/content_space

0
patacrep/songs/chordpro/data/latex/content_tablature → patacrep/data/ast_templates/chordpro/latex/content_tablature

0
patacrep/songs/chordpro/data/latex/content_verse → patacrep/data/ast_templates/chordpro/latex/content_verse

0
patacrep/songs/chordpro/data/latex/content_word → patacrep/data/ast_templates/chordpro/latex/content_word

14
patacrep/songs/chordpro/data/latex/song → patacrep/data/ast_templates/chordpro/latex/song

@ -22,16 +22,16 @@
(* endif *)
(* endfor *)
},
(* for key in ['album', 'copyright', 'tag'] *)
(* for key in ['album', 'copyright'] *)
(* if key in metadata *)
(( key ))={(( metadata[key] ))},
(* endif *)
(* endfor *)
(* if 'cov' in metadata *)
(* block cov *)
(* set cov = metadata["cov"].argument|search_image *)
(* if cov *)
cov={(( cov ))},
(* if 'cover' in metadata *)
(* block cover *)
(* set cover = metadata["cover"].argument|search_image|path2posix *)
(* if cover *)
cover={(( cover ))},
(* endif *)
(* endblock *)
(* endif *)
@ -40,7 +40,7 @@
(* endfor *)
]
(* if (metadata.cov is defined) *)
(* if (metadata.cover is defined) *)
\cover
(* endif *)

0
patacrep/songs/chordpro/data/latex/song_body → patacrep/data/ast_templates/chordpro/latex/song_body

2
patacrep/data/latex/patacrep.sty

@ -139,7 +139,7 @@
\setlength{\coverspace}{0.1cm}
\newcommand{\songcover}{}
\newcommand{\songalbum}{}
\newsongkey{cov}{\let\songcover\@empty}{\def\songcover{#1}}
\newsongkey{cover}{\let\songcover\@empty}{\def\songcover{#1}}
\newsongkey{album}{\let\songalbum\@empty}{\def\songalbum{#1}}
\newsongkey{url}{\let\songurl\@empty}{\def\songurl{#1}}
\newsongkey{original}{\let\songoriginal\@empty}{\def\songoriginal{#1}}

12
patacrep/errors.py

@ -31,6 +31,16 @@ class TemplateError(SongbookError):
else:
return self.message
class ExecutableNotFound(SongbookError):
"""Couldn't find a LaTeX executable."""
def __init__(self, executable):
super(ExecutableNotFound, self).__init__(
(
"""Could not find the following executable: {executable}"""
).format(executable=executable)
)
class StepError(SongbookError):
"""Error during execution of one compilation step."""
@ -47,7 +57,7 @@ class LatexCompilationError(StepError):
def __init__(self, basename):
super(LatexCompilationError, self).__init__(
(
"""Error while pdfLaTeX compilation of "{basename}.tex" """
"""Error while LaTeX compilation of "{basename}.tex" """
"""(see {basename}.log for more information)."""
).format(basename=basename)
)

0
patacrep/songbook/__init__.py

15
patacrep/songs/chordpro/__init__.py

@ -3,17 +3,22 @@
from jinja2 import Environment, FileSystemLoader, contextfunction, ChoiceLoader
import jinja2
import logging
import operator
import os
from pkg_resources import resource_filename
from patacrep import encoding, files
from patacrep import encoding, files, pkg_datapath
from patacrep.songs import Song
from patacrep.songs.chordpro.syntax import parse_song
from patacrep.templates import Renderer
from patacrep.latex import lang2babel
from patacrep.files import path2posix
LOGGER = logging.getLogger(__name__)
def sort_directive_argument(directives):
"""Sort directives by their argument."""
return sorted(directives, key=operator.attrgetter("argument"))
class ChordproSong(Song):
"""Chordpro song parser"""
# pylint: disable=abstract-method
@ -26,7 +31,7 @@ class ChordproSong(Song):
song = parse_song(song.read(), self.fullpath)
self.authors = song.authors
self.titles = song.titles
self.lang = song.get_data_argument('lang', self.config['lang'])
self.lang = song.get_data_argument('language', self.config['lang'])
self.data = song.meta
self.cached = {
'song': song,
@ -48,12 +53,14 @@ class ChordproSong(Song):
self.get_datadirs(os.path.join("templates", self.output_language))
),
FileSystemLoader(
os.path.join(resource_filename(__name__, 'data'), self.output_language)
pkg_datapath('ast_templates', 'chordpro', self.output_language)
),
]))
jinjaenv.filters['search_image'] = self.search_image
jinjaenv.filters['search_partition'] = self.search_partition
jinjaenv.filters['lang2babel'] = lang2babel
jinjaenv.filters['sortargs'] = sort_directive_argument
jinjaenv.filters['path2posix'] = path2posix
try:
return Renderer(

31
patacrep/songs/chordpro/ast.py

@ -11,6 +11,27 @@ def _indent(string):
"""Return and indented version of argument."""
return "\n".join([" {}".format(line) for line in string.split('\n')])
#: Available directives, that is, directives that we know how to deal with
AVAILABLE_DIRECTIVES = [
"album",
"artist",
"capo",
"comment",
"copyright",
"columns",
"cov",
"define",
"guitar_comment",
"image",
"key",
"language",
"newline",
"partition",
"subtitle",
"tag",
"title",
]
#: List of properties that are to be displayed in the flow of the song (not as
#: metadata at the beginning or end of song.
INLINE_DIRECTIVES = {
@ -30,8 +51,8 @@ DIRECTIVE_SHORTCUTS = {
"by": "artist",
"c": "comment",
"gc": "guitar_comment",
"cover": "cov",
"language": "lang",
"cov": "cover",
"lang": "language",
}
def directive_name(text):
@ -194,6 +215,7 @@ class Song(AST):
"artist": "add_author",
"key": "add_key",
"define": "add_cumulative",
"tag": "add_cumulative",
}
def __init__(self, filename):
@ -207,6 +229,7 @@ class Song(AST):
def add(self, data):
"""Add an element to the song"""
# pylint: disable=too-many-branches
if isinstance(data, Error):
pass
elif data is None:
@ -221,6 +244,8 @@ class Song(AST):
self.content[0].prepend(data.strip())
elif isinstance(data, Directive) and data.inline:
# Add a directive in the content of the song.
# It is useless to check if directive is in AVAILABLE_DIRECTIVES,
# since it is in INLINE_DIRECTIVES.
self.content.append(data)
elif data.inline:
# Add an object in the content of the song.
@ -228,6 +253,8 @@ class Song(AST):
elif isinstance(data, Directive):
# Add a metadata directive. Some of them are added using special
# methods listed in ``METADATA_ADD``.
if data.keyword not in AVAILABLE_DIRECTIVES:
LOGGER.warning("Ignoring unknown directive '{}'.".format(data.keyword))
if data.keyword in self.METADATA_ADD:
getattr(self, self.METADATA_ADD[data.keyword])(data)
else:

6
patacrep/songs/chordpro/data/latex/content_partition

@ -1,6 +0,0 @@
(* block partition *)
(* set partition = content.argument|search_partition *)
(* if partition *)
\lilypond{ ((- content.argument|search_partition -)) }
(*- endif -*)
(*- endblock -*)

7
setup.py

@ -21,7 +21,12 @@ setup(
"unidecode", "jinja2", "chardet", "ply",
],
setup_requires=["hgtools"],
include_package_data=True,
package_data={'patacrep': [
'data/ast_templates/*/*/*',
'data/img/*',
'data/latex/*',
'data/templates/*',
]},
entry_points={
'console_scripts': [
"songbook = patacrep.songbook.__main__:main",

2
test/test_chordpro/greensleeves.sgc

@ -5,7 +5,7 @@
{title: Un sous titre}
{artist: Traditionnel}
{album: Angleterre}
{cov: traditionnel}
{cover: traditionnel}
{partition: greensleeves.ly}

2
test/test_chordpro/greensleeves.tex

@ -7,7 +7,7 @@ Un sous titre}[
by={
Traditionnel },
album={Angleterre},
cov={img/traditionnel},
cover={img/traditionnel},
]
\cover

1
test/test_chordpro/invalid_directive.sgc

@ -0,0 +1 @@
{lang: en}

2
test/test_chordpro/invalid_directive.source

@ -0,0 +1,2 @@
{foo: bar}
{bar}

10
test/test_chordpro/invalid_directive.tex

@ -0,0 +1,10 @@
\selectlanguage{english}
\beginsong{}[
by={
},
]
\endsong

2
test/test_chordpro/metadata.sgc

@ -10,7 +10,7 @@
{artist: Texte de Jean Richepin, chanté par Georges Brassens}
{album: Album}
{copyright: Copyright}
{cov: metadata_cover}
{cover: metadata_cover}
{key: foo: Foo}
{comment: Comment}

2
test/test_chordpro/metadata.tex

@ -11,7 +11,7 @@ Subtitle5}[
Texte de Jean Richepin, chanté par Georges Brassens },
album={Album},
copyright={Copyright},
cov={img/test/test_chordpro/metadata_cover},
cover={img/test/test_chordpro/metadata_cover},
foo={Foo},
]

5
test/test_chordpro/tags.sgc

@ -0,0 +1,5 @@
{lang: en}
{title: Tag test}
{tag: a third tag}
{tag: another}
{tag: one tag}

4
test/test_chordpro/tags.source

@ -0,0 +1,4 @@
{title: Tag test}
{tag: one tag}
{tag: another}
{tag: a third tag}

10
test/test_chordpro/tags.tex

@ -0,0 +1,10 @@
\selectlanguage{english}
\beginsong{Tag test}[
by={
},
]
\endsong

8
test/test_compilation/datadir.tex.control

@ -103,7 +103,7 @@ guitar,
Chordpro}[
by={
},
cov={img/datadir.png},
cover={img/datadir.png},
]
\cover
@ -130,7 +130,7 @@ Chordpro}[
Chordpro}[
by={
},
cov={img/datadir2.png},
cover={img/datadir2.png},
]
\cover
@ -157,7 +157,7 @@ Chordpro}[
Chordpro}[
by={
},
cov={@TEST_FOLDER@/datadir_datadir/songs/./relative.png},
cover={@TEST_FOLDER@/datadir_datadir/songs/./relative.png},
]
\cover
@ -184,7 +184,7 @@ Chordpro}[
Chordpro}[
by={
},
cov={@TEST_FOLDER@/datadir_datadir/songs/./subdir/subdir.png},
cover={@TEST_FOLDER@/datadir_datadir/songs/./subdir/subdir.png},
]
\cover

2
test/test_compilation/datadir_datadir/songs/datadir.sg

@ -1,5 +1,5 @@
\beginsong{Image included from datadir\\\LaTeX}
[cov={img/datadir}]
[cover={img/datadir}]
\cover

2
test/test_compilation/datadir_datadir/songs/datadir2.sg

@ -1,5 +1,5 @@
\beginsong{Image included from a different datadir\\\LaTeX}
[cov={img/datadir2}]
[cover={img/datadir2}]
\cover

2
test/test_compilation/datadir_datadir/songs/relative.sg

@ -1,5 +1,5 @@
\beginsong{Image included from song directory\\\LaTeX}
[cov={relative}]
[cover={relative}]
\cover

2
test/test_compilation/datadir_datadir/songs/subdir/subdir.sg

@ -1,5 +1,5 @@
\beginsong{Image included from a nested song directory\\\LaTeX}
[cov={subdir}]
[cover={subdir}]
\cover

18
test/test_compilation/test_compilation.py

@ -5,10 +5,12 @@
import glob
import logging
import os
import sys
import subprocess
import unittest
from patacrep.encoding import open_read
from patacrep.files import path2posix
from .. import dynamic # pylint: disable=unused-import
@ -67,16 +69,18 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
expected = expectfile.read().strip()
expected = expected.replace(
"@TEST_FOLDER@",
os.path.dirname(__file__),
path2posix(os.path.dirname(__file__)),
)
expected = expected.replace(
"@DATA_FOLDER@",
path2posix(
subprocess.check_output(
["python", "-c", 'import patacrep, pkg_resources; print(pkg_resources.resource_filename(patacrep.__name__, "data"))'], # pylint: disable=line-too-long
[sys.executable, "-c", 'import patacrep; print(patacrep.__DATADIR__)'], # pylint: disable=line-too-long
universal_newlines=True,
cwd=os.path.dirname(songbook),
).strip(),
).strip()
),
)
self.assertMultiLineEqual(
@ -108,12 +112,16 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
@staticmethod
def compile_songbook(songbook, steps=None):
"""Compile songbook, and return the command return code."""
command = ['python', '-m', 'patacrep.songbook', songbook, '-v']
command = [sys.executable, '-m', 'patacrep.songbook', songbook]
if steps:
command.extend(['--steps', steps])
# Continuous Integration will be verbose
if 'CI' in os.environ:
command.append('-v')
try:
subprocess.check_output(
subprocess.check_call(
command,
stderr=subprocess.STDOUT,
universal_newlines=True,

18
texlive_packages.txt

@ -0,0 +1,18 @@
babel-english
babel-esperanto
babel-french
babel-german
babel-latin
babel-spanish
fancybox
framed
import
l3kernel
l3packages
mptopdf
ms
pgf
tipa
url
xcolor
xstring

2
tox.ini

@ -7,7 +7,7 @@ envlist = py34, lint
[testenv]
commands = {envpython} setup.py test
passenv = TRAVIS
passenv = TRAVIS APPVEYOR CI
deps =
[testenv:lint]

Loading…
Cancel
Save