Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

powrap doesn't accept files containing undecodable characters #104

Closed
egeakman opened this issue Feb 13, 2023 · 2 comments · Fixed by #105
Closed

powrap doesn't accept files containing undecodable characters #104

egeakman opened this issue Feb 13, 2023 · 2 comments · Fixed by #105

Comments

@egeakman
Copy link
Contributor

egeakman commented Feb 13, 2023

When I try to wrap c-api/stable.po, library/decimal.po, howto/unicode.po, etc. it throws:

usage: powrap [-h] [--modified] [-C GIT_ROOT] [--quiet] [--diff] [--check] [--version] [--no-wrap] [po_files ...]
powrap: error: argument po_files: invalid path value: 'library/decimal.po'

Also, msgcat can't write into the created NamedTemporaryFile, when run with --check.

EgeAk@egelaptop powrap on main 🐍 v3.10.9  in powrap
🕙 15:20:48 ❯ python -m powrap about.po --check
Checking wrapping of po files:   0%|                                                             | 0/1 [00:00<?, ?it/s]msgcat: cannot create output file "C:\Users\EgeAk\AppData\Local\Temp\tmp0megkadg": Permission denied
Error processing 'about.po': Command '['msgcat', '-', '-o', 'C:\\Users\\EgeAk\\AppData\\Local\\Temp\\tmp0megkadg']' returned non-zero exit status 1.
Checking wrapping of po files: 100%|█████████████████████████████████████████████████████| 1/1 [00:02<00:00,  2.52s/it]

It also adds whitespace at the top of the first msgid-msgstr pair on every file. (This turns out to be about MSYS msgcat not powrap itself)

# Python Documentation Turkish Translation
# Copyright (C) 2001-2023, Python Software Foundation
# This file is distributed under the same license as the Python package.
-#
+# 
msgid ""
msgstr ""

I tried this on different installations, different computers, and various shells (Git Bash, PowerShell 5 and 7, cmd). WSL (Ubuntu) seemed to have no problem though.

Any idea why this is happening?

@egeakman
Copy link
Contributor Author

egeakman commented Feb 16, 2023

Investigated a bit. The output of msgcat cannot be written into the temporary file created with tempfile.NamedTemporaryFile. I think it is directly related to "Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows)." statement in the tempfile documentation. I will open a PR if I come up with a cross-platform alternative or a workaround. (This comment is about running the command with --check)

@egeakman
Copy link
Contributor Author

egeakman commented Feb 16, 2023

About certain files not being accepted: I think it is because of the po_files argument's type definition. Path.read_text() raises UnicodeDecodeError on those files. Simply changing the type=path to type=Path resolves the issue. Or we can add an extra exception handler for UnicodeDecodeError for the path function to ignore this specific exception. Passing encoding = "utf-8" to Path.read_text() also works.

@egeakman egeakman changed the title Powrap doesn't wrap certain files and adds whitespace on Windows powrap doesn't accept files containing undecodable characters Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant