Delinting

This commit is contained in:
James R. Barlow
2021-04-07 02:09:45 -07:00
parent aa115a8be3
commit 173a80864d
18 changed files with 36 additions and 28 deletions
+1 -3
View File
@@ -4,10 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import threading
from abc import ABC, abstractmethod
from functools import partial
from typing import Callable, Iterable, Optional
@@ -128,7 +126,7 @@ class SerialExecutor(Executor):
task: Callable,
task_arguments: Iterable,
task_finished: Callable,
):
): # pylint: disable=unused-argument
with self.pbar_class(**tqdm_kwargs) as pbar:
for args in task_arguments:
result = task(args)
+1 -1
View File
@@ -20,7 +20,7 @@ MAX_REPLACE_PAGES = 100
def _ensure_dictionary(obj, name):
if name not in obj:
obj[name] = pikepdf.Dictionary({})
obj[name] = Dictionary({})
return obj[name]
+6 -6
View File
@@ -13,7 +13,7 @@ from contextlib import suppress
from datetime import datetime, timezone
from pathlib import Path
from shutil import copyfileobj
from typing import BinaryIO, Dict, Iterable, Optional, Union, cast
from typing import Dict, Iterable, Optional
import img2pdf
import pikepdf
@@ -162,10 +162,10 @@ def get_pdfinfo(
check_pages=check_pages,
executor=executor,
)
except pikepdf.PasswordError:
raise EncryptedPdfError()
except pikepdf.PdfError:
raise InputFileError()
except pikepdf.PasswordError as e:
raise EncryptedPdfError() from e
except pikepdf.PdfError as e:
raise InputFileError() from e
def validate_pdfinfo_options(context: PdfContext):
@@ -839,7 +839,7 @@ def optimize_pdf(input_file: Path, context: PdfContext, executor: Executor):
def enumerate_compress_ranges(iterable):
skipped_from = None
skipped_from, index = None, None
for index, txt_file in enumerate(iterable):
index += 1
if txt_file:
+1 -1
View File
@@ -65,7 +65,7 @@ from ocrmypdf.pdfa import file_claims_pdfa
log = logging.getLogger(__name__)
class PageResult(NamedTuple):
class PageResult(NamedTuple): # pylint: disable=inherit-non-class
pageno: int
pdf_page_from_image: Optional[Path]
ocr: Optional[Path]
+1 -1
View File
@@ -22,7 +22,7 @@ import threading
from contextlib import suppress
from multiprocessing import Pool as ProcessPool
from multiprocessing.pool import ThreadPool
from typing import Callable, Iterable, Optional, Union
from typing import Callable, Iterable, Union
from tqdm import tqdm
@@ -8,5 +8,7 @@ from ocrmypdf import hookimpl
@hookimpl
def filter_pdf_page(page, image_filename, output_pdf):
def filter_pdf_page(
page, image_filename, output_pdf
): # pylint: disable=unused-argument
return output_pdf
+4 -1
View File
@@ -10,7 +10,7 @@ from argparse import ArgumentParser, Namespace
from collections import namedtuple
from logging import Handler
from pathlib import Path
from typing import TYPE_CHECKING, AbstractSet, Callable, Iterable, List, Optional
from typing import TYPE_CHECKING, AbstractSet, List, Optional
import pluggy
@@ -20,9 +20,12 @@ from ocrmypdf.helpers import Resolution
if TYPE_CHECKING:
from PIL import Image
# pylint: disable=ungrouped-imports
from ocrmypdf._jobcontext import PageContext
from ocrmypdf.pdfinfo import PdfInfo
# pylint: enable=ungrouped-imports
hookspec = pluggy.HookspecMarker('ocrmypdf')
# pylint: disable=unused-argument
+2
View File
@@ -13,6 +13,8 @@ import ocrmypdf
from .conftest import check_ocrmypdf
# pylint: disable=redefined-outer-name
@pytest.fixture
def acroform(resources):
+1 -1
View File
@@ -16,7 +16,7 @@ from ocrmypdf._exec.ghostscript import rasterize_pdf
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.helpers import Resolution
from .conftest import check_ocrmypdf, run_ocrmypdf, run_ocrmypdf_api
from .conftest import check_ocrmypdf, run_ocrmypdf
# pylint: disable=redefined-outer-name
+2 -1
View File
@@ -12,7 +12,7 @@ from unittest.mock import MagicMock
import pytest
from ocrmypdf import helpers as helpers
from ocrmypdf import helpers
from .conftest import running_in_docker
@@ -100,6 +100,7 @@ class TestFileIsWritable:
@pytest.mark.skipif(os.name != 'nt', reason="Windows test")
def test_shim_paths(tmp_path):
# pylint: disable=import-outside-toplevel
from ocrmypdf.subprocess._windows import shim_env_path
progfiles = tmp_path / 'Program Files'
+2
View File
@@ -16,6 +16,8 @@ import ocrmypdf
from .conftest import check_ocrmypdf, run_ocrmypdf_api
# pylint: disable=redefined-outer-name
@pytest.fixture
def baiona(resources):
+1 -1
View File
@@ -143,7 +143,7 @@ def test_multiple_pngs(resources, outdir):
outputstream=inpdf,
)
def mockquant(input_file, output_file, *args):
def mockquant(input_file, output_file, *_args):
with Image.open(input_file) as im:
draw = ImageDraw.Draw(im)
draw.rectangle((0, 0, im.width, im.height), fill=128)
+1 -1
View File
@@ -15,7 +15,7 @@ from ocrmypdf.helpers import Resolution
from ocrmypdf.leptonica import Pix
from ocrmypdf.pdfinfo import PdfInfo
from .conftest import check_ocrmypdf, have_unpaper, run_ocrmypdf, run_ocrmypdf_api
from .conftest import check_ocrmypdf, have_unpaper
RENDERERS = ['hocr', 'sandwich']
+4 -4
View File
@@ -89,7 +89,7 @@ def test_monochrome_correlation(resources, outdir):
def test_autorotate(renderer, resources, outdir):
# cardinal.pdf contains four copies of an image rotated in each cardinal
# direction - these ones are "burned in" not tagged with /Rotate
out = check_ocrmypdf(
check_ocrmypdf(
resources / 'cardinal.pdf',
outdir / 'out.pdf',
'-r',
@@ -119,7 +119,7 @@ def test_autorotate(renderer, resources, outdir):
],
)
def test_autorotate_threshold(threshold, correlation_test, resources, outdir):
out = check_ocrmypdf(
check_ocrmypdf(
resources / 'cardinal.pdf',
outdir / 'out.pdf',
'--rotate-pages-threshold',
@@ -131,14 +131,14 @@ def test_autorotate_threshold(threshold, correlation_test, resources, outdir):
'tests/plugins/tesseract_cache.py',
)
correlation = check_monochrome_correlation(
correlation = check_monochrome_correlation( # pylint: disable=unused-variable
outdir,
reference_pdf=resources / 'cardinal.pdf',
reference_pageno=1,
test_pdf=outdir / 'out.pdf',
test_pageno=3,
)
assert eval(correlation_test) # pylint: disable=w0123
assert eval(correlation_test) # pylint: disable=eval-used
def test_rotated_skew_timeout(resources, outpdf):
+1 -1
View File
@@ -17,7 +17,7 @@ from ocrmypdf import pdfinfo
from ocrmypdf._exec import tesseract
from ocrmypdf.exceptions import MissingDependencyError
from .conftest import check_ocrmypdf, run_ocrmypdf
from .conftest import check_ocrmypdf
# pylint: disable=redefined-outer-name
+2 -2
View File
@@ -71,7 +71,7 @@ def test_unpaper_args_valid(resources, outpdf):
@pytest.mark.skipif(not have_unpaper(), reason="requires unpaper")
def test_unpaper_args_invalid_filename(resources, outpdf):
p, out, err = run_ocrmypdf(
p, _out, err = run_ocrmypdf(
resources / "skew.pdf",
outpdf,
"-c",
@@ -86,7 +86,7 @@ def test_unpaper_args_invalid_filename(resources, outpdf):
@pytest.mark.skipif(not have_unpaper(), reason="requires unpaper")
def test_unpaper_args_invalid(resources, outpdf):
p, out, err = run_ocrmypdf(
p, _out, _err = run_ocrmypdf(
resources / "skew.pdf",
outpdf,
"-c",
+1 -1
View File
@@ -12,7 +12,7 @@ import pytest
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.pdfinfo import PdfInfo
from .conftest import check_ocrmypdf, run_ocrmypdf, run_ocrmypdf_api
from .conftest import check_ocrmypdf, run_ocrmypdf_api
# pylint: disable=redefined-outer-name
+2 -2
View File
@@ -6,7 +6,7 @@
import logging
from unittest.mock import MagicMock, patch
from unittest.mock import patch
import pikepdf
import pytest
@@ -194,7 +194,7 @@ def test_no_progress_bar(progress_bar, resources):
def test_language_warning(caplog):
opts = make_opts(language=None)
plugin_manager = get_plugin_manager(opts.plugins)
_plugin_manager = get_plugin_manager(opts.plugins)
caplog.set_level(logging.DEBUG)
with patch(
'ocrmypdf._validation.locale.getlocale', return_value=('en_US', 'UTF-8')