pythonPackages.pillow: Convert to generic

This commit is contained in:
Sandro Jäckel 2021-01-01 06:43:07 +01:00
parent 8ac8a860b9
commit 84df5df735
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5
3 changed files with 83 additions and 124 deletions

View File

@ -1,75 +1,22 @@
{ lib, stdenv, buildPythonPackage, fetchPypi, isPyPy { lib, stdenv, buildPythonPackage, fetchPypi, isPyPy, isPy3k
, olefile , olefile, freetype, libjpeg, zlib, libtiff, libwebp, tcl, lcms2, tk, libX11
, freetype, libjpeg, zlib, libtiff, libwebp, tcl, lcms2, tk, libX11 , openjpeg, libimagequant, pyroma, numpy, pytestCheckHook
, openjpeg, libimagequant }@args:
, pytest, pytestrunner, pyroma, numpy
}:
buildPythonPackage rec { import ./generic.nix (rec {
pname = "Pillow"; pname = "Pillow";
version = "6.2.2"; version = "6.2.2";
disabled = !isPy3k;
src = fetchPypi { src = fetchPypi {
inherit pname version; inherit pname version;
sha256 = "0l5rv8jkdrb5q846v60v03mcq64yrhklidjkgwv6s1pda71g17yv"; sha256 = "0l5rv8jkdrb5q846v60v03mcq64yrhklidjkgwv6s1pda71g17yv";
}; };
# Disable imagefont tests, because they don't work well with infinality:
# https://github.com/python-pillow/Pillow/issues/1259
postPatch = ''
rm Tests/test_imagefont.py
'';
checkPhase = ''
runHook preCheck
python -m pytest -v -x -W always${lib.optionalString stdenv.isDarwin " --deselect=Tests/test_file_icns.py::TestFileIcns::test_save --deselect=Tests/test_imagegrab.py::TestImageGrab::test_grab"}
runHook postCheck
'';
propagatedBuildInputs = [ olefile ];
checkInputs = [ pytest pytestrunner pyroma numpy ];
buildInputs = [
freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
++ lib.optionals (isPyPy) [ tk libX11 ];
# NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
# NOTE: The Pillow install script will, by default, add paths like /usr/lib
# and /usr/include to the search paths. This can break things when building
# on a non-NixOS system that has some libraries installed that are not
# installed in Nix (for example, Arch Linux has jpeg2000 but Nix doesn't
# build Pillow with this support). We patch the `disable_platform_guessing`
# setting here, instead of passing the `--disable-platform-guessing`
# command-line option, since the command-line option doesn't work when we run
# tests.
preConfigure = let
libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
in ''
sed -i "setup.py" \
-e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
s|^JPEG2K_ROOT =.*$|JPEG2K_ROOT = ${libinclude openjpeg}|g ;
s|^IMAGEQUANT_ROOT =.*$|IMAGEQUANT_ROOT = ${libinclude' libimagequant}|g ;
s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;
s|self\.disable_platform_guessing = None|self.disable_platform_guessing = True|g ;'
export LDFLAGS="-L${libwebp}/lib"
export CFLAGS="-I${libwebp}/include"
''
# Remove impurities
+ lib.optionalString stdenv.isDarwin ''
substituteInPlace setup.py \
--replace '"/Library/Frameworks",' "" \
--replace '"/System/Library/Frameworks"' ""
'';
meta = with lib; { meta = with lib; {
homepage = "https://python-pillow.github.io/"; homepage = "https://python-pillow.org/";
description = "Fork of The Python Imaging Library (PIL)"; description = "The friendly PIL fork (Python Imaging Library)";
longDescription = '' longDescription = ''
The Python Imaging Library (PIL) adds image processing The Python Imaging Library (PIL) adds image processing
capabilities to your Python interpreter. This library capabilities to your Python interpreter. This library
@ -77,6 +24,6 @@ buildPythonPackage rec {
processing and graphics capabilities. processing and graphics capabilities.
''; '';
license = "http://www.pythonware.com/products/pil/license.htm"; license = "http://www.pythonware.com/products/pil/license.htm";
maintainers = with maintainers; [ goibhniu prikhi ]; maintainers = with maintainers; [ goibhniu prikhi SuperSandro2000 ];
}; };
} } // args )

View File

@ -1,12 +1,9 @@
{ lib, stdenv, buildPythonPackage, fetchPypi, isPyPy { lib, stdenv, buildPythonPackage, fetchPypi, isPyPy, isPy3k
, olefile , olefile, freetype, libjpeg, zlib, libtiff, libwebp, tcl, lcms2, tk, libX11
, freetype, libjpeg, zlib, libtiff, libwebp, tcl, lcms2, tk, libX11 , openjpeg, libimagequant, pyroma, numpy, pytestCheckHook
, openjpeg, libimagequant }@args:
, pyroma, numpy, pytestCheckHook
, isPy3k
}:
buildPythonPackage rec { import ./generic.nix (rec {
pname = "Pillow"; pname = "Pillow";
version = "8.0.1"; version = "8.0.1";
@ -17,56 +14,6 @@ buildPythonPackage rec {
sha256 = "11c5c6e9b02c9dac08af04f093eb5a2f84857df70a7d4a6a6ad461aca803fb9e"; sha256 = "11c5c6e9b02c9dac08af04f093eb5a2f84857df70a7d4a6a6ad461aca803fb9e";
}; };
# Disable imagefont tests, because they don't work well with infinality:
# https://github.com/python-pillow/Pillow/issues/1259
postPatch = ''
rm Tests/test_imagefont.py
'';
# Disable darwin tests which require executables: `iconutil` and `screencapture`
disabledTests = lib.optionals stdenv.isDarwin [ "test_save" "test_grab" "test_grabclipboard" ];
propagatedBuildInputs = [ olefile ];
checkInputs = [ pytestCheckHook pyroma numpy ];
buildInputs = [
freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
++ lib.optionals (isPyPy) [ tk libX11 ];
# NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
# NOTE: The Pillow install script will, by default, add paths like /usr/lib
# and /usr/include to the search paths. This can break things when building
# on a non-NixOS system that has some libraries installed that are not
# installed in Nix (for example, Arch Linux has jpeg2000 but Nix doesn't
# build Pillow with this support). We patch the `disable_platform_guessing`
# setting here, instead of passing the `--disable-platform-guessing`
# command-line option, since the command-line option doesn't work when we run
# tests.
preConfigure = let
libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
in ''
sed -i "setup.py" \
-e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
s|^JPEG2K_ROOT =.*$|JPEG2K_ROOT = ${libinclude openjpeg}|g ;
s|^IMAGEQUANT_ROOT =.*$|IMAGEQUANT_ROOT = ${libinclude' libimagequant}|g ;
s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;
s|self\.disable_platform_guessing = None|self.disable_platform_guessing = True|g ;'
export LDFLAGS="-L${libwebp}/lib"
export CFLAGS="-I${libwebp}/include"
''
# Remove impurities
+ lib.optionalString stdenv.isDarwin ''
substituteInPlace setup.py \
--replace '"/Library/Frameworks",' "" \
--replace '"/System/Library/Frameworks"' ""
'';
meta = with lib; { meta = with lib; {
homepage = "https://python-pillow.org/"; homepage = "https://python-pillow.org/";
description = "The friendly PIL fork (Python Imaging Library)"; description = "The friendly PIL fork (Python Imaging Library)";
@ -77,6 +24,6 @@ buildPythonPackage rec {
processing and graphics capabilities. processing and graphics capabilities.
''; '';
license = "http://www.pythonware.com/products/pil/license.htm"; license = "http://www.pythonware.com/products/pil/license.htm";
maintainers = with maintainers; [ goibhniu prikhi ]; maintainers = with maintainers; [ goibhniu prikhi SuperSandro2000 ];
}; };
} } // args )

View File

@ -0,0 +1,65 @@
{ pname
, version
, disabled
, src
, meta
, ...
}@args:
with args;
buildPythonPackage rec {
inherit pname version src meta;
# Disable imagefont tests, because they don't work well with infinality:
# https://github.com/python-pillow/Pillow/issues/1259
postPatch = ''
rm Tests/test_imagefont.py
'';
# Disable darwin tests which require executables: `iconutil` and `screencapture`
disabledTests = lib.optionals stdenv.isDarwin [
"test_grab"
"test_grabclipboard"
"test_save"
];
propagatedBuildInputs = [ olefile ];
checkInputs = [ pytestCheckHook pyroma numpy ];
buildInputs = [ freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
++ lib.optionals (isPyPy) [ tk libX11 ];
# NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
# NOTE: The Pillow install script will, by default, add paths like /usr/lib
# and /usr/include to the search paths. This can break things when building
# on a non-NixOS system that has some libraries installed that are not
# installed in Nix (for example, Arch Linux has jpeg2000 but Nix doesn't
# build Pillow with this support). We patch the `disable_platform_guessing`
# setting here, instead of passing the `--disable-platform-guessing`
# command-line option, since the command-line option doesn't work when we run
# tests.
preConfigure = let
libinclude' = pkg: ''"${pkg.out}/lib", "${pkg.out}/include"'';
libinclude = pkg: ''"${pkg.out}/lib", "${pkg.dev}/include"'';
in ''
sed -i "setup.py" \
-e 's|^FREETYPE_ROOT =.*$|FREETYPE_ROOT = ${libinclude freetype}|g ;
s|^JPEG_ROOT =.*$|JPEG_ROOT = ${libinclude libjpeg}|g ;
s|^JPEG2K_ROOT =.*$|JPEG2K_ROOT = ${libinclude openjpeg}|g ;
s|^IMAGEQUANT_ROOT =.*$|IMAGEQUANT_ROOT = ${libinclude' libimagequant}|g ;
s|^ZLIB_ROOT =.*$|ZLIB_ROOT = ${libinclude zlib}|g ;
s|^LCMS_ROOT =.*$|LCMS_ROOT = ${libinclude lcms2}|g ;
s|^TIFF_ROOT =.*$|TIFF_ROOT = ${libinclude libtiff}|g ;
s|^TCL_ROOT=.*$|TCL_ROOT = ${libinclude' tcl}|g ;
s|self\.disable_platform_guessing = None|self.disable_platform_guessing = True|g ;'
export LDFLAGS="$LDFLAGS -L${libwebp}/lib"
export CFLAGS="$CFLAGS -I${libwebp}/include"
'' + lib.optionalString stdenv.isDarwin ''
# Remove impurities
substituteInPlace setup.py \
--replace '"/Library/Frameworks",' "" \
--replace '"/System/Library/Frameworks"' ""
'';
}