1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 substituteAll,
6 isPyPy,
7 python,
8 setuptools,
9 pillow,
10 pycairo,
11 pkg-config,
12 boost,
13 cairo,
14 harfbuzz,
15 icu,
16 libjpeg,
17 libpng,
18 libtiff,
19 libwebp,
20 mapnik,
21 proj,
22 zlib,
23 libxml2,
24 sqlite,
25 pytestCheckHook,
26 darwin,
27 sparsehash,
28}:
29
30buildPythonPackage rec {
31 pname = "python-mapnik";
32 version = "3.0.16-unstable-2024-02-22";
33 pyproject = true;
34
35 src = fetchFromGitHub {
36 owner = "mapnik";
37 repo = "python-mapnik";
38 rev = "5ab32f0209909cc98c26e1d86ce0c8ef29a9bf3d";
39 hash = "sha256-OqijA1WcyBcyWO8gntqp+xNIaV1Jqa0n1eMDip2OCvY=";
40 # Only needed for test data
41 fetchSubmodules = true;
42 };
43
44 patches = [
45 # python-mapnik seems to depend on having the mapnik src directory
46 # structure available at build time. We just hardcode the paths.
47 (substituteAll {
48 src = ./find-libmapnik.patch;
49 libmapnik = "${mapnik}/lib";
50 })
51 # Use `std::optional` rather than `boost::optional`
52 # https://github.com/mapnik/python-mapnik/commit/e9f88a95a03dc081826a69da67bbec3e4cccd5eb
53 ./python-mapnik_std_optional.patch
54 ];
55
56 stdenv = if python.stdenv.isDarwin then darwin.apple_sdk_11_0.stdenv else python.stdenv;
57
58 build-system = [ setuptools ];
59
60 nativeBuildInputs = [
61 mapnik # for mapnik_config
62 pkg-config
63 ];
64
65 dependencies = [
66 mapnik
67 boost
68 cairo
69 harfbuzz
70 icu
71 libjpeg
72 libpng
73 libtiff
74 libwebp
75 proj
76 zlib
77 libxml2
78 sqlite
79 sparsehash
80 ];
81
82 propagatedBuildInputs = [
83 pillow
84 pycairo
85 ];
86
87 configureFlags = [ "XMLPARSER=libxml2" ];
88
89 disabled = isPyPy;
90
91 preBuild = ''
92 export BOOST_PYTHON_LIB="boost_python${"${lib.versions.major python.version}${lib.versions.minor python.version}"}"
93 export BOOST_THREAD_LIB="boost_thread"
94 export BOOST_SYSTEM_LIB="boost_system"
95 export PYCAIRO=true
96 export XMLPARSER=libxml2
97 '';
98
99 nativeCheckInputs = [ pytestCheckHook ];
100
101 preCheck =
102 ''
103 # import from $out
104 rm -r mapnik
105 ''
106 + lib.optionalString stdenv.isDarwin ''
107 # Replace the hardcoded /tmp references with $TMPDIR
108 sed -i "s,/tmp,$TMPDIR,g" test/python_tests/*.py
109 '';
110
111 # https://github.com/mapnik/python-mapnik/issues/255
112 disabledTests = [
113 "test_geometry_type"
114 "test_passing_pycairo_context_pdf"
115 "test_pdf_printing"
116 "test_render_with_scale_factor"
117 ] ++ lib.optionals stdenv.isDarwin [
118 "test_passing_pycairo_context_png"
119 "test_passing_pycairo_context_svg"
120 "test_pycairo_pdf_surface1"
121 "test_pycairo_pdf_surface2"
122 "test_pycairo_pdf_surface3"
123 "test_pycairo_svg_surface1"
124 "test_pycairo_svg_surface2"
125 "test_pycairo_svg_surface3"
126 ];
127
128 pythonImportsCheck = [ "mapnik" ];
129
130 meta = with lib; {
131 description = "Python bindings for Mapnik";
132 maintainers = [ ];
133 homepage = "https://mapnik.org";
134 license = licenses.lgpl21Plus;
135 };
136}