From f82479eff274c1888947a83c6c3ca5d424a175af Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Thu, 12 Dec 2024 13:21:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Use=20our=20own=20removesuffix()?= =?UTF-8?q?=20as=20we=20still=20support=20Python=203.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dinglehopper/cli_line_dirs.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dinglehopper/cli_line_dirs.py b/src/dinglehopper/cli_line_dirs.py index 43e4f1a..30b2be1 100644 --- a/src/dinglehopper/cli_line_dirs.py +++ b/src/dinglehopper/cli_line_dirs.py @@ -14,6 +14,11 @@ from .word_error_rate import word_error_rate_n, words_normalized def removesuffix(text, suffix): + """ + Remove suffix from text. + + Can be replaced with str.removesuffix when we only support Python >= 3.9. + """ if suffix and text.endswith(suffix): return text[: -len(suffix)] return text @@ -59,7 +64,7 @@ def find_gt_and_ocr_files(gt_dir, gt_suffix, ocr_dir, ocr_suffix) -> Iterator[Tu for gt_fn in find_all_files(gt_dir, lambda fn: fn.endswith(gt_suffix)): ocr_fn = os.path.join( ocr_dir, - os.path.relpath(gt_fn, start=gt_dir).removesuffix(gt_suffix) + removesuffix(os.path.relpath(gt_fn, start=gt_dir), gt_suffix) + ocr_suffix, ) if not os.path.exists(ocr_fn):