Pre-release delinting

This commit is contained in:
James R. Barlow
2020-06-09 15:27:14 -07:00
parent fe156db41d
commit 64891c2fc3
22 changed files with 29 additions and 46 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ ON_SUCCESS_DELETE = bool(os.getenv('OCR_ON_SUCCESS_DELETE', ''))
DESKEW = bool(os.getenv('OCR_DESKEW', ''))
OCR_JSON_SETTINGS = json.loads(os.getenv('OCR_JSON_SETTINGS', '{}'))
POLL_NEW_FILE_SECONDS = int(os.getenv('OCR_POLL_NEW_FILE_SECONDS', '1'))
USE_POLLING = bool(os.getenv('OCR_USE_POLLING', False))
USE_POLLING = bool(os.getenv('OCR_USE_POLLING', ''))
LOGLEVEL = os.getenv('OCR_LOGLEVEL', 'INFO').upper()
PATTERNS = ['*.pdf']
+1 -2
View File
@@ -26,14 +26,13 @@ from ocrmypdf._plugin_manager import get_parser_options_plugins
from ocrmypdf._sync import run_pipeline
from ocrmypdf._validation import check_closed_streams, check_options
from ocrmypdf.api import Verbosity, configure_logging
from ocrmypdf.cli import get_parser, plugins_only_parser
from ocrmypdf.exceptions import BadArgsError, ExitCode, MissingDependencyError
log = logging.getLogger('ocrmypdf')
def run(args=None):
parser, options, plugin_manager = get_parser_options_plugins(args=args)
_parser, options, plugin_manager = get_parser_options_plugins(args=args)
if not check_closed_streams(options):
return ExitCode.bad_args
+1 -3
View File
@@ -21,11 +21,10 @@ import logging
import os
import shutil
from collections import namedtuple
from contextlib import suppress
from os import fspath
from pathlib import Path
from subprocess import PIPE, STDOUT, CalledProcessError, TimeoutExpired
from typing import List, Optional
from typing import List
from PIL import Image
@@ -34,7 +33,6 @@ from ocrmypdf.exceptions import (
SubprocessOutputError,
TesseractConfigError,
)
from ocrmypdf.helpers import safe_symlink
from ocrmypdf.subprocess import get_version, run
log = logging.getLogger(__name__)
+1 -1
View File
@@ -28,7 +28,7 @@ from pikepdf.models.metadata import encode_pdf_date
from PIL import Image, ImageColor, ImageDraw
from ocrmypdf import leptonica
from ocrmypdf._exec import ghostscript, unpaper
from ocrmypdf._exec import unpaper
from ocrmypdf._version import PROGRAM_NAME
from ocrmypdf._version import __version__ as VERSION
from ocrmypdf.exceptions import (
+1 -1
View File
@@ -61,7 +61,7 @@ def get_parser_options_plugins(
plugin_manager = get_plugin_manager(pre_options.plugins)
parser = get_parser()
plugin_manager.hook.add_options(parser=parser)
plugin_manager.hook.add_options(parser=parser) # pylint: disable=no-member
options = parser.parse_args(args=args)
return parser, options, plugin_manager
+1 -2
View File
@@ -15,14 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import inspect
import logging
import os
import sys
from argparse import ArgumentParser
from enum import IntEnum
from pathlib import Path
from typing import Dict, Iterable
from typing import Iterable
from ocrmypdf._logging import PageNumberFilter, TqdmConsole
from ocrmypdf._plugin_manager import get_plugin_manager
@@ -16,13 +16,11 @@
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import logging
from pathlib import Path
from ocrmypdf import hookimpl
from ocrmypdf._exec import ghostscript
from ocrmypdf._validation import HOCR_OK_LANGS
from ocrmypdf.exceptions import MissingDependencyError
from ocrmypdf.helpers import Resolution
from ocrmypdf.subprocess import check_external_program
log = logging.getLogger(__name__)
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
+2 -2
View File
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
from abc import ABC, abstractstaticmethod
from abc import ABC, abstractmethod, abstractstaticmethod
from argparse import ArgumentParser, Namespace
from collections import namedtuple
from pathlib import Path
@@ -134,7 +134,7 @@ class OcrEngine(ABC):
def creator_tag(options: Namespace) -> str:
"""Returns the creator tag to identify this software's role in creating the PDF."""
@abstractstaticmethod
@abstractmethod
def __str__(self):
"""Returns name of OCR engine and version."""
+1 -2
View File
@@ -15,7 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import ast
import os
import platform
import sys
@@ -24,7 +23,7 @@ from subprocess import PIPE, run
import pytest
from ocrmypdf import api, cli, pdfinfo
from ocrmypdf import api, pdfinfo
from ocrmypdf._exec import unpaper
from ocrmypdf._plugin_manager import get_parser_options_plugins
-1
View File
@@ -25,7 +25,6 @@ from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess import run
def raise_gs_fail(*args, **kwargs):
-2
View File
@@ -19,13 +19,11 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import patch
from ocrmypdf import hookimpl
from ocrmypdf.builtin_plugins import ghostscript
from ocrmypdf.subprocess import run
def raise_gs_fail(*args, **kwargs):
-1
View File
@@ -20,7 +20,6 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import signal
import sys
from subprocess import CalledProcessError
from unittest.mock import patch
+9 -7
View File
@@ -26,9 +26,11 @@ from ocrmypdf._exec.ghostscript import rasterize_pdf
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.helpers import Resolution
check_ocrmypdf = pytest.helpers.check_ocrmypdf
run_ocrmypdf = pytest.helpers.run_ocrmypdf
run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api
check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=no-member
run_ocrmypdf = pytest.helpers.run_ocrmypdf # pylint: disable=no-member
run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api # pylint: disable=no-member
# pylint: disable=redefined-outer-name
@pytest.fixture
@@ -37,7 +39,7 @@ def francais(resources):
return path, pikepdf.open(path)
def test_rasterize_size(francais, outdir, caplog):
def test_rasterize_size(francais, outdir):
path, pdf = francais
page_size_pts = (pdf.pages[0].MediaBox[2], pdf.pages[0].MediaBox[3])
assert pdf.pages[0].MediaBox[0] == pdf.pages[0].MediaBox[1] == 0
@@ -86,7 +88,7 @@ def test_rasterize_rotated(francais, outdir, caplog):
def test_gs_render_failure(resources, outpdf):
p, out, err = run_ocrmypdf(
p, _out, err = run_ocrmypdf(
resources / 'blank.pdf',
outpdf,
'--plugin',
@@ -99,7 +101,7 @@ def test_gs_render_failure(resources, outpdf):
def test_gs_raster_failure(resources, outpdf):
p, out, err = run_ocrmypdf(
p, _out, err = run_ocrmypdf(
resources / 'francais.pdf',
outpdf,
'--plugin',
@@ -112,7 +114,7 @@ def test_gs_raster_failure(resources, outpdf):
def test_ghostscript_pdfa_failure(resources, outpdf):
p, out, err = run_ocrmypdf(
p, _out, _err = run_ocrmypdf(
resources / 'francais.pdf',
outpdf,
'--plugin',
-1
View File
@@ -18,7 +18,6 @@
import logging
import multiprocessing
import os
from pathlib import Path
from unittest.mock import MagicMock
import pytest
-2
View File
@@ -15,8 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
from pathlib import Path
import pytest
from PIL import Image
+2 -4
View File
@@ -17,7 +17,6 @@
import pickle
from math import isclose
from tempfile import NamedTemporaryFile
import img2pdf
import pikepdf
@@ -26,7 +25,6 @@ from PIL import Image
from reportlab.pdfgen.canvas import Canvas
from ocrmypdf import pdfinfo
from ocrmypdf._exec import ghostscript
from ocrmypdf.pdfinfo import Colorspace, Encoding
# pylint: disable=protected-access
@@ -110,7 +108,7 @@ def test_single_page_inline_image(outdir):
assert pdfimage.width == 8
def test_jpeg(resources, outdir):
def test_jpeg(resources):
filename = resources / 'c02-22.pdf'
pdf = pdfinfo.PdfInfo(filename)
@@ -133,7 +131,7 @@ def test_no_contents(resources):
pdf = pdfinfo.PdfInfo(filename)
assert len(pdf[0].images) == 0
assert pdf[0].has_text == False
assert not pdf[0].has_text
def test_oversized_page(resources):
-2
View File
@@ -15,10 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import logging
from io import BytesIO
from os import fspath
from unittest.mock import Mock
import img2pdf
import pikepdf
+3 -3
View File
@@ -18,7 +18,7 @@
import os
import sys
from pathlib import Path
from subprocess import DEVNULL, PIPE, CalledProcessError, Popen, run
from subprocess import DEVNULL, PIPE, Popen, run
import pytest
@@ -95,7 +95,7 @@ def test_closed_streams(ocrmypdf_exec, resources, outpdf):
stdin=None,
preexec_fn=evil_closer,
)
out, err = p.communicate()
_out, err = p.communicate()
print(err.decode())
assert p.returncode == ExitCode.ok
@@ -121,7 +121,7 @@ def test_dev_null(resources):
if 'COV_CORE_DATAFILE' in os.environ:
pytest.skip(msg="Coverage uses stdout")
p, out, err = run_ocrmypdf(
p, out, _err = run_ocrmypdf(
resources / 'trivial.pdf',
os.devnull,
'--force-ocr',
-1
View File
@@ -22,7 +22,6 @@ import pytest
from ocrmypdf._plugin_manager import get_parser_options_plugins
from ocrmypdf._validation import check_options
from ocrmypdf.cli import get_parser
from ocrmypdf.exceptions import ExitCode, MissingDependencyError
# pytest.helpers is dynamic
+5 -3
View File
@@ -22,9 +22,11 @@ import pytest
from ocrmypdf.exceptions import ExitCode
from ocrmypdf.pdfinfo import PdfInfo
check_ocrmypdf = pytest.helpers.check_ocrmypdf
run_ocrmypdf = pytest.helpers.run_ocrmypdf
run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api
check_ocrmypdf = pytest.helpers.check_ocrmypdf # pylint: disable=no-member
run_ocrmypdf = pytest.helpers.run_ocrmypdf # pylint: disable=no-member
run_ocrmypdf_api = pytest.helpers.run_ocrmypdf_api # pylint: disable=no-member
# pylint: disable=redefined-outer-name
@pytest.fixture
+1 -2
View File
@@ -16,7 +16,6 @@
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
import logging
import os
from unittest.mock import patch
import pikepdf
@@ -35,7 +34,7 @@ def make_opts_pm(input_file='a.pdf', output_file='b.pdf', language='eng', **kwar
kwargs['language'] = language
parser = get_parser()
pm = get_plugin_manager(kwargs.get('plugins', []))
pm.hook.add_options(parser=parser)
pm.hook.add_options(parser=parser) # pylint: disable=no-member
return (
create_options(
input_file=input_file, output_file=output_file, parser=parser, **kwargs