From 9175706300dc431fd8573305a1ef8e78fd55bc21 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 4 Oct 2017 06:34:56 -0700 Subject: [PATCH] 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. --- Tests/test_file_fpx.py | 8 +++++++- Tests/test_file_mic.py | 10 +++++++++- requirements.txt | 1 + setup.py | 2 -- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index a7c2f0c3b..441a3e635 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -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): diff --git a/Tests/test_file_mic.py b/Tests/test_file_mic.py index 44be9a475..fb37a5caa 100644 --- a/Tests/test_file_mic.py +++ b/Tests/test_file_mic.py @@ -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): diff --git a/requirements.txt b/requirements.txt index 4a946a64c..40985400e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ docutils jarn.viewdoc nose-cov nose +olefile pep8 pyflakes pyroma diff --git a/setup.py b/setup.py index 4948faf1a..487e8d6ba 100755 --- a/setup.py +++ b/setup.py @@ -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) -