Repository: spack/spack

Issue:
py-pillow fails test after building extension
The py-pillow package fails tests after building the extension. Here is the information from the build log:

```
=================================== FAILURES ===================================
_________________________ TestFilePalm.test_monochrome _________________________


self = <Tests.test_file_palm.TestFilePalm testMethod=test_monochrome>


    def test_monochrome(self):
        # Arrange
        mode = "1"
    
        # Act / Assert
        self.helper_save_as_palm(mode)
>       self.roundtrip(mode)


Tests/test_file_palm.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
Tests/test_file_palm.py:30: in roundtrip
    self.assert_image_equal(converted, im)
Tests/helper.py:105: in assert_image_equal
    a.mode, b.mode, msg or "got mode {!r}, expected {!r}".format(a.mode, b.mode)
E   AssertionError: 'P' != '1'
E   - P
E   + 1
E    : got mode 'P', expected '1' 
```



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-pillow/package.py b/var/spack/repos/builtin/packages/py-pillow/package.py
--- a/var/spack/repos/builtin/packages/py-pillow/package.py
+++ b/var/spack/repos/builtin/packages/py-pillow/package.py
@@ -61,6 +61,7 @@ class PyPillow(PythonPackage):
     depends_on('libwebp', when='+webp')
     depends_on('libwebp+libwebpmux+libwebpdemux', when='+webpmux')
     depends_on('openjpeg', when='+jpeg2000')
+    depends_on('imagemagick', type='test')
 
     # Spack does not (yet) support these modes of building
     # depends_on('libimagequant', when='+imagequant')
@@ -86,21 +87,25 @@ def patch(self):
         setup.filter('include_dirs = []',
                      'include_dirs = {0}'.format(include_dirs), string=True)
 
-    def build_ext_args(self, spec, prefix):
-        def variant_to_flag(variant):
-            able = 'enable' if '+' + variant in spec else 'disable'
-            return '--{0}-{1}'.format(able, variant)
-
-        args = ['--enable-zlib', '--enable-jpeg']
-
-        variants = ['tiff', 'freetype', 'lcms', 'webp', 'webpmux', 'jpeg2000']
-        args.extend(list(map(variant_to_flag, variants)))
-
-        # Spack does not (yet) support these modes of building
-        args.append('--disable-imagequant')
-
-        args.append('--rpath={0}'.format(':'.join(self.rpath)))
-        return args
+        def variant_to_cfg(setup):
+            able = 'enable' if '+' + variant in self.spec else 'disable'
+            return '{0}-{1}=1\n'.format(able, variant)
+
+        with open('setup.cfg', 'a') as setup:
+            # Default backend
+            setup.write('[build_ext]\n')
+            setup.write('enable-zlib=1\n')
+            setup.write('enable-jpeg=1\n')
+            variants = ['tiff', 'freetype', 'lcms', 'webp',
+                        'webpmux', 'jpeg2000']
+            for variant in variants:
+                setup.write(variant_to_cfg(setup))
+
+            # Spack does not (yet) support these modes of building
+            setup.write('disable-imagequant=1\n')
+
+            setup.write('rpath={0}\n'.format(':'.join(self.rpath)))
+            setup.write('[install]\n')
 
     # Tests need to be re-added since `phases` was overridden
     run_after('build_ext')(


Test patch: