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 =
57 if python.stdenv.hostPlatform.isDarwin then darwin.apple_sdk_11_0.stdenv else python.stdenv;
58
59 build-system = [ setuptools ];
60
61 nativeBuildInputs = [
62 mapnik # for mapnik_config
63 pkg-config
64 ];
65
66 dependencies = [
67 mapnik
68 boost
69 cairo
70 harfbuzz
71 icu
72 libjpeg
73 libpng
74 libtiff
75 libwebp
76 proj
77 zlib
78 libxml2
79 sqlite
80 sparsehash
81 ];
82
83 propagatedBuildInputs = [
84 pillow
85 pycairo
86 ];
87
88 configureFlags = [ "XMLPARSER=libxml2" ];
89
90 disabled = isPyPy;
91
92 preBuild = ''
93 export BOOST_PYTHON_LIB="boost_python${"${lib.versions.major python.version}${lib.versions.minor python.version}"}"
94 export BOOST_THREAD_LIB="boost_thread"
95 export BOOST_SYSTEM_LIB="boost_system"
96 export PYCAIRO=true
97 export XMLPARSER=libxml2
98 '';
99
100 nativeCheckInputs = [ pytestCheckHook ];
101
102 preCheck =
103 ''
104 # import from $out
105 rm -r mapnik
106 ''
107 + lib.optionalString stdenv.hostPlatform.isDarwin ''
108 # Replace the hardcoded /tmp references with $TMPDIR
109 sed -i "s,/tmp,$TMPDIR,g" test/python_tests/*.py
110 '';
111
112 # https://github.com/mapnik/python-mapnik/issues/255
113 disabledTests =
114 [
115 "test_geometry_type"
116 "test_passing_pycairo_context_pdf"
117 "test_pdf_printing"
118 "test_render_with_scale_factor"
119 ]
120 ++ lib.optionals stdenv.hostPlatform.isDarwin [
121 "test_passing_pycairo_context_png"
122 "test_passing_pycairo_context_svg"
123 "test_pycairo_pdf_surface1"
124 "test_pycairo_pdf_surface2"
125 "test_pycairo_pdf_surface3"
126 "test_pycairo_svg_surface1"
127 "test_pycairo_svg_surface2"
128 "test_pycairo_svg_surface3"
129 ];
130
131 pythonImportsCheck = [ "mapnik" ];
132
133 meta = with lib; {
134 description = "Python bindings for Mapnik";
135 maintainers = [ ];
136 homepage = "https://mapnik.org";
137 license = licenses.lgpl21Plus;
138 broken = true; # At 2024-11-13, test_raster_warping fails.
139 };
140}