diff --git a/misc/synology.py b/misc/synology.py index d9547559..fe45b797 100644 --- a/misc/synology.py +++ b/misc/synology.py @@ -2,6 +2,8 @@ # SPDX-FileCopyrightText: 2017 Enantiomerie # SPDX-License-Identifier: MIT +"""Example OCRmyPDF for Synology NAS""" + from __future__ import annotations # This script must be edited to meet your needs. @@ -25,10 +27,7 @@ logging.basicConfig( filemode='w', ) -if len(sys.argv) > 1: - start_dir = sys.argv[1] -else: - start_dir = '.' +start_dir = sys.argv[1] if len(sys.argv) > 1 else '.' for dir_name, _subdirs, file_list in os.walk(start_dir): logging.info(dir_name) diff --git a/src/ocrmypdf/builtin_plugins/concurrency.py b/src/ocrmypdf/builtin_plugins/concurrency.py index dabdd6dc..3c53b3e7 100644 --- a/src/ocrmypdf/builtin_plugins/concurrency.py +++ b/src/ocrmypdf/builtin_plugins/concurrency.py @@ -1,9 +1,9 @@ # SPDX-FileCopyrightText: 2022 James R. Barlow # SPDX-License-Identifier: MPL-2.0 -from __future__ import annotations - """OCRmyPDF's multiprocessing/multithreading abstraction layer.""" +from __future__ import annotations + import logging import logging.handlers import multiprocessing diff --git a/src/ocrmypdf/pdfinfo/info.py b/src/ocrmypdf/pdfinfo/info.py index 1430af12..305b2e80 100644 --- a/src/ocrmypdf/pdfinfo/info.py +++ b/src/ocrmypdf/pdfinfo/info.py @@ -17,16 +17,7 @@ from functools import partial from math import hypot, inf, isclose from os import PathLike from pathlib import Path -from typing import ( - Container, - Iterable, - Iterator, - Mapping, - NamedTuple, - Optional, - Sequence, - Tuple, -) +from typing import Container, Iterable, Iterator, Mapping, NamedTuple, Sequence, Tuple from warnings import warn from pikepdf import ( diff --git a/src/ocrmypdf/pdfinfo/layout.py b/src/ocrmypdf/pdfinfo/layout.py index c5785522..d586fbfe 100644 --- a/src/ocrmypdf/pdfinfo/layout.py +++ b/src/ocrmypdf/pdfinfo/layout.py @@ -1,5 +1,7 @@ # SPDX-FileCopyrightText: 2022 James R. Barlow # SPDX-License-Identifier: MPL-2.0 +"""Detailed text position and layout analysis, building on pdfminer.six.""" + from __future__ import annotations import re @@ -23,14 +25,14 @@ from ocrmypdf.exceptions import EncryptedPdfError, InputFileError STRIP_NAME = re.compile(r'[0-9]+') -original_PDFSimpleFont_init = PDFSimpleFont.__init__ +original_pdfsimplefont_init = PDFSimpleFont.__init__ -def PDFSimpleFont__init__(self, descriptor, widths, spec): +def pdfsimplefont__init__(self, descriptor, widths, spec): # Font encoding is specified either by a name of # built-in encoding or a dictionary that describes # the differences. - original_PDFSimpleFont_init(self, descriptor, widths, spec) + original_pdfsimplefont_init(self, descriptor, widths, spec) # pdfminer is incorrect. If there is no ToUnicode and no Encoding, do not # assume Unicode conversion is possible. RM 9.10.2 if not self.unicode_map and 'Encoding' not in spec: @@ -38,25 +40,25 @@ def PDFSimpleFont__init__(self, descriptor, widths, spec): return -PDFSimpleFont.__init__ = PDFSimpleFont__init__ +PDFSimpleFont.__init__ = pdfsimplefont__init__ # # pdfminer patches when creator is PScript5.dll # -def PDFType3Font__PScript5_get_height(self): +def pdftype3font__pscript5_get_height(self): h = self.bbox[3] - self.bbox[1] if h == 0: h = self.ascent - self.descent return h * copysign(1.0, self.vscale) -def PDFType3Font__PScript5_get_descent(self): +def pdftype3font__pscript5_get_descent(self): return self.descent * copysign(1.0, self.vscale) -def PDFType3Font__PScript5_get_ascent(self): +def pdftype3font__pscript5_get_ascent(self): return self.ascent * copysign(1.0, self.vscale) @@ -132,14 +134,14 @@ class LTStateAwareChar(LTChar): return self._text def __repr__(self): - return '<{} {} matrix={} rendermode={!r} font={!r} adv={} text={!r}>'.format( - self.__class__.__name__, - bbox2str(self.bbox), - matrix2str(self.matrix), - self.rendermode, - self.fontname, - self.adv, - self.get_text(), + return ( + f"<{self.__class__.__name__} " + f"{bbox2str(self.bbox)} " + f"matrix={matrix2str(self.matrix)} " + f"rendermode={self.rendermode!r} " + f"font={self.fontname!r} " + f"adv={self.adv} " + f"text={self.get_text()!r}>" ) @@ -221,9 +223,9 @@ def get_page_analysis(infile, pageno, pscript5_mode): patcher = patch.multiple( 'pdfminer.pdffont.PDFType3Font', spec=True, - get_ascent=PDFType3Font__PScript5_get_ascent, - get_descent=PDFType3Font__PScript5_get_descent, - get_height=PDFType3Font__PScript5_get_height, + get_ascent=pdftype3font__pscript5_get_ascent, + get_descent=pdftype3font__pscript5_get_descent, + get_height=pdftype3font__pscript5_get_height, ) patcher.start() diff --git a/tests/test_optimize.py b/tests/test_optimize.py index 5717269e..b2ad9bfe 100644 --- a/tests/test_optimize.py +++ b/tests/test_optimize.py @@ -27,6 +27,9 @@ needs_jbig2enc = pytest.mark.skipif( ) +# pylint:disable=redefined-outer-name + + @pytest.fixture(scope="session") def palette(resources): return resources / 'palette.pdf'