1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 flit-core,
7 numpy,
8 pillow,
9 pytestCheckHook,
10 pythonOlder,
11 setuptools,
12}:
13
14let
15 pname = "pydicom";
16 version = "2.4.4";
17
18 src = fetchFromGitHub {
19 owner = "pydicom";
20 repo = "pydicom";
21 rev = "refs/tags/v${version}";
22 hash = "sha256-iJE1horEmdL7bKPn+NlZLgmtCbLZCZWQ8NjDBQPzXk8=";
23 };
24
25 # Pydicom needs pydicom-data to run some tests. If these files aren't downloaded
26 # before the package creation, it'll try to download during the checkPhase.
27 test_data = fetchFromGitHub {
28 owner = "pydicom";
29 repo = "pydicom-data";
30 rev = "cbb9b2148bccf0f550e3758c07aca3d0e328e768";
31 hash = "sha256-nF/j7pfcEpWHjjsqqTtIkW8hCEbuQ3J4IxpRk0qc1CQ=";
32 };
33in
34buildPythonPackage {
35 inherit pname version src;
36 pyproject = true;
37
38 disabled = pythonOlder "3.10";
39
40 patches = [
41 # backport of https://github.com/pydicom/pydicom/commit/2513a20cc41743a42bdb86f4cbb4873899b7823c
42 ./pillow-10.1.0-compat.patch
43 ];
44
45 nativeBuildInputs = [ flit-core ];
46
47 propagatedBuildInputs = [
48 numpy
49 pillow
50 setuptools
51 ];
52
53 nativeCheckInputs = [ pytestCheckHook ];
54
55 # Setting $HOME to prevent pytest to try to create a folder inside
56 # /homeless-shelter which is read-only.
57 # Linking pydicom-data dicom files to $HOME/.pydicom/data
58 preCheck = ''
59 export HOME=$TMP/test-home
60 mkdir -p $HOME/.pydicom/
61 ln -s ${test_data}/data_store/data $HOME/.pydicom/data
62 '';
63
64 disabledTests =
65 [
66 # tries to remove a dicom inside $HOME/.pydicom/data/ and download it again
67 "test_fetch_data_files"
68 ]
69 ++ lib.optionals stdenv.isAarch64 [
70 # https://github.com/pydicom/pydicom/issues/1386
71 "test_array"
72 ]
73 ++ lib.optionals stdenv.isDarwin [
74 # flaky, hard to reproduce failure outside hydra
75 "test_time_check"
76 ];
77
78 pythonImportsCheck = [ "pydicom" ];
79
80 meta = with lib; {
81 description = "Python package for working with DICOM files";
82 mainProgram = "pydicom";
83 homepage = "https://pydicom.github.io";
84 changelog = "https://github.com/pydicom/pydicom/releases/tag/v${version}";
85 license = licenses.mit;
86 maintainers = with maintainers; [ bcdarwin ];
87 };
88}