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