From 230d39694153b115d0d841f93205c321f3754315 Mon Sep 17 00:00:00 2001 From: Eric Joanis Date: Tue, 24 Aug 2021 16:21:44 -0400 Subject: [PATCH] fix: make readalongs prepare Windows compatible - 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, "" on Linux --- readalongs/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/readalongs/cli.py b/readalongs/cli.py index 31b0d0c1..08a7d2f4 100644 --- a/readalongs/cli.py +++ b/readalongs/cli.py @@ -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( @@ -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 == "": # actual intput_file.name when cli input is "-" + print(f"input_file={out_file}") + if out_file in ("", "-"): # intput_file.name is on Linux, - on Windows, when cli input is "-" out_file = "-" else: if out_file.endswith(".txt"):