1# FIXME: make gdk-pixbuf dependency optional
2{ stdenv
3, buildPythonPackage
4, pythonOlder
5, fetchPypi
6, lib
7, substituteAll
8, makeFontsConf
9, freefont_ttf
10, pikepdf
11, pytest
12, glibcLocales
13, cairo
14, cffi
15, numpy
16, withXcffib ? false
17, xcffib
18, python
19, glib
20, gdk-pixbuf
21}:
22
23buildPythonPackage rec {
24 pname = "cairocffi";
25 version = "1.4.0";
26
27 disabled = pythonOlder "3.5";
28
29 src = fetchPypi {
30 inherit pname version;
31 hash = "sha256-UJM5syzNjXsAwiBMMnNs3njbU6MuahYtMSR40lYmzZo=";
32 };
33
34 patches = [
35 # OSError: dlopen() failed to load a library: gdk-pixbuf-2.0 / gdk-pixbuf-2.0-0
36 (substituteAll {
37 src = ./dlopen-paths.patch;
38 ext = stdenv.hostPlatform.extensions.sharedLibrary;
39 cairo = cairo.out;
40 glib = glib.out;
41 gdk_pixbuf = gdk-pixbuf.out;
42 })
43 ./fix_test_scaled_font.patch
44 ];
45
46 postPatch = ''
47 substituteInPlace setup.cfg \
48 --replace "pytest-runner" "" \
49 --replace "pytest-cov" "" \
50 --replace "pytest-flake8" "" \
51 --replace "pytest-isort" "" \
52 --replace "--flake8 --isort" ""
53 '';
54
55 LC_ALL = "en_US.UTF-8";
56
57 # checkPhase require at least one 'normal' font and one 'monospace',
58 # otherwise glyph tests fails
59 FONTCONFIG_FILE = makeFontsConf {
60 fontDirectories = [ freefont_ttf ];
61 };
62
63 propagatedNativeBuildInputs = [ cffi ];
64
65 propagatedBuildInputs = [ cairo cffi ]
66 ++ lib.optional withXcffib xcffib;
67
68 # pytestCheckHook does not work
69 nativeCheckInputs = [ numpy pikepdf pytest glibcLocales ];
70
71 checkPhase = ''
72 py.test $out/${python.sitePackages}
73 '';
74
75 meta = with lib; {
76 homepage = "https://github.com/SimonSapin/cairocffi";
77 license = licenses.bsd3;
78 maintainers = with maintainers; [ SuperSandro2000 ];
79 description = "cffi-based cairo bindings for Python";
80 };
81}