Skip to content

Commit

Permalink
refactor: narrow the try/except to just the parse_g2p_fallback call
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Oct 5, 2021
1 parent 53ffcfb commit 753c77e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions readalongs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def align(**kwargs): # noqa: C901
f"Cannot write into output folder '{output_dir}'. Please verify permissions."
) from e

try:
g2p_fallbacks = parse_g2p_fallback(kwargs["g2p_fallback"])
except ValueError as e:
raise click.BadParameter(e) from e

output_basename = os.path.basename(output_dir)
temp_base = None
if kwargs["save_temps"]:
Expand Down Expand Up @@ -247,7 +252,7 @@ def align(**kwargs): # noqa: C901
bare=bare,
config=config,
save_temps=temp_base,
g2p_fallbacks=parse_g2p_fallback(kwargs["g2p_fallback"]),
g2p_fallbacks=g2p_fallbacks,
verbose_g2p_warnings=kwargs["g2p_verbose"],
)
except RuntimeError as e:
Expand Down Expand Up @@ -495,18 +500,19 @@ def g2p(**kwargs):
% (get_click_file_name(input_file), e)
)

# Add the IDs to paragraph, sentences, word, etc.
xml = add_ids(xml)
# Apply the g2p mappings.
try:
xml, valid = convert_xml(
xml,
g2p_fallbacks=parse_g2p_fallback(kwargs["g2p_fallback"]),
verbose_warnings=kwargs["g2p_verbose"],
)
g2p_fallbacks = parse_g2p_fallback(kwargs["g2p_fallback"])
except ValueError as e:
raise click.BadParameter(e) from e

# Add the IDs to paragraph, sentences, word, etc.
xml = add_ids(xml)

# Apply the g2p mappings.
xml, valid = convert_xml(
xml, g2p_fallbacks=g2p_fallbacks, verbose_warnings=kwargs["g2p_verbose"],
)

if output_path == "-":
write_xml(sys.stdout.buffer, xml)
else:
Expand Down

0 comments on commit 753c77e

Please sign in to comment.