diff --git a/setup.py b/setup.py
index c046cd8d..443a6023 100644
--- a/setup.py
+++ b/setup.py
@@ -24,11 +24,12 @@ if sys.version_info < (3, 6):
print("Python 3.6 or newer is required", file=sys.stderr)
sys.exit(1)
-from setuptools import setup, find_packages # nopep8
-from subprocess import STDOUT, check_output, CalledProcessError # nopep8
-from collections.abc import Mapping # nopep8
-import re # nopep8
+from setuptools import setup, find_packages
+from subprocess import STDOUT, check_output, CalledProcessError
+from collections.abc import Mapping
+import re
+# pylint: disable=w0613
missing_program = '''
The program '{program}' could not be executed or was not found on your
@@ -131,10 +132,11 @@ def check_external_program(
program,
need_version,
package,
- version_check_args=['--version'],
+ version_check_args=None,
version_scrape_regex=re.compile(r'(\d+\.\d+(?:\.\d+)?)'),
optional=False):
-
+ if not version_check_args:
+ version_check_args = ['--version']
print(f'Checking for {program} >= {need_version}...')
try:
result = check_output(
diff --git a/src/ocrmypdf/_pipeline.py b/src/ocrmypdf/_pipeline.py
index 8ec40f71..16b0e279 100644
--- a/src/ocrmypdf/_pipeline.py
+++ b/src/ocrmypdf/_pipeline.py
@@ -581,7 +581,6 @@ def select_ocr_image(infiles, output_file, log, context):
with Image.open(image) as im:
from PIL import ImageColor
from PIL import ImageDraw
- from decimal import Decimal
white = ImageColor.getcolor('#ffffff', im.mode)
# pink = ImageColor.getcolor('#ff0080', im.mode)
@@ -800,8 +799,6 @@ def get_docinfo(base_pdf, options):
def generate_postscript_stub(input_file, output_file, log, context):
- options = context.get_options()
- pdf = pikepdf.open(input_file)
generate_pdfa_ps(output_file)
diff --git a/src/ocrmypdf/leptonica.py b/src/ocrmypdf/leptonica.py
index 99630d0c..0cc8b643 100644
--- a/src/ocrmypdf/leptonica.py
+++ b/src/ocrmypdf/leptonica.py
@@ -611,7 +611,7 @@ class Pix(LeptonicaObject):
0,
)
)
- except (LeptonicaError, ValueError, IndexError) as e:
+ except (LeptonicaError, ValueError, IndexError):
return
finally:
with suppress(FileNotFoundError):
diff --git a/src/ocrmypdf/optimize.py b/src/ocrmypdf/optimize.py
index 8d388dba..49b087ac 100644
--- a/src/ocrmypdf/optimize.py
+++ b/src/ocrmypdf/optimize.py
@@ -148,7 +148,7 @@ def extract_image_generic(*, pike, root, log, image, xref, options):
def extract_images(pike, root, log, options, extract_fn):
"""Extract image using extract_fn
- extract_fn decides where the image is interesting in this case
+ extract_fn decides whether the image is interesting in this case
"""
include_xrefs = set()
diff --git a/src/ocrmypdf/pdfinfo/layout.py b/src/ocrmypdf/pdfinfo/layout.py
index 9b2b60a9..e6d04c9c 100644
--- a/src/ocrmypdf/pdfinfo/layout.py
+++ b/src/ocrmypdf/pdfinfo/layout.py
@@ -25,25 +25,11 @@ import pdfminer.pdfdevice
import pdfminer.pdfinterp
from pdfminer.converter import PDFLayoutAnalyzer
from pdfminer.glyphlist import glyphname2unicode
-from pdfminer.layout import (
- LAParams,
- LTChar,
- LTContainer,
- LTLayoutContainer,
- LTPage,
- LTTextBox,
- LTTextLine,
-)
+from pdfminer.layout import LAParams, LTChar, LTPage, LTTextBox
from pdfminer.pdfdocument import PDFTextExtractionNotAllowed
-from pdfminer.pdffont import (
- PDFCIDFont,
- PDFFont,
- PDFSimpleFont,
- PDFType3Font,
- PDFUnicodeNotDefined,
-)
+from pdfminer.pdffont import PDFFont, PDFSimpleFont, PDFUnicodeNotDefined
from pdfminer.pdfpage import PDFPage
-from pdfminer.utils import bbox2str, fsplit, matrix2str
+from pdfminer.utils import bbox2str, matrix2str
from ..exceptions import EncryptedPdfError
@@ -161,11 +147,21 @@ class LTStateAwareChar(LTChar):
text,
textwidth,
textdisp,
+ ncs,
+ graphicstate,
textstate,
- *args,
):
super().__init__(
- matrix, font, fontsize, scaling, rise, text, textwidth, textdisp, *args
+ matrix,
+ font,
+ fontsize,
+ scaling,
+ rise,
+ text,
+ textwidth,
+ textdisp,
+ ncs,
+ graphicstate,
)
self.rendermode = textstate.render
@@ -223,11 +219,13 @@ class TextPositionTracker(PDFLayoutAnalyzer):
self.pageno += 1
self.receive_layout(self.cur_item)
- def render_string(self, textstate, seq, *args):
+ def render_string(self, textstate, seq, ncs, graphicstate):
self.textstate = textstate.copy()
- super().render_string(self.textstate, seq, *args)
+ super().render_string(self.textstate, seq, ncs, graphicstate)
- def render_char(self, matrix, font, fontsize, scaling, rise, cid, *args):
+ def render_char(
+ self, matrix, font, fontsize, scaling, rise, cid, ncs, graphicstate
+ ):
try:
text = font.to_unichr(cid)
assert isinstance(text, str), str(type(text))
@@ -244,8 +242,9 @@ class TextPositionTracker(PDFLayoutAnalyzer):
text,
textwidth,
textdisp,
+ ncs,
+ graphicstate,
self.textstate,
- *args,
)
self.cur_item.add(item)
return item.adv
diff --git a/tests/spoof/tesseract_badutf8.py b/tests/spoof/tesseract_badutf8.py
index e38a7cf5..ba21bb17 100755
--- a/tests/spoof/tesseract_badutf8.py
+++ b/tests/spoof/tesseract_badutf8.py
@@ -22,8 +22,6 @@
import sys
-import img2pdf
-from PIL import Image
"""Tesseract bad utf8 spoof
diff --git a/tests/spoof/tesseract_crash.py b/tests/spoof/tesseract_crash.py
index 0ad89909..8b6f90d8 100755
--- a/tests/spoof/tesseract_crash.py
+++ b/tests/spoof/tesseract_crash.py
@@ -20,7 +20,6 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-import os
import signal
import sys
diff --git a/tests/test_lept.py b/tests/test_lept.py
index 1f643625..142fc702 100644
--- a/tests/test_lept.py
+++ b/tests/test_lept.py
@@ -16,9 +16,6 @@
# along with OCRmyPDF. If not, see .
-import os
-import shutil
-import sys
from os import fspath
from pickle import dumps, loads
diff --git a/tests/test_main.py b/tests/test_main.py
index f428de90..79c50749 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -600,7 +600,7 @@ def test_closed_streams(spoof_tesseract_noop, ocrmypdf_exec, resources, outpdf):
os.close(1)
p_args = ocrmypdf_exec + [input_file, output_file]
- p = Popen(
+ p = Popen( # pylint: disable=subprocess-popen-preexec-fn
p_args,
close_fds=True,
stdout=None,
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
index 27528093..201ae8bb 100644
--- a/tests/test_metadata.py
+++ b/tests/test_metadata.py
@@ -27,7 +27,6 @@ import pytest
import pikepdf
from ocrmypdf.exceptions import ExitCode
-from ocrmypdf.exec import ghostscript
from ocrmypdf.pdfa import SRGB_ICC_PROFILE, file_claims_pdfa, generate_pdfa_ps
from pikepdf.models.metadata import decode_pdf_date
diff --git a/tests/test_optimize.py b/tests/test_optimize.py
index f73cd60c..e2eef80b 100644
--- a/tests/test_optimize.py
+++ b/tests/test_optimize.py
@@ -27,7 +27,7 @@ from ocrmypdf import optimize as opt
from ocrmypdf.exec import jbig2enc, pngquant
from ocrmypdf.exec.ghostscript import rasterize_pdf
-check_ocrmypdf = pytest.helpers.check_ocrmypdf
+check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=e1101
@pytest.mark.parametrize('pdf', ['multipage.pdf', 'palette.pdf'])
diff --git a/tests/test_pdfinfo.py b/tests/test_pdfinfo.py
index 087e9fed..a4ab14f6 100644
--- a/tests/test_pdfinfo.py
+++ b/tests/test_pdfinfo.py
@@ -15,11 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see .
-import os
import pickle
-import shutil
-import sys
-from contextlib import suppress
from math import isclose
from tempfile import NamedTemporaryFile
@@ -32,6 +28,8 @@ import pikepdf
from ocrmypdf import pdfinfo
from ocrmypdf.pdfinfo import Colorspace, Encoding
+# pylint: disable=protected-access
+
def test_single_page_text(outdir):
filename = outdir / 'text.pdf'
@@ -185,7 +183,7 @@ def test_ocr_detection(resources):
@pytest.mark.parametrize(
'testfile', ('truetype_font_nomapping.pdf', 'type3_font_nomapping.pdf')
)
-@pytest.helpers.needs_pdfminer
+@pytest.helpers.needs_pdfminer # pylint: disable=e1101
def test_corrupt_font_detection(resources, testfile):
try:
import pdfminer
diff --git a/tests/test_rotation.py b/tests/test_rotation.py
index 3447570a..bfcf3dae 100644
--- a/tests/test_rotation.py
+++ b/tests/test_rotation.py
@@ -152,7 +152,7 @@ def test_autorotate_threshold(
test_pdf=outdir / 'out.pdf',
test_pageno=3,
)
- assert eval(correlation_test)
+ assert eval(correlation_test) # pylint: disable=w0123
def test_rotated_skew_timeout(resources, outpdf):
diff --git a/tests/test_tess4.py b/tests/test_tess4.py
index afd5b1dc..7720d16b 100644
--- a/tests/test_tess4.py
+++ b/tests/test_tess4.py
@@ -16,19 +16,17 @@
# along with OCRmyPDF. If not, see .
import os
-import sys
from contextlib import contextmanager
from os import fspath
from pathlib import Path
-import PyPDF2 as pypdf
import pytest
from ocrmypdf import pdfinfo
-from ocrmypdf.exceptions import ExitCode, MissingDependencyError
+from ocrmypdf.exceptions import MissingDependencyError
from ocrmypdf.exec import tesseract
-# pylint: disable=no-member
+# pylint: disable=no-member,w0621
spoof = pytest.helpers.spoof