diff --git a/powrap/powrap.py b/powrap/powrap.py index c3c70df..393a0f0 100644 --- a/powrap/powrap.py +++ b/powrap/powrap.py @@ -27,7 +27,10 @@ def check_style(po_files: Iterable[str], no_wrap=False, quiet=False, diff=False) except OSError as open_error: tqdm.write(f"Error opening '{po_path}': {open_error}") continue - with NamedTemporaryFile("w+") as tmpfile: + + delete = os.name == "posix" and sys.platform != "cygwin" + + with NamedTemporaryFile("w+", delete=delete, encoding="utf-8") as tmpfile: args = ["msgcat", "-", "-o", tmpfile.name] if no_wrap: args[1:1] = ["--no-wrap"] @@ -49,6 +52,8 @@ def check_style(po_files: Iterable[str], no_wrap=False, quiet=False, diff=False) new_po_content.splitlines(keepends=True), ): print(line, end="", file=sys.stderr) + if not delete: + os.remove(tmpfile.name) return errors @@ -81,7 +86,7 @@ def path(path_str): if not path_obj.is_file(): raise argparse.ArgumentTypeError("{!r} is not a file.".format(path_str)) try: - path_obj.read_text() + path_obj.read_text(encoding="utf-8") except PermissionError as read_error: raise argparse.ArgumentTypeError( "{!r}: Permission denied.".format(path_str)