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

powrap does not work on Windows #82

Open
yeyeto2788 opened this issue Oct 6, 2020 · 5 comments
Open

powrap does not work on Windows #82

yeyeto2788 opened this issue Oct 6, 2020 · 5 comments

Comments

@yeyeto2788
Copy link

Steps to reproduce:

  • git clone https://github.com/yeyeto2788/python-docs-es.git
  • git checkout traduccion-misc
  • pip install powrap
  • powrap .\library\misc.po

Error:

(venv) C:\Users\yeyeto2788\workspace\python-docs-es\library>powrap "misc.po"
Fixing wrapping of po files:   0%|                                                                                                                                                            | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\yeyeto2788\workspace\python-docs-es\venv\Scripts\powrap.exe\__main__.py", line 9, in <module>
  File "c:\users\yeyeto2788\workspace\python-docs-es\venv\lib\site-packages\powrap\powrap.py", line 142, in main
    fix_style(args.po_files, args.no_wrap, args.quiet)
  File "c:\users\yeyeto2788\workspace\python-docs-es\venv\lib\site-packages\powrap\powrap.py", line 55, in fix_style
    run(args, encoding="utf-8", check=True, input=po_content)
  File "C:\Program Files\Python36\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files\Python36\lib\subprocess.py", line 971, in _execute_child
    args = list2cmdline(args)
  File "C:\Program Files\Python36\lib\subprocess.py", line 461, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'WindowsPath' is not iterable

OS: Windows 10
Python: Python 3.6.5

No matter what path I pass over the arguments that I would give me the same error.

P.D: Might not be the best OS in the world but that's what I have for now 😢

@JulienPalard
Copy link
Collaborator

JulienPalard commented Oct 7, 2020

Hi! Thanks for reporting!

Can you try this patch:

diff --git a/powrap/powrap.py b/powrap/powrap.py
index 17be2f1..d6f515f 100644
--- a/powrap/powrap.py
+++ b/powrap/powrap.py
@@ -48,7 +48,7 @@ def fix_style(po_files, no_wrap=False, quiet=False):
     for po_path in tqdm(po_files, desc="Fixing wrapping of po files", disable=quiet):
         with open(po_path, encoding="UTF-8") as po_file:
             po_content = po_file.read()
-        args = ["msgcat", "-", "-o", po_path]
+        args = ["msgcat", "-", "-o", str(po_path)]
         if no_wrap:
             args[1:1] = ["--no-wrap"]
         try:

I think it's more a Python 3.6 issue than a Windows issue (but I'm surprised you have msgcat on windows :p)

@yeyeto2788
Copy link
Author

yeyeto2788 commented Oct 8, 2020

Thanks for the quick reply @JulienPalard

I actually didn't install msgcat so it is weird. I did try your patch and it actually "worked" not raising any exception except for these messages:

(venv) C:\Users\yeyeto2788\workspace\python-docs-es>powrap .\library\othergui.po
Error running msgcat - -o library\othergui.po: [WinError 2] The system cannot find the file specified
Fixing wrapping of po files:   0%|                                                                                                                                                            | 0/1 [00:00<?, ?it/s]

(venv) C:\Users\yeyeto2788\workspace\python-docs-es>powrap C:\Users\yeyeto2788\workspace\python-docs-es\library\abc.po
Error running msgcat - -o C:\Users\yeyeto2788\workspace\python-docs-es\library\abc.po: [WinError 2] The system cannot find the file specified
Fixing wrapping of po files:   0%|    

IMHO this might be somehow expected since I do not have msgcat installed but it is weird having the progress bar stuck on the bottom and the error above the bar.

Seems like the actual error is because when it tries to execute the command and it does not find msgcat, but the .po file exists and checks are passed on line https://github.com/JulienPalard/powrap/blob/master/powrap/powrap.py#L68

@JulienPalard
Copy link
Collaborator

Yes, that's because you don't have msgcat.

Some people and I are sometimes trying to get rid of this dependency, as we know it's not trivial to get msgcat on Windows.

(I'm starting to think having a textwrap lib in Python implementing https://www.unicode.org/reports/tr14/tr14-45.html would be great.)

Another way to properly indent a .po file in the meantime would be to use poedit (open the file whithin poedit, save, close), which itself uses the same algorithm as msgcat, so it wraps like powrap. The default configuration is the right one (79 chars per line, something like that), yet you may have to check a box like "rewrap even if I did not modified the file" in the settings to encourage it to actually rewrap the file, IIRC it's not by default.

@yeyeto2788
Copy link
Author

In the meantime, I used the library on Linux based OS on a VM and it worked flawlessly. Thank you very much for your suggestion on using poedit, I'll keep it in mind for the next time.

Do you think https://docs.python.org/3.5/library/textwrap.html does not implement somehow that? If there is anything I can help with just let me know.

I did a quick review of the code and I notice there are still lines belonging to the old dependency of msgcat command execution https://github.com/JulienPalard/powrap/blob/from_msgcat/powrap/powrap.py#L43

@JulienPalard
Copy link
Collaborator

Do you think https://docs.python.org/3.5/library/textwrap.html does not implement somehow that? If there is anything I can help with just let me know.

No, that's not the same algorithm. I opened an issue about it: https://bugs.python.org/issue41975

I did a quick review of the code and I notice there are still lines belonging to the old dependency of msgcat command execution https://github.com/JulienPalard/powrap/blob/from_msgcat/powrap/powrap.py#L43

Yes, this is clearly WIP, not working, it's really just the beginning of a proof of concept which does not even really solve the problem: instead of having a dependency on msgcat, we have a dependency on libunistring.

@JulienPalard JulienPalard changed the title TypeError: argument of type 'WindowsPath' is not iterable powrap does not work on Windows Oct 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants