refactor: change pystache to chevron · ReadAlongs/Studio@d1797c0 · GitHub
Skip to content

Commit d1797c0

Browse files
committed
refactor: change pystache to chevron
1 parent 3eb2a33 commit d1797c0

13 files changed

Lines changed: 37 additions & 39 deletions

File tree

readalongs/_version.py

Lines changed: 1 addition & 1 deletion

readalongs/align.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from datetime import timedelta
1818
from typing import Dict, List, Union
1919

20-
import pystache
20+
import chevron
2121
import regex as re
2222
import soundswallower
2323
from lxml import etree
@@ -53,7 +53,7 @@
5353

5454
@dataclass
5555
class WordSequence:
56-
""" Sequence of "unit" XML elements
56+
"""Sequence of "unit" XML elements
5757
5858
By default, the unit elements are the <w> elements.
5959
@@ -69,7 +69,7 @@ class WordSequence:
6969

7070

7171
def get_sequences(xml, xml_filename, unit="w", anchor="anchor") -> List[WordSequence]:
72-
""" Return the list of anchor-separated word sequences in xml
72+
"""Return the list of anchor-separated word sequences in xml
7373
7474
Args:
7575
xml (etree): xml structure in which to search for words and anchors
@@ -122,7 +122,7 @@ def get_sequences(xml, xml_filename, unit="w", anchor="anchor") -> List[WordSequ
122122

123123

124124
def split_silences(words: List[dict], final_end, excluded_segments: List[dict]) -> None:
125-
""" split the silences between words, making sure we don't step over any
125+
"""split the silences between words, making sure we don't step over any
126126
excluded segment boundaries
127127
128128
Args:
@@ -170,7 +170,7 @@ def align_audio( # noqa: C901
170170
g2p_fallbacks=None,
171171
verbose_g2p_warnings=False,
172172
):
173-
""" Align an XML input file to an audio file.
173+
"""Align an XML input file to an audio file.
174174
175175
Args:
176176
xml_path (str): Path to XML input file in TEI-like format
@@ -429,7 +429,7 @@ def save_readalong(
429429
output_xhtml: bool = False,
430430
audiofile: str,
431431
):
432-
""" Save the results from align_audio() into the otuput files required for a
432+
"""Save the results from align_audio() into the otuput files required for a
433433
readalong
434434
435435
Args:
@@ -529,7 +529,7 @@ def save_readalong(
529529

530530

531531
def return_word_from_id(xml: etree, el_id: str) -> str:
532-
""" Given an XML document, return the innertext at id
532+
"""Given an XML document, return the innertext at id
533533
534534
Args:
535535
xml (etree): XML document
@@ -542,7 +542,7 @@ def return_word_from_id(xml: etree, el_id: str) -> str:
542542

543543

544544
def return_words_and_sentences(results):
545-
""" Parse xml into word and sentence 'tier' data
545+
"""Parse xml into word and sentence 'tier' data
546546
547547
Args:
548548
results([TODO type]): [TODO description]
@@ -587,7 +587,7 @@ def return_words_and_sentences(results):
587587

588588

589589
def write_to_text_grid(words: List[dict], sentences: List[dict], duration: float):
590-
""" Write results to Praat TextGrid. Because we are using pympi, we can also export to Elan EAF.
590+
"""Write results to Praat TextGrid. Because we are using pympi, we can also export to Elan EAF.
591591
592592
Args:
593593
words (List[dict]): List of word times containing start, end, and value keys
@@ -629,7 +629,7 @@ def float_to_timedelta(n: float) -> str:
629629

630630

631631
def write_to_subtitles(data: Union[List[dict], List[List[dict]]]):
632-
""" Returns WebVTT object from data.
632+
"""Returns WebVTT object from data.
633633
634634
Args:
635635
data (Union[List[dict], List[List[dict]]]):
@@ -659,7 +659,7 @@ def write_to_subtitles(data: Union[List[dict], List[List[dict]]]):
659659

660660

661661
def convert_to_xhtml(tokenized_xml, title="Book"):
662-
""" Do a simple and not at all foolproof conversion to XHTML.
662+
"""Do a simple and not at all foolproof conversion to XHTML.
663663
664664
Args:
665665
tokenized_xml (etree): xml etree with tokens, converted in place
@@ -715,7 +715,7 @@ def convert_to_xhtml(tokenized_xml, title="Book"):
715715

716716

717717
def create_input_tei(**kwargs):
718-
""" Create input xml in TEI standard.
718+
"""Create input xml in TEI standard.
719719
Uses readlines to infer paragraph and sentence structure from plain text.
720720
TODO: Check if path, if it's just plain text, then render that instead of reading from the file
721721
Assumes a double blank line marks a page break, and a single blank line
@@ -780,7 +780,7 @@ def create_input_tei(**kwargs):
780780
paragraphs.append({"sentences": sentences})
781781
if paragraphs:
782782
pages.append({"paragraphs": paragraphs})
783-
xml = pystache.render(TEI_TEMPLATE, {**kwargs, **{"pages": pages}})
783+
xml = chevron.render(TEI_TEMPLATE, {**kwargs, **{"pages": pages}})
784784
outfile.write(xml.encode("utf-8"))
785785
outfile.flush()
786786
outfile.close()

readalongs/epub/create_epub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
import shutil
1414

15-
import pystache
15+
import chevron
1616

1717
from readalongs.log import LOGGER
1818
from readalongs.text.util import (
@@ -154,15 +154,15 @@ def create_epub(input_path, output_path, unpacked=False):
154154

155155
# container.xml file
156156
container_template = load_txt(CONTAINER_ORIGIN_PATH)
157-
container_txt = pystache.render(
157+
container_txt = chevron.render(
158158
container_template, {"package_path": PACKAGE_DEST_PATH}
159159
)
160160
save(output_path, CONTAINER_DEST_PATH, container_txt)
161161

162162
# the SMIL and all the files referenced in the SMIL
163163
package_data = extract_files_from_SMIL(input_path)
164164
package_template = load_txt(PACKAGE_ORIGIN_PATH)
165-
package_txt = pystache.render(package_template, package_data)
165+
package_txt = chevron.render(package_template, package_data)
166166
save(output_path, PACKAGE_DEST_PATH, package_txt)
167167

168168
for entry in package_data["media"]:

readalongs/text/make_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import argparse
1919

20-
import pystache
20+
import chevron
2121

2222
from readalongs.log import LOGGER
2323
from readalongs.text.util import load_xml, save_txt
@@ -43,7 +43,7 @@ def make_dict(word_elements, input_filename, unit="m"):
4343
data["items"].append({"id": e.attrib["id"], "pronunciation": text})
4444
if nwords == 0:
4545
raise RuntimeError("No words in dictionary!")
46-
return pystache.render(DICT_TEMPLATE, data)
46+
return chevron.render(DICT_TEMPLATE, data)
4747

4848

4949
def go(input_filename, output_filename, unit):

readalongs/text/make_fsg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import argparse
1919
import os
2020

21-
import pystache
21+
import chevron
2222
from slugify import slugify
2323

2424
from readalongs.log import LOGGER
@@ -65,7 +65,7 @@ def make_fsg(word_elements, filename):
6565
data["final_state"] = data["num_states"]
6666
data["num_states"] += 1
6767

68-
return pystache.render(FSG_TEMPLATE, data)
68+
return chevron.render(FSG_TEMPLATE, data)
6969

7070

7171
def go(input_filename, output_filename, unit):

readalongs/text/make_jsgf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import datetime
2222
import os
2323

24-
import pystache
24+
import chevron
2525

2626
from readalongs.text.util import load_xml, save_txt
2727

@@ -56,7 +56,7 @@ def make_jsgf(xml, filename, unit="m"):
5656
id = e.attrib["id"]
5757
data["words"].append({"id": id})
5858

59-
return pystache.render(JSGF_TEMPLATE, data)
59+
return chevron.render(JSGF_TEMPLATE, data)
6060

6161

6262
def go(input_filename, output_filename, unit):

readalongs/text/make_jsgf_advanced.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import datetime
2020
import os
2121

22-
import pystache
23-
2422
from readalongs.text.util import load_xml, save_txt
2523

2624
# ###################3

readalongs/text/make_smil.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import argparse
1313

14-
import pystache
14+
import chevron
1515

1616
from readalongs.text.util import save_txt
1717

@@ -36,7 +36,7 @@
3636

3737

3838
def parse_hypseg(text):
39-
""" Parse hypseg alignments file and return alignements
39+
"""Parse hypseg alignments file and return alignements
4040
4141
Args:
4242
text(str): hypseg text
@@ -61,7 +61,7 @@ def parse_hypseg(text):
6161

6262

6363
def make_smil(text_path: str, audio_path: str, results: dict) -> str:
64-
""" Actually render the SMIL
64+
"""Actually render the SMIL
6565
6666
Args:
6767
text_path(str): path to text
@@ -73,7 +73,7 @@ def make_smil(text_path: str, audio_path: str, results: dict) -> str:
7373
"""
7474
results["text_path"] = text_path
7575
results["audio_path"] = audio_path
76-
return pystache.render(SMIL_TEMPLATE, results)
76+
return chevron.render(SMIL_TEMPLATE, results)
7777

7878

7979
def go(seg_path, text_path, audio_path, output_path):

readalongs/waveform2svg/pitch2svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
from io import open
2222
from math import floor
2323

24+
import chevron
2425
import librosa
2526
import numpy as np
26-
import pystache
2727

2828
from readalongs.log import LOGGER
2929
from readalongs.waveform2svg.audio_util import (
@@ -54,7 +54,7 @@ def render_svg(pitches, width=512, height=100, zero_height=5):
5454
data["points"].append({"x": x, "y": y})
5555
data["points"].append({"x": float(width), "y": float(height - zero_height)})
5656
data["points"].append({"x": float(width), "y": float(height)})
57-
return pystache.render(SVG_TEMPLATE, data)
57+
return chevron.render(SVG_TEMPLATE, data)
5858

5959

6060
def extract_pitches(waveform, nbuckets=512):

readalongs/waveform2svg/units2svg.py

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)