Delinting
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -611,7 +611,7 @@ class Pix(LeptonicaObject):
|
||||
0,
|
||||
)
|
||||
)
|
||||
except (LeptonicaError, ValueError, IndexError) as e:
|
||||
except (LeptonicaError, ValueError, IndexError):
|
||||
return
|
||||
finally:
|
||||
with suppress(FileNotFoundError):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
import sys
|
||||
|
||||
import img2pdf
|
||||
from PIL import Image
|
||||
|
||||
"""Tesseract bad utf8 spoof
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from os import fspath
|
||||
from pickle import dumps, loads
|
||||
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -15,11 +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/>.
|
||||
|
||||
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
|
||||
|
||||
@@ -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):
|
||||
|
||||
+2
-4
@@ -16,19 +16,17 @@
|
||||
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user