Make pdfminer.six optional
Mainly since the current release of pdfminer.six lacks a sdist, blocking homebrew packaging. Also in case other distros don't accept pdfminer.six.
This commit is contained in:
+20
@@ -74,6 +74,25 @@ matrix:
|
||||
- qpdf
|
||||
- tesseract
|
||||
- unpaper
|
||||
- os: osx
|
||||
osx_image: xcode9.2
|
||||
language: generic
|
||||
env:
|
||||
- ADD_PDFMINER=1
|
||||
addons:
|
||||
homebrew:
|
||||
update: true
|
||||
packages:
|
||||
- exempi
|
||||
- ghostscript
|
||||
- jbig2enc
|
||||
- leptonica
|
||||
- openjpeg
|
||||
- pngquant
|
||||
- python
|
||||
- qpdf
|
||||
- tesseract
|
||||
- unpaper
|
||||
|
||||
before_cache:
|
||||
- rm -f $HOME/.cache/pip/log/debug.log
|
||||
@@ -98,6 +117,7 @@ install:
|
||||
- pip3 install pycparser # py3.7 workaround for https://github.com/eliben/pycparser/issues/251
|
||||
- pip3 install -r requirements/main.txt
|
||||
- pip3 install --no-deps .
|
||||
- '[[ "$ADD_PDFMINER" == "1" ]] && pip3 install .[pdfminer]'
|
||||
- pip3 install -r requirements/test.txt
|
||||
|
||||
script:
|
||||
|
||||
@@ -250,7 +250,7 @@ setup(
|
||||
'chardet >= 3.0.4, < 4', # unlisted requirement of pdfminer.six 20181108
|
||||
'cffi >= 1.9.1', # must be a setup and install requirement
|
||||
'img2pdf >= 0.3.0, < 0.4', # pure Python, so track HEAD closely
|
||||
'pdfminer.six == 20181108',
|
||||
'pdfminer.six == 20181108 ; sys_platform != "darwin"',
|
||||
'pikepdf >= 0.10.0, < 0.11.0',
|
||||
'Pillow >= 4.0.0, != 5.1.0 ; sys_platform == "darwin"',
|
||||
# Pillow < 4 has BytesIO/TIFF bug w/img2pdf 0.2.3
|
||||
@@ -259,7 +259,7 @@ setup(
|
||||
'ruffus >= 2.7.0',
|
||||
],
|
||||
extras_require={
|
||||
'fitz': [], # Backward compatibility
|
||||
'pdfminer': ['pdfminer.six == 20181108'],
|
||||
},
|
||||
tests_require=tests_require,
|
||||
entry_points={
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -30,9 +30,8 @@ from pikepdf import PdfMatrix
|
||||
import pikepdf
|
||||
|
||||
from . import ghosttext
|
||||
from .layout import get_page_analysis, get_text_boxes
|
||||
|
||||
from ..exceptions import EncryptedPdfError
|
||||
from ..exceptions import EncryptedPdfError, MissingDependencyError
|
||||
|
||||
|
||||
Colorspace = Enum('Colorspace', 'gray rgb cmyk lab icc index sep devn pattern jpeg2000')
|
||||
@@ -533,12 +532,12 @@ def _page_has_text(text_blocks, page_width, page_height):
|
||||
return has_text
|
||||
|
||||
|
||||
def simplify_textboxes(miner):
|
||||
def simplify_textboxes(miner, textbox_getter):
|
||||
"""Extract only limited content from text boxes
|
||||
|
||||
We do this to save memory and ensure that our objects are pickleable.
|
||||
"""
|
||||
for box in get_text_boxes(miner):
|
||||
for box in textbox_getter(miner):
|
||||
first_line = box._objs[0]
|
||||
first_char = first_line._objs[0]
|
||||
|
||||
@@ -563,9 +562,17 @@ def _pdf_get_pageinfo(pdf, pageno: int, infile, xmltext):
|
||||
)
|
||||
pageinfo['bboxes'] = bboxes
|
||||
else:
|
||||
# pdfminer required for this section
|
||||
try:
|
||||
from .layout import get_page_analysis, get_text_boxes
|
||||
except ImportError:
|
||||
raise MissingDependencyError(
|
||||
"pdfminer is required for this feature. Your distribution "
|
||||
"may not have installed it."
|
||||
)
|
||||
pscript5_mode = str(pdf.docinfo.get('/Creator')).startswith('PScript5')
|
||||
miner = get_page_analysis(infile, pageno, pscript5_mode)
|
||||
pageinfo['textboxes'] = list(simplify_textboxes(miner))
|
||||
pageinfo['textboxes'] = list(simplify_textboxes(miner, get_text_boxes))
|
||||
bboxes = (box.bbox for box in pageinfo['textboxes'])
|
||||
|
||||
pageinfo['has_text'] = _page_has_text(bboxes, width_pt, height_pt)
|
||||
|
||||
@@ -62,6 +62,16 @@ def running_in_travis():
|
||||
return os.environ.get('TRAVIS') == 'true'
|
||||
|
||||
|
||||
@pytest.helpers.register
|
||||
def needs_pdfminer(fn):
|
||||
try:
|
||||
import pdfminer
|
||||
except ImportError:
|
||||
skip = pytest.mark.skipif(True, reason="pdfminer not available")
|
||||
return skip(fn)
|
||||
return fn
|
||||
|
||||
|
||||
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||
SPOOF_PATH = os.path.join(TESTS_ROOT, 'spoof')
|
||||
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
|
||||
|
||||
@@ -219,6 +219,7 @@ def test_skip_ocr(spoof_tesseract_cache, resources, outpdf):
|
||||
assert pdfinfo[0].has_text
|
||||
|
||||
|
||||
@pytest.helpers.needs_pdfminer
|
||||
def test_redo_ocr(spoof_tesseract_cache, resources, outpdf):
|
||||
in_ = resources / 'graph_ocred.pdf'
|
||||
before = PdfInfo(in_, detailed_page_analysis=True)
|
||||
|
||||
@@ -182,10 +182,16 @@ def test_ocr_detection(resources):
|
||||
assert pdf[0].has_text
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'testfile', ('truetype_font_nomapping.pdf', 'type3_font_nomapping.pdf')
|
||||
)
|
||||
@pytest.helpers.needs_pdfminer
|
||||
def test_corrupt_font_detection(resources, testfile):
|
||||
try:
|
||||
import pdfminer
|
||||
except ImportError:
|
||||
pytest.skip("Needs pdfminer")
|
||||
filename = resources / testfile
|
||||
with pytest.raises(NotImplementedError):
|
||||
pdf = pdfinfo.PdfInfo(filename)
|
||||
|
||||
Reference in New Issue
Block a user