From 790ff58f675bab850fca41a8ac0c2918bc8dbd96 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 7 May 2020 22:19:21 -0700 Subject: [PATCH] Add fix for bug in Windows Python 3.6/3.7 TypeError: argument of type 'WindowsPath' is not iterable --- docs/api.rst | 4 ++-- src/ocrmypdf/exec/__init__.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index b724b116..ce6583fc 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -56,8 +56,8 @@ OCRmyPDF does not. On Windows, the script that calls ``ocrmypdf.ocr()`` must be protected by an "ifmain" guard (``if __name__ == '__main__'``) or you must use ``ocrmypdf.ocr(...use_threads=True)``. If you do not take at least one - of these steps, Windows fork semantics will prevent OCRmyPDF from working - correct. + of these steps, Windows process semantics will prevent OCRmyPDF from working + correctly. Logging ------- diff --git a/src/ocrmypdf/exec/__init__.py b/src/ocrmypdf/exec/__init__.py index 80e6ba98..d400820f 100644 --- a/src/ocrmypdf/exec/__init__.py +++ b/src/ocrmypdf/exec/__init__.py @@ -94,6 +94,11 @@ def run(args, *, env=None, **kwargs): def fix_windows_args(program, args, env): """Adjust our desired program and command line arguments for use on Windows""" + if sys.version_info < (3, 8): + # bpo-33617 - Windows needs manual Path -> str conversion + args = [os.fspath(arg) for arg in args] + program = os.fspath(program) + # If we are running a .py on Windows, ensure we call it with this Python # (to support test suite shims) if program.lower().endswith('.py'):