From d151c203bc547311c0b3f67ae69a29e3384e174d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 8 Sep 2021 15:01:47 -0700 Subject: [PATCH] Rename the project --- README.rst | 30 +++++---- setup.cfg | 6 +- src/chordpro/__init__.py | 1 - src/chordpro/__main__.py | 2 - src/chordpro/cli.py | 41 ------------ src/igitar/__init__.py | 1 + src/igitar/__main__.py | 2 + src/{chordpro => igitar}/base.py | 4 +- src/{chordpro => igitar}/chords.py | 2 +- src/igitar/cli.py | 67 +++++++++++++++++++ src/{chordpro => igitar}/constants.py | 0 .../renderers/__init__.py | 0 src/{chordpro => igitar}/renderers/html.py | 0 src/{chordpro => igitar}/renderers/text.py | 7 ++ 14 files changed, 101 insertions(+), 62 deletions(-) delete mode 100644 src/chordpro/__init__.py delete mode 100644 src/chordpro/__main__.py delete mode 100644 src/chordpro/cli.py create mode 100644 src/igitar/__init__.py create mode 100644 src/igitar/__main__.py rename src/{chordpro => igitar}/base.py (98%) rename src/{chordpro => igitar}/chords.py (95%) create mode 100644 src/igitar/cli.py rename src/{chordpro => igitar}/constants.py (100%) rename src/{chordpro => igitar}/renderers/__init__.py (100%) rename src/{chordpro => igitar}/renderers/html.py (100%) rename src/{chordpro => igitar}/renderers/text.py (95%) diff --git a/README.rst b/README.rst index 8e98853..99f8150 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,10 @@ -python-chordpro +igitar =============== -``python-chordpro`` is a ChordPro parser, written in Python. The main difference between this module -and other similar libraries is that ``python-chordpro`` parses ChordPro files down to the syllable + **igitar** *[ee-gee-tahr]* isiXhosa, meaning guitar + +``igitar`` is a ChordPro parser, written in Python. The main difference between this module +and other similar libraries is that ``igitar`` parses ChordPro files down to the syllable level, enabling finer-grained control of the formatted output. .. warning:: @@ -13,16 +15,18 @@ level, enabling finer-grained control of the formatted output. Installation ------------ -You can use ``pip`` to install ``python-chordpro``:: +You can use ``pip`` to install ``igitar``: - $ pip install python-chordpro +.. code-block:: shell-session + + $ pip install igitar Example Usage ------------- .. code-block:: python - from chordpro import Song + from igitar import Song song = Song('path/to/song.chordpro') @@ -32,11 +36,11 @@ Example Usage Rendering --------- -``python-chordpro`` comes with two renders, HTML and Text. +``igitar`` comes with two renders, HTML and Text. .. code-block:: python - from chordpro.renderers.html import render + from igitar.renderers.html import render print(render(song)) @@ -44,14 +48,16 @@ Rendering Command Line Interface ---------------------- -``python-chordpro`` also ships with a built-in command line interface which will read a ChordPro +``igitar`` also ships with a built-in command line interface which will read a ChordPro file and then render it using either the text or HTML renderer. -For example:: +For example: - $ python-chordpro path/to/song.chordpro -f text -o song.txt +.. code-block:: shell-session + + $ igitar path/to/song.chordpro -f text -o song.txt License ------- -``python-chordpro`` is licensed under the MIT license. See the LICENSE file for more information. +``igitar`` is licensed under the MIT license. See the LICENSE file for more information. diff --git a/setup.cfg b/setup.cfg index 421ccbe..74d5c2b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,11 @@ [metadata] -name = python-chordpro +name = igitar author = Raoul Snyman author_email = raoul@snyman.info description = A ChordPro parser, written in Python long_description = file:README.rst long_description_content_type = text/x-rst -url = https://git.snyman.info/raoul/python-chordpro +url = https://git.snyman.info/raoul/igitar license = MIT classifiers = Development Status :: 3 - Alpha @@ -38,7 +38,7 @@ where = src [options.entry_points] console_scripts = - python-chordpro = chordpro.cli:main + igitar = igitar.cli:main [bdist_wheel] universal = 1 diff --git a/src/chordpro/__init__.py b/src/chordpro/__init__.py deleted file mode 100644 index 5d169d1..0000000 --- a/src/chordpro/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from chordpro.base import Song # noqa diff --git a/src/chordpro/__main__.py b/src/chordpro/__main__.py deleted file mode 100644 index 0f54225..0000000 --- a/src/chordpro/__main__.py +++ /dev/null @@ -1,2 +0,0 @@ -from chordpro.cli import main -main() diff --git a/src/chordpro/cli.py b/src/chordpro/cli.py deleted file mode 100644 index 6b9cc2e..0000000 --- a/src/chordpro/cli.py +++ /dev/null @@ -1,41 +0,0 @@ -from argparse import ArgumentParser - -from chordpro.base import Song -from chordpro.renderers.html import render as html_render, get_options as html_get_options -from chordpro.renderers.text import render as text_render - - -def get_args(): - """Parse the command line arguments""" - parser = ArgumentParser() - parser.add_argument('input', metavar='FILENAME', help='Input ChordPro file') - parser.add_argument('-o', '--output', metavar='FILENAME', help='Output to a file') - parser.add_argument('-f', '--format', metavar='FORMAT', choices=['html', 'text'], default='html', - help='Output format') - parser.add_argument('-p', '--param', metavar='KEY=VALUE', action='append', help='Parameter to send to renderer') - return parser.parse_args() - - -def main(): - """The command line entrypoint""" - args = get_args() - render_params = {kv.split('=')[0]: kv.split('=')[-1] for kv in args.param} if args.param else {} - # Prepare the params - for key, value in render_params.items(): - if value.lower() == "true": - render_params[key] = True - elif value.lower() == "false": - render_params[key] = False - elif value.isdigit(): - render_params[key] = int(value) - - song = Song(args.input) - if args.format == 'text': - output = text_render(song, **render_params) - else: - output = html_render(song, **render_params) - if args.output: - with open(args.output, 'w') as html_file: - html_file.write(output) - else: - print(output) diff --git a/src/igitar/__init__.py b/src/igitar/__init__.py new file mode 100644 index 0000000..1378733 --- /dev/null +++ b/src/igitar/__init__.py @@ -0,0 +1 @@ +from igitar.base import Song # noqa diff --git a/src/igitar/__main__.py b/src/igitar/__main__.py new file mode 100644 index 0000000..9fe77ee --- /dev/null +++ b/src/igitar/__main__.py @@ -0,0 +1,2 @@ +from igitar.cli import main +main() diff --git a/src/chordpro/base.py b/src/igitar/base.py similarity index 98% rename from src/chordpro/base.py rename to src/igitar/base.py index b973901..8483052 100644 --- a/src/chordpro/base.py +++ b/src/igitar/base.py @@ -1,7 +1,7 @@ from hyphen import Hyphenator -from chordpro.constants import BRIDGE_MARKER, CHORD_WORD, CHORUS_MARKER, DIRECTIVE, END_OF, \ - KNOWN_DIRECTIVES, START_OF, VERSE_MARKER +from igitar.constants import BRIDGE_MARKER, CHORD_WORD, CHORUS_MARKER, DIRECTIVE, END_OF, KNOWN_DIRECTIVES, START_OF, \ + VERSE_MARKER HYPHEN_CACHE = {} SYLLABLE_EXCEPTIONS = { diff --git a/src/chordpro/chords.py b/src/igitar/chords.py similarity index 95% rename from src/chordpro/chords.py rename to src/igitar/chords.py index c73755e..3b4b0e7 100644 --- a/src/chordpro/chords.py +++ b/src/igitar/chords.py @@ -1,6 +1,6 @@ import re -from chordpro.constants import CHORD_SUFFIXES, ENGLISH_NOTES, GERMAN_NOTES, NEOLATIN_NOTES +from igitar.constants import CHORD_SUFFIXES, ENGLISH_NOTES, GERMAN_NOTES, NEOLATIN_NOTES _chord_cache = {} _line_cache = {} diff --git a/src/igitar/cli.py b/src/igitar/cli.py new file mode 100644 index 0000000..72a2a6c --- /dev/null +++ b/src/igitar/cli.py @@ -0,0 +1,67 @@ +from argparse import ArgumentParser + +from igitar.base import Song +from igitar.renderers.html import render as html_render, get_options as html_get_options +from igitar.renderers.text import render as text_render, get_options as text_get_options + + +def get_args(): + """Parse the command line arguments""" + parser = ArgumentParser() + subparsers = parser.add_subparsers(title='commands', dest='command') + + subparsers.add_parser('list', aliases=['list-commands', 'l'], help='List the commands available') + subparsers.add_parser('html', aliases=['html-params', 'h'], help='List the parameters available for HTML rendering') + subparsers.add_parser('text', aliases=['text-params', 't'], help='List the parameters available for text rendering') + + parser_render = subparsers.add_parser('render', aliases=['r'], help='Render a ChordPro file to HTML or text') + parser_render.add_argument('input', metavar='FILENAME', help='Input ChordPro file') + parser_render.add_argument('-o', '--output', metavar='FILENAME', help='Output to a file') + parser_render.add_argument('-f', '--format', metavar='FORMAT', choices=['html', 'text'], default='html', + help='Output format') + parser_render.add_argument('-p', '--param', metavar='KEY=VALUE', action='append', + help='Parameter to send to renderer') + return parser.parse_args() + + +def main(): + """The command line entrypoint""" + args = get_args() + if args.command in ['list', 'list-commands', 'l']: + print('Commands') + print('') + print(' list List all available commands') + print(' render Render a ChordPro file to HTML or text') + print(' html List the parameters available for HTML rendering') + print(' text List the parameters available for text rendering') + elif args.command in ['html', 'html-params', 'h']: + print('HTML parameters') + print('') + for param, details in html_get_options().items(): + print(' {:<12} {}'.format(param, details['description'])) + elif args.command in ['text', 'text-params', 't']: + print('Text parameters') + print('') + for param, details in text_get_options().items(): + print(' {:<12} {}'.format(param, details['description'])) + elif args.command == 'render': + render_params = {kv.split('=')[0]: kv.split('=')[-1] for kv in args.param} if args.param else {} + # Prepare the params + for key, value in render_params.items(): + if value.lower() == "true": + render_params[key] = True + elif value.lower() == "false": + render_params[key] = False + elif value.isdigit(): + render_params[key] = int(value) + + song = Song(args.input) + if args.format == 'text': + output = text_render(song, **render_params) + else: + output = html_render(song, **render_params) + if args.output: + with open(args.output, 'w') as output_file: + output_file.write(output) + else: + print(output) diff --git a/src/chordpro/constants.py b/src/igitar/constants.py similarity index 100% rename from src/chordpro/constants.py rename to src/igitar/constants.py diff --git a/src/chordpro/renderers/__init__.py b/src/igitar/renderers/__init__.py similarity index 100% rename from src/chordpro/renderers/__init__.py rename to src/igitar/renderers/__init__.py diff --git a/src/chordpro/renderers/html.py b/src/igitar/renderers/html.py similarity index 100% rename from src/chordpro/renderers/html.py rename to src/igitar/renderers/html.py diff --git a/src/chordpro/renderers/text.py b/src/igitar/renderers/text.py similarity index 95% rename from src/chordpro/renderers/text.py rename to src/igitar/renderers/text.py index 6ce4259..e636cb1 100644 --- a/src/chordpro/renderers/text.py +++ b/src/igitar/renderers/text.py @@ -1,6 +1,13 @@ import os +TEXT_OPTIONS = {} + + +def get_options(group=None): + return TEXT_OPTIONS + + def render(song, verse_upper=False): """Render a song to a text file""" nl = os.linesep -- 2.45.2