Skip to content

Commit

Permalink
fix: make readalongs prepare Windows compatible
Browse files Browse the repository at this point in the history
 - open the input file in utf-8 mode
 - don't open the input file until we need it, so we don't keep it open
   in case of error (causes unit testing errors when file handles are
   not closed so that temp files cannot be deleted)
 - the click file name for stdin is "-" on Windows, "<stdin>" on Linux
  • Loading branch information
joanise committed Aug 24, 2021
1 parent 06676cf commit 230d396
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions readalongs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def epub(**kwargs):
context_settings=CONTEXT_SETTINGS,
short_help="Convert a plain text file into the XML format for alignment.",
)
@click.argument("plaintextfile", type=click.File("r", encoding="utf8"))
@click.argument("plaintextfile", type=click.File("r", encoding="utf8", lazy=True))
@click.argument("xmlfile", type=click.Path(), required=False, default="")
@click.option("-d", "--debug", is_flag=True, help="Add debugging messages to logger")
@click.option(
Expand Down Expand Up @@ -344,7 +344,8 @@ def prepare(**kwargs):
out_file = kwargs["xmlfile"]
if not out_file:
out_file = get_click_file_name(input_file)
if out_file == "<stdin>": # actual intput_file.name when cli input is "-"
print(f"input_file={out_file}")
if out_file in ("<stdin>", "-"): # intput_file.name is <stdin> on Linux, - on Windows, when cli input is "-"
out_file = "-"
else:
if out_file.endswith(".txt"):
Expand Down

0 comments on commit 230d396

Please sign in to comment.