mirror of
https://github.com/ocrmypdf/OCRmyPDF.git
synced 2025-12-29 08:01:04 +00:00
Replace several uses of str(path) with fspath(path)
Helps make it more explicit. Did not do this to tests because use of paths is more involved there.
This commit is contained in:
parent
324598e992
commit
76e7e8dbbb
@ -29,8 +29,8 @@ def re_symlink(input_file, soft_link_name, log=None):
|
||||
"""
|
||||
Helper function: relinks soft symbolic link if necessary
|
||||
"""
|
||||
input_file = str(input_file) # For Py3.5
|
||||
soft_link_name = str(soft_link_name)
|
||||
input_file = fspath(input_file) # For Py3.5
|
||||
soft_link_name = fspath(soft_link_name)
|
||||
if log is None:
|
||||
prdebug = partial(print, file=sys.stderr)
|
||||
else:
|
||||
@ -108,14 +108,14 @@ def is_file_writable(test_file):
|
||||
# defaults to strict=False. This implements strict=False like behavior
|
||||
# for Python 3.5.
|
||||
if sys.version_info[0:2] <= (3, 5):
|
||||
p = Path(os.path.realpath(str(p)))
|
||||
p = Path(os.path.realpath(fspath(p)))
|
||||
else:
|
||||
p = p.resolve(strict=False)
|
||||
|
||||
# p.is_file() throws an exception in some cases
|
||||
if p.exists() and p.is_file():
|
||||
return os.access(
|
||||
str(p), os.W_OK,
|
||||
fspath(p), os.W_OK,
|
||||
effective_ids=(os.access in os.supports_effective_ids))
|
||||
else:
|
||||
try:
|
||||
|
||||
@ -39,7 +39,7 @@ PNG_QUALITY = (65, 75)
|
||||
|
||||
|
||||
def img_name(root, xref, ext):
|
||||
return str(root / '{:08d}{}'.format(xref, ext))
|
||||
return fspath(root / '{:08d}{}'.format(xref, ext))
|
||||
|
||||
|
||||
def png_name(root, xref):
|
||||
@ -193,7 +193,7 @@ def convert_to_jbig2(pike, jbig2_groups, root, log, options):
|
||||
prefix = 'group{:08d}'.format(group)
|
||||
future = executor.submit(
|
||||
jbig2enc.convert_group,
|
||||
cwd=str(root),
|
||||
cwd=fspath(root),
|
||||
infiles=(img_name(root, xref, ext) for xref, ext in xref_exts),
|
||||
out_prefix=prefix
|
||||
)
|
||||
@ -229,8 +229,8 @@ def transcode_jpegs(pike, jpegs, root, log, options):
|
||||
# DEBUG:PIL.Image:Error closing: 'NoneType' object has no attribute
|
||||
# 'close'. Seems to be mostly harmless
|
||||
# https://github.com/python-pillow/Pillow/issues/1144
|
||||
with Image.open(str(in_jpg)) as im:
|
||||
im.save(str(opt_jpg),
|
||||
with Image.open(fspath(in_jpg)) as im:
|
||||
im.save(fspath(opt_jpg),
|
||||
optimize=True,
|
||||
quality=JPEG_QUALITY)
|
||||
if opt_jpg.stat().st_size > in_jpg.stat().st_size:
|
||||
|
||||
@ -575,7 +575,7 @@ def _pdf_get_pageinfo(pdf, pageno: int, infile):
|
||||
|
||||
page = pdf.pages[pageno]
|
||||
|
||||
pageinfo['textinfo'] = _page_get_textblocks(str(infile), pageno)
|
||||
pageinfo['textinfo'] = _page_get_textblocks(fspath(infile), pageno)
|
||||
|
||||
mediabox = [Decimal(d) for d in page.MediaBox.as_list()]
|
||||
width_pt = mediabox[2] - mediabox[0]
|
||||
|
||||
@ -34,8 +34,7 @@ import sys
|
||||
@pytest.fixture
|
||||
def blank_hocr(tmpdir):
|
||||
filename = Path(str(tmpdir)) / "blank.hocr"
|
||||
with open(str(filename), 'w') as f:
|
||||
f.write(HOCR_TEMPLATE)
|
||||
filename.write_text(HOCR_TEMPLATE)
|
||||
return filename
|
||||
|
||||
|
||||
@ -50,6 +49,3 @@ def test_mono_image(blank_hocr, outdir):
|
||||
str(outdir / 'mono.pdf'), imageFileName=str(outdir / 'mono.tif'))
|
||||
|
||||
qpdf.check(str(outdir / 'mono.pdf'))
|
||||
|
||||
|
||||
|
||||
|
||||
@ -56,8 +56,8 @@ def check_monochrome_correlation(
|
||||
rasterize(reference_pdf, reference_pageno, reference_png)
|
||||
rasterize(test_pdf, test_pageno, test_png)
|
||||
|
||||
pix_ref = leptonica.Pix.read(str(reference_png))
|
||||
pix_test = leptonica.Pix.read(str(test_png))
|
||||
pix_ref = leptonica.Pix.open(reference_png)
|
||||
pix_test = leptonica.Pix.open(test_png)
|
||||
|
||||
return leptonica.Pix.correlation_binary(pix_ref, pix_test)
|
||||
|
||||
@ -127,7 +127,7 @@ def test_rotated_skew_timeout(resources, outpdf):
|
||||
timeout produced a page whose dimensions did not match the original's.
|
||||
"""
|
||||
|
||||
input_file = str(resources / 'rotated_skew.pdf')
|
||||
input_file = resources / 'rotated_skew.pdf'
|
||||
in_pageinfo = PdfInfo(input_file)[0]
|
||||
|
||||
assert in_pageinfo.height_pixels < in_pageinfo.width_pixels, \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user