Assure powrap is compatible with Windows (#105)

This commit is contained in:
Ege Akman 2023-03-30 23:54:35 +03:00 committed by GitHub
parent c826541447
commit b5c70a7654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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 parse_args():
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)