diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_chord b/patacrep/data/templates/songs/chordpro/chordpro/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_chord rename to patacrep/data/templates/songs/chordpro/chordpro/content_chord diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_chordlist b/patacrep/data/templates/songs/chordpro/chordpro/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_chordlist rename to patacrep/data/templates/songs/chordpro/chordpro/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_comment b/patacrep/data/templates/songs/chordpro/chordpro/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_comment rename to patacrep/data/templates/songs/chordpro/chordpro/content_comment diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_define b/patacrep/data/templates/songs/chordpro/chordpro/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_define rename to patacrep/data/templates/songs/chordpro/chordpro/content_define diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_endofline b/patacrep/data/templates/songs/chordpro/chordpro/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_endofline rename to patacrep/data/templates/songs/chordpro/chordpro/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_error b/patacrep/data/templates/songs/chordpro/chordpro/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_error rename to patacrep/data/templates/songs/chordpro/chordpro/content_error diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment b/patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/chordpro/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_image b/patacrep/data/templates/songs/chordpro/chordpro/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_image rename to patacrep/data/templates/songs/chordpro/chordpro/content_image diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_line b/patacrep/data/templates/songs/chordpro/chordpro/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_line rename to patacrep/data/templates/songs/chordpro/chordpro/content_line diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_newline b/patacrep/data/templates/songs/chordpro/chordpro/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_newline rename to patacrep/data/templates/songs/chordpro/chordpro/content_newline diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_partition b/patacrep/data/templates/songs/chordpro/chordpro/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_partition rename to patacrep/data/templates/songs/chordpro/chordpro/content_partition diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_space b/patacrep/data/templates/songs/chordpro/chordpro/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_space rename to patacrep/data/templates/songs/chordpro/chordpro/content_space diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_tablature b/patacrep/data/templates/songs/chordpro/chordpro/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_tablature rename to patacrep/data/templates/songs/chordpro/chordpro/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_verse b/patacrep/data/templates/songs/chordpro/chordpro/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_verse rename to patacrep/data/templates/songs/chordpro/chordpro/content_verse diff --git a/patacrep/data/ast_templates/chordpro/chordpro/content_word b/patacrep/data/templates/songs/chordpro/chordpro/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/content_word rename to patacrep/data/templates/songs/chordpro/chordpro/content_word diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song b/patacrep/data/templates/songs/chordpro/chordpro/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song rename to patacrep/data/templates/songs/chordpro/chordpro/song diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song_body b/patacrep/data/templates/songs/chordpro/chordpro/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song_body rename to patacrep/data/templates/songs/chordpro/chordpro/song_body diff --git a/patacrep/data/ast_templates/chordpro/chordpro/song_header b/patacrep/data/templates/songs/chordpro/chordpro/song_header similarity index 100% rename from patacrep/data/ast_templates/chordpro/chordpro/song_header rename to patacrep/data/templates/songs/chordpro/chordpro/song_header diff --git a/patacrep/data/ast_templates/chordpro/html/content_chord b/patacrep/data/templates/songs/chordpro/html/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_chord rename to patacrep/data/templates/songs/chordpro/html/content_chord diff --git a/patacrep/data/ast_templates/chordpro/html/content_chordlist b/patacrep/data/templates/songs/chordpro/html/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_chordlist rename to patacrep/data/templates/songs/chordpro/html/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/html/content_comment b/patacrep/data/templates/songs/chordpro/html/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_comment rename to patacrep/data/templates/songs/chordpro/html/content_comment diff --git a/patacrep/data/ast_templates/chordpro/html/content_define b/patacrep/data/templates/songs/chordpro/html/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_define rename to patacrep/data/templates/songs/chordpro/html/content_define diff --git a/patacrep/data/ast_templates/chordpro/html/content_define_list b/patacrep/data/templates/songs/chordpro/html/content_define_list similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_define_list rename to patacrep/data/templates/songs/chordpro/html/content_define_list diff --git a/patacrep/data/ast_templates/chordpro/html/content_endofline b/patacrep/data/templates/songs/chordpro/html/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_endofline rename to patacrep/data/templates/songs/chordpro/html/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/html/content_error b/patacrep/data/templates/songs/chordpro/html/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_error rename to patacrep/data/templates/songs/chordpro/html/content_error diff --git a/patacrep/data/ast_templates/chordpro/html/content_guitar_comment b/patacrep/data/templates/songs/chordpro/html/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/html/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/html/content_image b/patacrep/data/templates/songs/chordpro/html/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_image rename to patacrep/data/templates/songs/chordpro/html/content_image diff --git a/patacrep/data/ast_templates/chordpro/html/content_line b/patacrep/data/templates/songs/chordpro/html/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_line rename to patacrep/data/templates/songs/chordpro/html/content_line diff --git a/patacrep/data/ast_templates/chordpro/html/content_metadata_cover b/patacrep/data/templates/songs/chordpro/html/content_metadata_cover similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_metadata_cover rename to patacrep/data/templates/songs/chordpro/html/content_metadata_cover diff --git a/patacrep/data/ast_templates/chordpro/html/content_newline b/patacrep/data/templates/songs/chordpro/html/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_newline rename to patacrep/data/templates/songs/chordpro/html/content_newline diff --git a/patacrep/data/ast_templates/chordpro/html/content_partition b/patacrep/data/templates/songs/chordpro/html/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_partition rename to patacrep/data/templates/songs/chordpro/html/content_partition diff --git a/patacrep/data/ast_templates/chordpro/html/content_space b/patacrep/data/templates/songs/chordpro/html/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_space rename to patacrep/data/templates/songs/chordpro/html/content_space diff --git a/patacrep/data/ast_templates/chordpro/html/content_tablature b/patacrep/data/templates/songs/chordpro/html/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_tablature rename to patacrep/data/templates/songs/chordpro/html/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/html/content_verse b/patacrep/data/templates/songs/chordpro/html/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_verse rename to patacrep/data/templates/songs/chordpro/html/content_verse diff --git a/patacrep/data/ast_templates/chordpro/html/content_word b/patacrep/data/templates/songs/chordpro/html/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/content_word rename to patacrep/data/templates/songs/chordpro/html/content_word diff --git a/patacrep/data/ast_templates/chordpro/html/song b/patacrep/data/templates/songs/chordpro/html/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song rename to patacrep/data/templates/songs/chordpro/html/song diff --git a/patacrep/data/ast_templates/chordpro/html/song_body b/patacrep/data/templates/songs/chordpro/html/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song_body rename to patacrep/data/templates/songs/chordpro/html/song_body diff --git a/patacrep/data/ast_templates/chordpro/html/song_header b/patacrep/data/templates/songs/chordpro/html/song_header similarity index 100% rename from patacrep/data/ast_templates/chordpro/html/song_header rename to patacrep/data/templates/songs/chordpro/html/song_header diff --git a/patacrep/data/ast_templates/chordpro/latex/content_chord b/patacrep/data/templates/songs/chordpro/latex/content_chord similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_chord rename to patacrep/data/templates/songs/chordpro/latex/content_chord diff --git a/patacrep/data/ast_templates/chordpro/latex/content_chordlist b/patacrep/data/templates/songs/chordpro/latex/content_chordlist similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_chordlist rename to patacrep/data/templates/songs/chordpro/latex/content_chordlist diff --git a/patacrep/data/ast_templates/chordpro/latex/content_comment b/patacrep/data/templates/songs/chordpro/latex/content_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_comment rename to patacrep/data/templates/songs/chordpro/latex/content_comment diff --git a/patacrep/data/ast_templates/chordpro/latex/content_define b/patacrep/data/templates/songs/chordpro/latex/content_define similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_define rename to patacrep/data/templates/songs/chordpro/latex/content_define diff --git a/patacrep/data/ast_templates/chordpro/latex/content_endofline b/patacrep/data/templates/songs/chordpro/latex/content_endofline similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_endofline rename to patacrep/data/templates/songs/chordpro/latex/content_endofline diff --git a/patacrep/data/ast_templates/chordpro/latex/content_error b/patacrep/data/templates/songs/chordpro/latex/content_error similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_error rename to patacrep/data/templates/songs/chordpro/latex/content_error diff --git a/patacrep/data/ast_templates/chordpro/latex/content_guitar_comment b/patacrep/data/templates/songs/chordpro/latex/content_guitar_comment similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_guitar_comment rename to patacrep/data/templates/songs/chordpro/latex/content_guitar_comment diff --git a/patacrep/data/ast_templates/chordpro/latex/content_image b/patacrep/data/templates/songs/chordpro/latex/content_image similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_image rename to patacrep/data/templates/songs/chordpro/latex/content_image diff --git a/patacrep/data/ast_templates/chordpro/latex/content_line b/patacrep/data/templates/songs/chordpro/latex/content_line similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_line rename to patacrep/data/templates/songs/chordpro/latex/content_line diff --git a/patacrep/data/ast_templates/chordpro/latex/content_newline b/patacrep/data/templates/songs/chordpro/latex/content_newline similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_newline rename to patacrep/data/templates/songs/chordpro/latex/content_newline diff --git a/patacrep/data/ast_templates/chordpro/latex/content_partition b/patacrep/data/templates/songs/chordpro/latex/content_partition similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_partition rename to patacrep/data/templates/songs/chordpro/latex/content_partition diff --git a/patacrep/data/ast_templates/chordpro/latex/content_space b/patacrep/data/templates/songs/chordpro/latex/content_space similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_space rename to patacrep/data/templates/songs/chordpro/latex/content_space diff --git a/patacrep/data/ast_templates/chordpro/latex/content_tablature b/patacrep/data/templates/songs/chordpro/latex/content_tablature similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_tablature rename to patacrep/data/templates/songs/chordpro/latex/content_tablature diff --git a/patacrep/data/ast_templates/chordpro/latex/content_verse b/patacrep/data/templates/songs/chordpro/latex/content_verse similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_verse rename to patacrep/data/templates/songs/chordpro/latex/content_verse diff --git a/patacrep/data/ast_templates/chordpro/latex/content_word b/patacrep/data/templates/songs/chordpro/latex/content_word similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/content_word rename to patacrep/data/templates/songs/chordpro/latex/content_word diff --git a/patacrep/data/ast_templates/chordpro/latex/song b/patacrep/data/templates/songs/chordpro/latex/song similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/song rename to patacrep/data/templates/songs/chordpro/latex/song diff --git a/patacrep/data/ast_templates/chordpro/latex/song_body b/patacrep/data/templates/songs/chordpro/latex/song_body similarity index 100% rename from patacrep/data/ast_templates/chordpro/latex/song_body rename to patacrep/data/templates/songs/chordpro/latex/song_body diff --git a/patacrep/files.py b/patacrep/files.py index 1116c8b0..a204f8e7 100644 --- a/patacrep/files.py +++ b/patacrep/files.py @@ -12,20 +12,24 @@ from patacrep import utils LOGGER = logging.getLogger(__name__) -def recursive_find(root_directory, extensions): +def recursive_find(root_directory, extensions=None): """Recursively find files with the given extensions, from a root_directory. Return a list of files matching those conditions. Arguments: - - `extensions`: list of accepted extensions. + - `extensions`: list of accepted extensions (None means every file). - `root_directory`: root directory of the search. """ if not os.path.isdir(root_directory): return [] matches = [] - pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions))) + if extensions is None: + pattern = re.compile('.*') + else: + pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions))) + with chdir(root_directory): for root, __ignored, filenames in os.walk(os.curdir): for filename in filenames: diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index a36c17bc..922ecb00 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -192,11 +192,11 @@ class Song: """ raise NotImplementedError() - def get_datadirs(self, subdir=None): - """Return an iterator of existing datadirs (with eventually a subdir) + def iter_datadirs(self, *subpath): + """Return an iterator of existing datadirs (with an optionnal subpath) """ for directory in self.config['datadir']: - fullpath = os.path.join(directory, subdir) + fullpath = os.path.join(directory, *subpath) if os.path.isdir(fullpath): yield fullpath @@ -255,7 +255,7 @@ class Song: return self.search_file( filename, ['', '.jpg', '.png'], - datadirs=self.get_datadirs('img'), + datadirs=self.iter_datadirs('img'), ) def search_partition(self, filename): @@ -263,7 +263,7 @@ class Song: return self.search_file( filename, ['', '.ly'], - datadirs=self.get_datadirs('scores'), + datadirs=self.iter_datadirs('scores'), ) def unprefixed_title(title, prefixes): diff --git a/patacrep/songs/chordpro/__init__.py b/patacrep/songs/chordpro/__init__.py index 513977f6..0be23592 100644 --- a/patacrep/songs/chordpro/__init__.py +++ b/patacrep/songs/chordpro/__init__.py @@ -48,14 +48,9 @@ class ChordproSong(Song): "content": self.cached['song'].content, } - jinjaenv = Environment(loader=ChoiceLoader([ - FileSystemLoader( - self.get_datadirs(os.path.join("templates", self.output_language)) - ), - FileSystemLoader( - pkg_datapath('ast_templates', 'chordpro', self.output_language) - ), - ])) + jinjaenv = Environment(loader=FileSystemLoader( + self.iter_datadirs("templates", "songs", "chordpro", self.output_language) + )) jinjaenv.filters['search_image'] = self.search_image jinjaenv.filters['search_partition'] = self.search_partition jinjaenv.filters['lang2babel'] = lang2babel diff --git a/setup.py b/setup.py index 023201eb..8d8717d6 100755 --- a/setup.py +++ b/setup.py @@ -4,10 +4,14 @@ $ python setup.py install """ -from patacrep import __version__ +from patacrep import __version__, __DATADIR__, files from setuptools import setup, find_packages +# List the data files +data_files = files.recursive_find(__DATADIR__) +data_files = ["data/" + d for d in data_files] + setup( name='patacrep', version=__version__, @@ -21,12 +25,7 @@ setup( "unidecode", "jinja2", "chardet", "ply", ], setup_requires=["hgtools"], - package_data={'patacrep': [ - 'data/ast_templates/*/*/*', - 'data/img/*', - 'data/latex/*', - 'data/templates/*', - ]}, + package_data={'patacrep': data_files}, entry_points={ 'console_scripts': [ "songbook = patacrep.songbook.__main__:main", diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index f0e94290..f542a203 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -7,7 +7,7 @@ import os import unittest from pkg_resources import resource_filename -from patacrep import files +from patacrep import files, __DATADIR__ from patacrep.build import DEFAULT_CONFIG from patacrep.encoding import open_read @@ -41,6 +41,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): if 'datadir' not in cls.config: cls.config['datadir'] = [] cls.config['datadir'].append(resource_filename(__name__, 'datadir')) + cls.config['datadir'].append(__DATADIR__) cls.song_plugins = files.load_plugins( datadirs=cls.config['datadir'],