about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/scikit-image/default.nix
blob: 03eaf556050fe740f2ef2ce31cf8945f3b7ffbd0 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{ lib
, stdenv
, fetchFromGitHub
, buildPythonPackage
, python
, pythonOlder
, astropy
, cloudpickle
, cython
, dask
, imageio
, lazy-loader
, matplotlib
, meson-python
, networkx
, numpy
, packaging
, pillow
, pooch
, pyamg
, pytestCheckHook
, pythran
, pywavelets
, scikit-learn
, scipy
, setuptools
, simpleitk
, six
, tifffile
, wheel
}:

let
  installedPackageRoot = "${builtins.placeholder "out"}/${python.sitePackages}";
  self = buildPythonPackage rec {
    pname = "scikit-image";
    version = "0.21.0";
    format = "pyproject";

    disabled = pythonOlder "3.8";

    src = fetchFromGitHub {
      owner = "scikit-image";
      repo = "scikit-image";
      rev = "v${version}";
      hash = "sha256-WJ2WNlcFCEtPr+bV/af6MoBBhbXDpOBEsJu4FmudoIo=";
    };

    patches = [
      # https://github.com/scikit-image/scikit-image/pull/7052
      # prepare a patch file because the commit contains additional changes
      ./suppress-deprecation-warning.patch
    ];

    postPatch = ''
      patchShebangs skimage/_build_utils/{version,cythoner}.py
    '';

    nativeBuildInputs = [
      cython
      meson-python
      numpy
      packaging
      pythran
      setuptools
      wheel
    ];

    propagatedBuildInputs = [
      imageio
      lazy-loader
      matplotlib
      networkx
      numpy
      packaging
      pillow
      pywavelets
      scipy
      tifffile
    ];

    passthru.optional-dependencies = {
      data = [
        pooch
      ];
      optional = [
        astropy
        cloudpickle
        dask
        matplotlib
        pooch
        pyamg
        scikit-learn
        simpleitk
      ] ++ dask.optional-dependencies.array;
    };

    # test suite is very cpu intensive, move to passthru.tests
    doCheck = false;
    nativeCheckInputs = [ pytestCheckHook ];

    # (1) The package has cythonized modules, whose .so libs will appear only in the wheel, i.e. in nix store;
    # (2) To stop Python from importing the wrong directory, i.e. the one in the build dir, not the one in nix store, `skimage` dir should be removed or renamed;
    # (3) Therefore, tests should be run on the installed package in nix store.

    # See e.g. https://discourse.nixos.org/t/cant-import-cythonized-modules-at-checkphase/14207 on why the following is needed.
    preCheck = ''
      rm -r skimage
    '';

    disabledTestPaths = [
      # Requires network access (actually some data is loaded via `skimage._shared.testing.fetch` in the global scope, which calls `pytest.skip` when a network is unaccessible, leading to a pytest collection error).
      "${installedPackageRoot}/skimage/filters/rank/tests/test_rank.py"
    ];
    pytestFlagsArray = [ "${installedPackageRoot}" "--pyargs" "skimage" ] ++ builtins.map (testid: "--deselect=" + testid) ([
      # These tests require network access
      "skimage/data/test_data.py::test_skin"
      "skimage/data/tests/test_data.py::test_skin"
      "skimage/io/tests/test_io.py::test_imread_http_url"
      "skimage/restoration/tests/test_rolling_ball.py::test_ndim"
    ] ++ lib.optionals stdenv.isDarwin [
      # Matplotlib tests are broken inside darwin sandbox
      "skimage/feature/tests/test_util.py::test_plot_matches"
      "skimage/filters/tests/test_thresholding.py::TestSimpleImage::test_try_all_threshold"
      "skimage/io/tests/test_mpl_imshow.py::"
    ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
      # https://github.com/scikit-image/scikit-image/issues/7104
      "skimage/measure/tests/test_fit.py"
      "skimage/measure/tests/test_moments.py"
    ]);

    # Check cythonized modules
    pythonImportsCheck = [
      "skimage"
      "skimage._shared"
      "skimage.draw"
      "skimage.feature"
      "skimage.restoration"
      "skimage.filters"
      "skimage.graph"
      "skimage.io"
      "skimage.measure"
      "skimage.morphology"
      "skimage.transform"
      "skimage.util"
      "skimage.segmentation"
    ];

    passthru.tests = {
      all-tests = self.override { doCheck = true; };
    };

    meta = {
      description = "Image processing routines for SciPy";
      homepage = "https://scikit-image.org";
      changelog = "https://github.com/scikit-image/scikit-image/releases/tag/${src.rev}";
      license = lib.licenses.bsd3;
      maintainers = with lib.maintainers; [ yl3dy ];
    };
  };
in
  self