1{ lib
2, stdenv
3, fetchFromGitHub
4, buildPythonPackage
5, python
6, pythonOlder
7, astropy
8, cloudpickle
9, cython
10, dask
11, imageio
12, lazy-loader
13, matplotlib
14, meson-python
15, networkx
16, numpy
17, packaging
18, pillow
19, pooch
20, pyamg
21, pytestCheckHook
22, pythran
23, pywavelets
24, scikit-learn
25, scipy
26, setuptools
27, simpleitk
28, six
29, tifffile
30, wheel
31}:
32
33let
34 installedPackageRoot = "${builtins.placeholder "out"}/${python.sitePackages}";
35 self = buildPythonPackage rec {
36 pname = "scikit-image";
37 version = "0.21.0";
38 format = "pyproject";
39
40 disabled = pythonOlder "3.8";
41
42 src = fetchFromGitHub {
43 owner = "scikit-image";
44 repo = "scikit-image";
45 rev = "v${version}";
46 hash = "sha256-WJ2WNlcFCEtPr+bV/af6MoBBhbXDpOBEsJu4FmudoIo=";
47 };
48
49 patches = [
50 # https://github.com/scikit-image/scikit-image/pull/7052
51 # prepare a patch file because the commit contains additional changes
52 ./suppress-deprecation-warning.patch
53 ];
54
55 postPatch = ''
56 patchShebangs skimage/_build_utils/{version,cythoner}.py
57
58 substituteInPlace pyproject.toml \
59 --replace "numpy==" "numpy>="
60 '';
61
62 nativeBuildInputs = [
63 cython
64 meson-python
65 numpy
66 packaging
67 pythran
68 setuptools
69 wheel
70 ];
71
72 propagatedBuildInputs = [
73 imageio
74 lazy-loader
75 matplotlib
76 networkx
77 numpy
78 packaging
79 pillow
80 pywavelets
81 scipy
82 tifffile
83 ];
84
85 passthru.optional-dependencies = {
86 data = [
87 pooch
88 ];
89 optional = [
90 astropy
91 cloudpickle
92 dask
93 matplotlib
94 pooch
95 pyamg
96 scikit-learn
97 simpleitk
98 ] ++ dask.optional-dependencies.array;
99 };
100
101 # test suite is very cpu intensive, move to passthru.tests
102 doCheck = false;
103 nativeCheckInputs = [ pytestCheckHook ];
104
105 # (1) The package has cythonized modules, whose .so libs will appear only in the wheel, i.e. in nix store;
106 # (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;
107 # (3) Therefore, tests should be run on the installed package in nix store.
108
109 # See e.g. https://discourse.nixos.org/t/cant-import-cythonized-modules-at-checkphase/14207 on why the following is needed.
110 preCheck = ''
111 rm -r skimage
112 '';
113
114 disabledTestPaths = [
115 # 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).
116 "${installedPackageRoot}/skimage/filters/rank/tests/test_rank.py"
117 ];
118 pytestFlagsArray = [ "${installedPackageRoot}" "--pyargs" "skimage" ] ++ builtins.map (testid: "--deselect=" + testid) ([
119 # These tests require network access
120 "skimage/data/test_data.py::test_skin"
121 "skimage/data/tests/test_data.py::test_skin"
122 "skimage/io/tests/test_io.py::test_imread_http_url"
123 "skimage/restoration/tests/test_rolling_ball.py::test_ndim"
124 ] ++ lib.optionals stdenv.isDarwin [
125 # Matplotlib tests are broken inside darwin sandbox
126 "skimage/feature/tests/test_util.py::test_plot_matches"
127 "skimage/filters/tests/test_thresholding.py::TestSimpleImage::test_try_all_threshold"
128 "skimage/io/tests/test_mpl_imshow.py::"
129 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
130 # https://github.com/scikit-image/scikit-image/issues/7104
131 "skimage/measure/tests/test_fit.py"
132 "skimage/measure/tests/test_moments.py"
133 ]);
134
135 # Check cythonized modules
136 pythonImportsCheck = [
137 "skimage"
138 "skimage._shared"
139 "skimage.draw"
140 "skimage.feature"
141 "skimage.restoration"
142 "skimage.filters"
143 "skimage.graph"
144 "skimage.io"
145 "skimage.measure"
146 "skimage.morphology"
147 "skimage.transform"
148 "skimage.util"
149 "skimage.segmentation"
150 ];
151
152 passthru.tests = {
153 all-tests = self.override { doCheck = true; };
154 };
155
156 meta = {
157 description = "Image processing routines for SciPy";
158 homepage = "https://scikit-image.org";
159 changelog = "https://github.com/scikit-image/scikit-image/releases/tag/${src.rev}";
160 license = lib.licenses.bsd3;
161 maintainers = with lib.maintainers; [ yl3dy ];
162 };
163 };
164in
165 self