From a757325efb060c26cf761638238411db7ffd7f66 Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Fri, 29 Dec 2023 08:26:02 -0800 Subject: [PATCH 1/2] Fix problem with ZIP paths on Windows. Fixes #181. --- propka/input.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/propka/input.py b/propka/input.py index 6925d4c..a9ebc18 100644 --- a/propka/input.py +++ b/propka/input.py @@ -38,9 +38,11 @@ def open_file_for_reading(input_file: _TextIOSource) -> ContextManager[IO[str]]: if not input_file.is_file(): for p in input_file.parents: if not zipfile.is_zipfile(p): + print(f"Parent {p} is not ZIP file.") continue zf = zipfile.ZipFile(p) - stream = zf.open(str(input_file.relative_to(p))) + path_string = "/".join(input_file.relative_to(p).parts) + stream = zf.open(path_string) return io.TextIOWrapper(stream) return contextlib.closing(open(input_file, 'rt')) From 8659f0372e3160da7f48ab40daf7ccd99fc29b0a Mon Sep 17 00:00:00 2001 From: Nathan Baker Date: Sat, 30 Dec 2023 15:25:46 -0800 Subject: [PATCH 2/2] Clean up POSIX path conversion. Replace `str.join` with `Path.as_posix`. --- propka/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/propka/input.py b/propka/input.py index a9ebc18..6a67052 100644 --- a/propka/input.py +++ b/propka/input.py @@ -41,7 +41,7 @@ def open_file_for_reading(input_file: _TextIOSource) -> ContextManager[IO[str]]: print(f"Parent {p} is not ZIP file.") continue zf = zipfile.ZipFile(p) - path_string = "/".join(input_file.relative_to(p).parts) + path_string = Path.as_posix(input_file.relative_to(p)) stream = zf.open(path_string) return io.TextIOWrapper(stream)