about summary refs log tree commit diff
path: root/pkgs/development/python-modules/python-mapnik/default.nix
blob: c93adc9f09db87d2409ac719c5e70d9e33dcf8ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  substituteAll,
  isPyPy,
  python,
  pillow,
  pycairo,
  pkg-config,
  boost,
  cairo,
  harfbuzz,
  icu,
  libjpeg,
  libpng,
  libtiff,
  libwebp,
  mapnik,
  proj,
  zlib,
  libxml2,
  sqlite,
  nose,
  pytestCheckHook,
  stdenv,
}:

buildPythonPackage rec {
  pname = "python-mapnik";
  version = "unstable-2023-02-23";
  format = "setuptools";

  src = fetchFromGitHub {
    owner = "mapnik";
    repo = "python-mapnik";
    # Use proj6 branch in order to support Proj >= 6 (excluding commits after 2023-02-23)
    # https://github.com/mapnik/python-mapnik/compare/master...proj6
    rev = "687b2c72a24c59d701d62e4458c380f8c54f0549";
    hash = "sha256-q3Snd3K/JndckwAVwSKU+kFK5E1uph78ty7mwVo/7Ik=";
    # Only needed for test data
    fetchSubmodules = true;
  };

  patches = [
    # python-mapnik seems to depend on having the mapnik src directory
    # structure available at build time. We just hardcode the paths.
    (substituteAll {
      src = ./find-libmapnik.patch;
      libmapnik = "${mapnik}/lib";
    })
  ];

  nativeBuildInputs = [
    mapnik # for mapnik_config
    pkg-config
  ];

  buildInputs = [
    mapnik
    boost
    cairo
    harfbuzz
    icu
    libjpeg
    libpng
    libtiff
    libwebp
    proj
    zlib
    libxml2
    sqlite
  ];

  propagatedBuildInputs = [
    pillow
    pycairo
  ];

  configureFlags = [ "XMLPARSER=libxml2" ];

  disabled = isPyPy;

  preBuild = ''
    export BOOST_PYTHON_LIB="boost_python${"${lib.versions.major python.version}${lib.versions.minor python.version}"}"
    export BOOST_THREAD_LIB="boost_thread"
    export BOOST_SYSTEM_LIB="boost_system"
    export PYCAIRO=true
    export XMLPARSER=libxml2
  '';

  nativeCheckInputs = [
    nose
    pytestCheckHook
  ];

  preCheck =
    ''
      # import from $out
      rm -r mapnik
    ''
    + lib.optionalString stdenv.isDarwin ''
      # Replace the hardcoded /tmp references with $TMPDIR
      sed -i "s,/tmp,$TMPDIR,g" test/python_tests/*.py
    '';

  # https://github.com/mapnik/python-mapnik/issues/255
  disabledTests = [
    "test_geometry_type"
    "test_marker_ellipse_render1"
    "test_marker_ellipse_render2"
    "test_normalizing_definition"
    "test_passing_pycairo_context_pdf"
    "test_pdf_printing"
    "test_visual_zoom_all_rendering2"
    "test_wgs84_inverse_forward"
  ] ++ lib.optionals stdenv.isDarwin [ "test_passing_pycairo_context_svg" ];

  pythonImportsCheck = [ "mapnik" ];

  meta = with lib; {
    description = "Python bindings for Mapnik";
    maintainers = with maintainers; [ ];
    homepage = "https://mapnik.org";
    license = licenses.lgpl21Plus;
  };
}