Allow the olefile dependency to be optional

Support for plugins requiring olefile will not be loaded if it is not
installed. Allows library consumers to avoid installing this dependency
if they choose. Some library consumers have little interest in the
format support and would like to keep dependencies to a minimum.
This commit is contained in:
Jon Dufresne 2017-10-04 06:34:56 -07:00
parent 1d18a5cfef
commit 9175706300
4 changed files with 17 additions and 4 deletions

View File

@ -1,8 +1,14 @@
from helper import unittest, PillowTestCase
from PIL import FpxImagePlugin
try:
from PIL import FpxImagePlugin
except ImportError:
olefile_installed = False
else:
olefile_installed = True
@unittest.skipUnless(olefile_installed, "olefile package not installed")
class TestFileFpx(PillowTestCase):
def test_invalid_file(self):

View File

@ -1,10 +1,18 @@
from helper import unittest, PillowTestCase, hopper
from PIL import Image, ImagePalette, MicImagePlugin
from PIL import Image, ImagePalette
try:
from PIL import MicImagePlugin
except ImportError:
olefile_installed = False
else:
olefile_installed = True
TEST_FILE = "Tests/images/hopper.mic"
@unittest.skipUnless(olefile_installed, "olefile package not installed")
class TestFileMic(PillowTestCase):
def test_sanity(self):

View File

@ -15,6 +15,7 @@ docutils
jarn.viewdoc
nose-cov
nose
olefile
pep8
pyflakes
pyroma

View File

@ -780,7 +780,6 @@ try:
include_package_data=True,
packages=find_packages(),
scripts=glob.glob("Scripts/*.py"),
install_requires=['olefile'],
test_suite='nose.collector',
keywords=["Imaging", ],
license='Standard PIL License',
@ -806,4 +805,3 @@ which was requested by the option flag --enable-%s
""" % (str(err), str(err))
sys.stderr.write(msg)
raise DependencyException(msg)