1{ 2 lib, 3 buildPythonPackage, 4 fetchFromGitHub, 5 replaceVars, 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 sparsehash, 27}: 28 29buildPythonPackage rec { 30 pname = "python-mapnik"; 31 version = "3.0.16-unstable-2024-02-22"; 32 pyproject = true; 33 34 src = fetchFromGitHub { 35 owner = "mapnik"; 36 repo = "python-mapnik"; 37 rev = "5ab32f0209909cc98c26e1d86ce0c8ef29a9bf3d"; 38 hash = "sha256-OqijA1WcyBcyWO8gntqp+xNIaV1Jqa0n1eMDip2OCvY="; 39 # Only needed for test data 40 fetchSubmodules = true; 41 }; 42 43 patches = [ 44 # python-mapnik seems to depend on having the mapnik src directory 45 # structure available at build time. We just hardcode the paths. 46 (replaceVars ./find-libmapnik.patch { 47 libmapnik = "${mapnik}/lib"; 48 }) 49 # Use `std::optional` rather than `boost::optional` 50 # https://github.com/mapnik/python-mapnik/commit/e9f88a95a03dc081826a69da67bbec3e4cccd5eb 51 ./python-mapnik_std_optional.patch 52 ]; 53 54 stdenv = python.stdenv; 55 56 build-system = [ setuptools ]; 57 58 nativeBuildInputs = [ 59 mapnik # for mapnik_config 60 pkg-config 61 ]; 62 63 dependencies = [ 64 mapnik 65 boost 66 cairo 67 harfbuzz 68 icu 69 libjpeg 70 libpng 71 libtiff 72 libwebp 73 proj 74 zlib 75 libxml2 76 sqlite 77 sparsehash 78 ]; 79 80 propagatedBuildInputs = [ 81 pillow 82 pycairo 83 ]; 84 85 configureFlags = [ "XMLPARSER=libxml2" ]; 86 87 disabled = isPyPy; 88 89 preBuild = '' 90 export BOOST_PYTHON_LIB="boost_python${"${lib.versions.major python.version}${lib.versions.minor python.version}"}" 91 export BOOST_THREAD_LIB="boost_thread" 92 export BOOST_SYSTEM_LIB="boost_system" 93 export PYCAIRO=true 94 export XMLPARSER=libxml2 95 ''; 96 97 nativeCheckInputs = [ pytestCheckHook ]; 98 99 preCheck = '' 100 # import from $out 101 rm -r mapnik 102 '' 103 + lib.optionalString stdenv.hostPlatform.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_passing_pycairo_context_pdf" 112 "test_pdf_printing" 113 "test_render_with_scale_factor" 114 "test_raster_warping" 115 "test_pycairo_svg_surface1" 116 ] 117 ++ lib.optionals stdenv.hostPlatform.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_surface2" 124 "test_pycairo_svg_surface3" 125 ]; 126 127 pythonImportsCheck = [ "mapnik" ]; 128 129 meta = { 130 description = "Python bindings for Mapnik"; 131 homepage = "https://mapnik.org"; 132 license = lib.licenses.lgpl21Plus; 133 teams = [ lib.teams.geospatial ]; 134 }; 135}