1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 flit-core,
7 numpy,
8 pytestCheckHook,
9
10 # optional/test dependencies
11 gdcm,
12 pillow,
13 pyjpegls,
14 pylibjpeg-libjpeg,
15 writableTmpDirAsHomeHook,
16}:
17let
18 # Pydicom needs pydicom-data to run some tests. If these files aren't downloaded
19 # before the package creation, it'll try to download during the checkPhase.
20 test_data = fetchFromGitHub {
21 owner = "pydicom";
22 repo = "pydicom-data";
23 rev = "8da482f208401d63cd63f3f4efc41b6856ef36c7";
24 hash = "sha256-ji7SppKdiszaXs8yCSIPkJj4Ld++XWNw9FuxLoFLfFo=";
25 };
26in
27buildPythonPackage rec {
28 pname = "pydicom";
29 version = "3.0.1";
30 pyproject = true;
31
32 src = fetchFromGitHub {
33 owner = "pydicom";
34 repo = "pydicom";
35 tag = "v${version}";
36 hash = "sha256-SvRevQehRaSp+vCtJRQVEJiC5noIJS+bGG1/q4p7/XU=";
37 };
38
39 build-system = [ flit-core ];
40
41 dependencies = [
42 numpy
43 ];
44
45 optional-dependencies = {
46 pixeldata = [
47 pillow
48 pyjpegls
49 #pylibjpeg.optional-dependencies.openjpeg # infinite recursion
50 #pylibjpeg.optional-dependencies.rle # infinite recursion
51 pylibjpeg-libjpeg
52 gdcm
53 ];
54 };
55
56 nativeCheckInputs = [
57 pytestCheckHook
58 writableTmpDirAsHomeHook
59 ]
60 ++ optional-dependencies.pixeldata;
61
62 passthru.pydicom-data = test_data;
63
64 # Setting $HOME to prevent pytest to try to create a folder inside
65 # /homeless-shelter which is read-only.
66 # Linking pydicom-data dicom files to $HOME/.pydicom/data
67 preCheck = ''
68 mkdir -p $HOME/.pydicom/
69 ln -s ${test_data}/data_store/data $HOME/.pydicom/data
70 '';
71
72 disabledTests = [
73 # tries to remove a dicom inside $HOME/.pydicom/data/ and download it again
74 "test_fetch_data_files"
75
76 # test_reference_expl{,_binary}[parametric_map_float.dcm] tries to download that file for some reason even though it's present in test-data
77 "test_reference_expl"
78 "test_reference_expl_binary"
79
80 # slight error in regex matching
81 "test_no_decoders_raises"
82 "test_deepcopy_bufferedreader_raises"
83 ]
84 ++ lib.optionals stdenv.hostPlatform.isAarch64 [
85 # https://github.com/pydicom/pydicom/issues/1386
86 "test_array"
87 ]
88 ++ lib.optionals stdenv.hostPlatform.isDarwin [
89 # flaky, hard to reproduce failure outside hydra
90 "test_time_check"
91 ];
92
93 pythonImportsCheck = [ "pydicom" ];
94
95 meta = {
96 description = "Python package for working with DICOM files";
97 mainProgram = "pydicom";
98 homepage = "https://pydicom.github.io";
99 changelog = "https://github.com/pydicom/pydicom/releases/tag/v${version}";
100 license = lib.licenses.mit;
101 maintainers = with lib.maintainers; [ bcdarwin ];
102 badPlatforms = [
103 # > 200 tests are failing with errors like:
104 # AttributeError: 'FileDataset' object has no attribute 'BitsStored'
105 # AttributeError: 'FileDataset' object has no attribute 'Rows'
106 # AttributeError: The dataset has no 'Pixel Data', 'Float Pixel Data' or 'Double Float Pixel Data' element, no pixel data to decode
107 # pydicom.errors.InvalidDicomError: File is missing DICOM File Meta Information header or the 'DICM' prefix is missing from the header.
108 lib.systems.inspect.patterns.isDarwin
109 ];
110 };
111}