Browse Source

Recursively discover data files or the setup

pull/156/head
Oliverpool 9 years ago
parent
commit
efb36b3815
  1. 7
      patacrep/files.py
  2. 13
      setup.py

7
patacrep/files.py

@ -12,24 +12,25 @@ 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 = []
if extensions:
pattern = re.compile(r'.*\.({})$'.format('|'.join(extensions)))
with chdir(root_directory):
for root, __ignored, filenames in os.walk(os.curdir):
for filename in filenames:
if pattern.match(filename):
if not extensions or pattern.match(filename):
matches.append(os.path.join(root, filename))
return matches

13
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/chordpro/*/*',
'data/img/*',
'data/latex/*',
'data/templates/*',
]},
package_data={'patacrep': data_files},
entry_points={
'console_scripts': [
"songbook = patacrep.songbook.__main__:main",

Loading…
Cancel
Save