1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 fetchpatch,
6 substituteAll,
7 isPyPy,
8 python,
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 nose,
26 pytestCheckHook,
27 stdenv,
28}:
29
30buildPythonPackage rec {
31 pname = "python-mapnik";
32 version = "unstable-2023-02-23";
33 format = "setuptools";
34
35 src = fetchFromGitHub {
36 owner = "mapnik";
37 repo = "python-mapnik";
38 # Use proj6 branch in order to support Proj >= 6 (excluding commits after 2023-02-23)
39 # https://github.com/mapnik/python-mapnik/compare/master...proj6
40 rev = "687b2c72a24c59d701d62e4458c380f8c54f0549";
41 hash = "sha256-q3Snd3K/JndckwAVwSKU+kFK5E1uph78ty7mwVo/7Ik=";
42 # Only needed for test data
43 fetchSubmodules = true;
44 };
45
46 patches = [
47 # python-mapnik seems to depend on having the mapnik src directory
48 # structure available at build time. We just hardcode the paths.
49 (substituteAll {
50 src = ./find-libmapnik.patch;
51 libmapnik = "${mapnik}/lib";
52 })
53 ];
54
55 nativeBuildInputs = [
56 mapnik # for mapnik_config
57 pkg-config
58 ];
59
60 buildInputs = [
61 mapnik
62 boost
63 cairo
64 harfbuzz
65 icu
66 libjpeg
67 libpng
68 libtiff
69 libwebp
70 proj
71 zlib
72 libxml2
73 sqlite
74 ];
75
76 propagatedBuildInputs = [
77 pillow
78 pycairo
79 ];
80
81 configureFlags = [ "XMLPARSER=libxml2" ];
82
83 disabled = isPyPy;
84
85 preBuild = ''
86 export BOOST_PYTHON_LIB="boost_python${"${lib.versions.major python.version}${lib.versions.minor python.version}"}"
87 export BOOST_THREAD_LIB="boost_thread"
88 export BOOST_SYSTEM_LIB="boost_system"
89 export PYCAIRO=true
90 export XMLPARSER=libxml2
91 '';
92
93 nativeCheckInputs = [
94 nose
95 pytestCheckHook
96 ];
97
98 preCheck =
99 ''
100 # import from $out
101 rm -r mapnik
102 ''
103 + lib.optionalString stdenv.isDarwin ''
104 # Replace the hardcoded /tmp references with $TMPDIR
105 sed -i "s,/tmp,$TMPDIR,g" test/python_tests/*.py
106 '';
107
108 # https://github.com/mapnik/python-mapnik/issues/255
109 disabledTests = [
110 "test_geometry_type"
111 "test_marker_ellipse_render1"
112 "test_marker_ellipse_render2"
113 "test_normalizing_definition"
114 "test_passing_pycairo_context_pdf"
115 "test_pdf_printing"
116 "test_visual_zoom_all_rendering2"
117 "test_wgs84_inverse_forward"
118 ] ++ lib.optionals stdenv.isDarwin [ "test_passing_pycairo_context_svg" ];
119
120 pythonImportsCheck = [ "mapnik" ];
121
122 meta = with lib; {
123 description = "Python bindings for Mapnik";
124 maintainers = with maintainers; [ ];
125 homepage = "https://mapnik.org";
126 license = licenses.lgpl21Plus;
127 };
128}