summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/graph-tool/default.nix
blob: f455258ea14ba2e08d2b5a043208d1161f0982ff (plain)
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
128
129
130
131
132
133
{
  buildPythonPackage,
  lib,
  fetchurl,
  fetchpatch,
  stdenv,

  boost189,
  cairomm,
  cgal,
  expat,
  fontconfig,
  gobject-introspection,
  graphviz,
  gtk3,
  llvmPackages,
  matplotlib,
  mpfr,
  numpy,
  pkg-config,
  pycairo,
  pygobject3,
  python,
  scipy,
  sparsehash,
  zstandard,
  gitUpdater,
}:

let
  boost' = boost189.override {
    patches = [
      # required to build against Clang >= 21 (https://github.com/boostorg/lexical_cast/pull/87)
      # TODO: drop when upgrading to Boost >= 1.90
      (fetchpatch {
        name = "Reduce-dependency-on-Boost.TypeTraits-now-that-C-11-.patch";
        url = "https://github.com/boostorg/lexical_cast/commit/8fc8a19931c8cb452400af907959fdacbbdd8ec1.patch";
        relative = "include";
        hash = "sha256-OO39ejR+I5ufjqinrMJ6HgjTE7Ph+XBu50PqcIKaIQo=";
      })
    ];
    enablePython = true;
    inherit python;
  };
in
buildPythonPackage rec {
  pname = "graph-tool";
  version = "2.98";
  pyproject = false;

  src = fetchurl {
    url = "https://downloads.skewed.de/graph-tool/graph-tool-${version}.tar.bz2";
    hash = "sha256-7vGUi5N/XwQ3Se7nX+DG1+jwNlUdlF6dVeN4cLBsxSc=";
  };

  postPatch =
    # remove error messages about tput during build process without adding ncurses
    ''
      substituteInPlace configure \
        --replace-fail 'tput setaf $1' : \
        --replace-fail 'tput sgr0' :
    ''
    +
    # hardcode path to graphviz library to avoid find_library, which would require setting LD_LIBRARY_PATH
    ''
      substituteInPlace src/graph_tool/draw/graphviz_draw.py \
        --replace-fail \
          'ctypes.util.find_library("gvc")' \
          '"${lib.getLib graphviz}/lib/libgvc${stdenv.hostPlatform.extensions.sharedLibrary}"'
    '';

  configureFlags =
    lib.mapAttrsToList (lib.withFeatureAs true) {
      boost-libdir = "${lib.getLib boost'}/lib";
      cgal = lib.getDev cgal;
      python-module-path = "$(out)/${python.sitePackages}";
    }
    ++
      lib.optionals stdenv.cc.isGNU
        # enable GCC's link-time optimizer in order to reduce compilation time and memory usage during compilation
        # https://graph-tool.skewed.de/installation.html#memory-requirements-for-compilation
        # https://git.skewed.de/count0/graph-tool/-/issues/798#note_5626
        [ "MOD_CXXFLAGS=-flto" ];

  enableParallelBuilding = true;

  nativeBuildInputs = [ pkg-config ];

  # https://graph-tool.skewed.de/installation.html#manual-compilation
  buildInputs = [
    boost'
    cairomm
    cgal
    expat
    mpfr
    sparsehash
  ]
  ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ];

  dependencies = [
    gtk3
    matplotlib
    numpy
    pycairo
    pygobject3
    scipy
    zstandard
  ];

  propagatedNativeBuildInputs = [ gobject-introspection ];

  preInstallCheck =
    # avoid warnings about Matplotlib and Fontconfig configuration issues
    ''
      export HOME=$(mktemp -d)
      export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf
    '';

  pythonImportsCheck = [ "graph_tool.all" ];

  passthru.updateScript = gitUpdater {
    url = "https://git.skewed.de/count0/graph-tool";
    rev-prefix = "release-";
  };

  meta = {
    description = "Python module for manipulation and statistical analysis of graphs";
    homepage = "https://graph-tool.skewed.de";
    changelog = "https://git.skewed.de/count0/graph-tool/commits/release-${version}";
    license = lib.licenses.lgpl3Plus;
    maintainers = [ lib.maintainers.mjoerg ];
  };
}