Pillow sucks

Far from being fluffy or friendly, Pillow silently allows installation
of itself without support for major image types.  Reportlab calls for
pillow 2.4.0.  On Ubuntu 14.04 LTS this will trigger an upgrade of
pillow that will be built without JPEG or ZLIB so it is effectively
neutered, and unfortunately Pillow will not detect this situation at
install time and guide users to a resolution.  Instead, you see nasty
stack traces.

So add a run-time check to ensure that Pillow is sane and capable of JPEG
and PNG support since both may be used internally.
This commit is contained in:
James R. Barlow 2015-08-16 00:54:03 -07:00
parent eb04a890b2
commit 30072e0c70
2 changed files with 37 additions and 2 deletions

View File

@ -63,6 +63,41 @@ if tesseract.version() < MINIMUM_TESS_VERSION:
sys.exit(ExitCode.missing_dependency)
try:
import PIL.features
check_codec = PIL.features.check_codec
except (ImportError, AttributeError):
def check_codec(codec_name):
if codec_name == 'jpg':
return 'jpeg_encoder' in dir(Image.core)
elif codec_name == 'zlib':
return 'zip_encoder' in dir(Image.core)
raise NotImplementedError(codec_name)
def check_pil_encoder(codec_name, friendly_name):
try:
if check_codec(codec_name):
return
except Exception:
pass
complain(
"ERROR: Your version of the Python imaging library (Pillow) was "
"compiled without support for " + friendly_name + " encoding/decoding."
"\n"
"You will need to uninstall Pillow and reinstall it with PNG and JPEG "
"support (libjpeg and zlib)."
"\n"
"See installation instructions for your platform here:\n"
" https://pillow.readthedocs.org/installation.html"
)
sys.exit(ExitCode.missing_dependency)
check_pil_encoder('jpg', 'JPEG')
check_pil_encoder('zlib', 'PNG')
# -------------
# Parser

View File

@ -202,12 +202,12 @@ setup(
],
install_requires=[
'ruffus>=2.6.3',
'Pillow>=2.3',
'Pillow>=2.4.0',
'lxml>=3.3.3',
'reportlab>=3.1.44',
'PyPDF2>=1.25.1'
],
test_requires=[
tests_require=[
'img2pdf>=0.1.5',
'pytest>=2.7.2'
],