nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildPythonPackage,
6 python,
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 numpydoc,
23 pythran,
24 pywavelets,
25 scikit-learn,
26 scipy,
27 setuptools,
28 simpleitk,
29 tifffile,
30 wheel,
31}:
32
33let
34 installedPackageRoot = "${placeholder "out"}/${python.sitePackages}";
35 self = buildPythonPackage rec {
36 pname = "scikit-image";
37 version = "0.26.0";
38 pyproject = true;
39
40 src = fetchFromGitHub {
41 owner = "scikit-image";
42 repo = "scikit-image";
43 tag = "v${version}";
44 hash = "sha256-VpvlG2ECbq+FWLZ4RfdbbR3V6Fbw0RIvnVp+w0Rp+8o=";
45 };
46
47 postPatch = ''
48 patchShebangs src/skimage/_build_utils/{version,cythoner}.py
49
50 substituteInPlace src/skimage/_build_utils/version.py \
51 --replace-fail "version = version_from_init()" "version = \"${version}\""
52 '';
53
54 nativeBuildInputs = [
55 cython
56 meson-python
57 numpy
58 packaging
59 pythran
60 setuptools
61 wheel
62 ];
63
64 propagatedBuildInputs = [
65 imageio
66 lazy-loader
67 matplotlib
68 networkx
69 numpy
70 packaging
71 pillow
72 pywavelets
73 scipy
74 tifffile
75 ];
76
77 optional-dependencies = {
78 data = [ pooch ];
79 optional = [
80 astropy
81 cloudpickle
82 dask
83 matplotlib
84 pooch
85 pyamg
86 scikit-learn
87 simpleitk
88 ]
89 ++ dask.optional-dependencies.array;
90 };
91
92 # test suite is very cpu intensive, move to passthru.tests
93 doCheck = false;
94 nativeCheckInputs = [
95 pytestCheckHook
96 numpydoc
97 ];
98
99 # (1) The package has cythonized modules, whose .so libs will appear only in the wheel, i.e. in nix store;
100 # (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;
101 # (3) Therefore, tests should be run on the installed package in nix store.
102
103 # See e.g. https://discourse.nixos.org/t/cant-import-cythonized-modules-at-checkphase/14207 on why the following is needed.
104 preCheck = ''
105 rm -r skimage
106 '';
107
108 pytestFlagsArray = [
109 "${installedPackageRoot}"
110 "--pyargs"
111 "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 # These tests require network access
119 "skimage/data/test_data.py::test_skin"
120 "skimage/data/tests/test_data.py::test_skin"
121 "skimage/io/tests/test_io.py::test_imread_http_url"
122 "skimage/restoration/tests/test_rolling_ball.py::test_ndim"
123 ]
124 ++ lib.optionals stdenv.hostPlatform.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 # See https://github.com/scikit-image/scikit-image/issues/7061 and https://github.com/scikit-image/scikit-image/issues/7104
130 "skimage/measure/tests/test_fit.py"
131 ]
132 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
133 # https://github.com/scikit-image/scikit-image/issues/7104
134 "skimage/measure/tests/test_moments.py"
135 ];
136
137 # Check cythonized modules
138 pythonImportsCheck = [
139 "skimage"
140 "skimage._shared"
141 "skimage.draw"
142 "skimage.feature"
143 "skimage.restoration"
144 "skimage.filters"
145 "skimage.graph"
146 "skimage.io"
147 "skimage.measure"
148 "skimage.morphology"
149 "skimage.transform"
150 "skimage.util"
151 "skimage.segmentation"
152 ];
153
154 passthru.tests = {
155 all-tests = self.overridePythonAttrs { doCheck = true; };
156 };
157
158 meta = {
159 description = "Image processing routines for SciPy";
160 homepage = "https://scikit-image.org";
161 changelog = "https://github.com/scikit-image/scikit-image/releases/tag/${src.tag}";
162 license = lib.licenses.bsd3;
163 maintainers = with lib.maintainers; [ yl3dy ];
164 };
165 };
166in
167self