Enable ruff PTH (flake8-use-pathlib) and fix all findings

Replaces os.path/open()/os.stat()/os.chmod() calls with their Path
method equivalents across src, tests, misc, and bin, wrapping str
variables in Path(...) where they must stay str for other uses (e.g.
subprocess argv, CLI-arg formatting). helpers.safe_symlink() now
decodes StrOrBytesPath to a str Path via os.fsdecode() upfront, same
pattern already used elsewhere for the str|bytes union.
This commit is contained in:
James R. Barlow
2026-07-16 00:52:57 -07:00
parent e45c40b063
commit 089f46690a
22 changed files with 66 additions and 71 deletions
+2 -2
View File
@@ -74,11 +74,11 @@ class FixedRotateNoopOcrEngine(OcrEngine):
def generate_hocr(input_file, output_hocr, output_text, options):
with (
Image.open(input_file) as im,
open(output_hocr, 'w', encoding='utf-8') as f,
output_hocr.open('w', encoding='utf-8') as f,
):
w, h = im.size
f.write(HOCR_TEMPLATE.format(str(w), str(h)))
with open(output_text, 'w') as f:
with output_text.open('w') as f:
f.write('')
@staticmethod
+2 -2
View File
@@ -72,11 +72,11 @@ class NoopOcrEngine(OcrEngine):
def generate_hocr(input_file, output_hocr, output_text, options):
with (
Image.open(input_file) as im,
open(output_hocr, 'w', encoding='utf-8') as f,
output_hocr.open('w', encoding='utf-8') as f,
):
w, h = im.size
f.write(HOCR_TEMPLATE.format(str(w), str(h)))
with open(output_text, 'w') as f:
with output_text.open('w') as f:
f.write('')
@staticmethod