From 50d3c941064d94e964dfad0993bedd1844196a9d9f9bf7b2d9fb5cab7416bf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=C3=A9ta=20Machov=C3=A1?= Date: Wed, 4 Sep 2024 12:11:51 +0000 Subject: [PATCH] - Add pydicom-pr2076-np2.patch backport of gh#pydicom/pydicom#2076 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-pydicom?expand=0&rev=32 --- .gitattributes | 23 ++++ .gitignore | 1 + pydicom-2.4.4-gh.tar.gz | 3 + pydicom-pr1908-fixpillow.patch | 23 ++++ pydicom-pr2076-np2.patch | 101 +++++++++++++++++ python-pydicom.changes | 195 +++++++++++++++++++++++++++++++++ python-pydicom.spec | 111 +++++++++++++++++++ 7 files changed, 457 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 pydicom-2.4.4-gh.tar.gz create mode 100644 pydicom-pr1908-fixpillow.patch create mode 100644 pydicom-pr2076-np2.patch create mode 100644 python-pydicom.changes create mode 100644 python-pydicom.spec diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/pydicom-2.4.4-gh.tar.gz b/pydicom-2.4.4-gh.tar.gz new file mode 100644 index 0000000..ab0ee33 --- /dev/null +++ b/pydicom-2.4.4-gh.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42c06ed74331174111dd42c89db774a13fc472abe18015f22c5aba80cddb7843 +size 2203904 diff --git a/pydicom-pr1908-fixpillow.patch b/pydicom-pr1908-fixpillow.patch new file mode 100644 index 0000000..489ed6e --- /dev/null +++ b/pydicom-pr1908-fixpillow.patch @@ -0,0 +1,23 @@ +From 11f7bd260137a18496bdfd00ddb742ef0cf2d2fd Mon Sep 17 00:00:00 2001 +From: scaramallion +Date: Mon, 16 Oct 2023 10:35:46 +1100 +Subject: [PATCH 1/4] Fix Pillow raising AttributeError due to Image.mode being + read-only + +Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py +=================================================================== +--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pillow_handler.py ++++ pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py +@@ -129,7 +129,11 @@ def _decompress_single_frame( + image.tile[0][2], + (color_mode, ''), + )] +- image.mode = color_mode ++ # Pillow 10.1+ made Image.mode read-only ++ if hasattr(image, "_mode"): ++ image._mode = color_mode ++ else: ++ image.mode = color_mode + image.rawmode = color_mode + return image + diff --git a/pydicom-pr2076-np2.patch b/pydicom-pr2076-np2.patch new file mode 100644 index 0000000..5ba3c47 --- /dev/null +++ b/pydicom-pr2076-np2.patch @@ -0,0 +1,101 @@ + +Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py +=================================================================== +--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pillow_handler.py ++++ pydicom-2.4.4/pydicom/pixel_data_handlers/pillow_handler.py +@@ -255,14 +255,14 @@ def get_pixeldata(ds: "Dataset") -> "num + if ds.PixelRepresentation == 1: + # Pillow converts signed data to unsigned + # so we need to undo this conversion +- arr -= 2**(bits_allocated - 1) ++ arr -= numpy.uint32(2**(bits_allocated - 1)) + + if shift: + arr = numpy.right_shift(arr, shift) + else: + # Corrections based on dataset elements + if ds.PixelRepresentation == 1: +- arr -= 2**(bits_allocated - 1) ++ arr -= numpy.uint32(2**(bits_allocated - 1)) + + if shift: + arr = numpy.right_shift(arr, shift) +Index: pydicom-2.4.4/pydicom/pixel_data_handlers/pylibjpeg_handler.py +=================================================================== +--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/pylibjpeg_handler.py ++++ pydicom-2.4.4/pydicom/pixel_data_handlers/pylibjpeg_handler.py +@@ -66,11 +66,7 @@ except ImportError: + HAVE_PYLIBJPEG = False + + if HAVE_PYLIBJPEG: +- try: +- from pylibjpeg.utils import get_pixel_data_decoders +- except ImportError: +- # Old import, deprecated in 1.2, removal in 2.0 +- from pylibjpeg.pydicom.utils import get_pixel_data_decoders ++ from pylibjpeg.utils import get_pixel_data_decoders, Decoder + + try: + import openjpeg +@@ -249,7 +245,7 @@ def generate_frames( + "elements are missing from the dataset: " + ", ".join(missing) + ) + +- decoder = _DECODERS[tsyntax] ++ decoder = cast(Decoder, _DECODERS[tsyntax]) + LOGGER.debug(f"Decoding {tsyntax.name} encoded Pixel Data using {decoder}") + + nr_frames = getattr(ds, "NumberOfFrames", 1) +@@ -260,7 +256,7 @@ def generate_frames( + bits_allocated = cast(int, ds.BitsAllocated) + + for frame in generate_pixel_data_frame(ds.PixelData, nr_frames): +- arr = decoder(frame, pixel_module) ++ arr = decoder(frame, ds=pixel_module) + + if ( + tsyntax in [JPEG2000, JPEG2000Lossless] +Index: pydicom-2.4.4/pydicom/tests/test_encoders_pydicom.py +=================================================================== +--- pydicom-2.4.4.orig/pydicom/tests/test_encoders_pydicom.py ++++ pydicom-2.4.4/pydicom/tests/test_encoders_pydicom.py +@@ -444,7 +444,7 @@ class TestRLEEncodeFrame: + assert ds.SamplesPerPixel == 3 + assert ds.PixelRepresentation == 0 + +- arr = ref.newbyteorder('>') ++ arr = ref.view(ref.dtype.newbyteorder('>')) + assert id(arr) != id(ref) + assert arr.dtype == '>u2' + encoded = rle_encode_frame(arr) +Index: pydicom-2.4.4/pydicom/pixel_data_handlers/util.py +=================================================================== +--- pydicom-2.4.4.orig/pydicom/pixel_data_handlers/util.py ++++ pydicom-2.4.4/pydicom/pixel_data_handlers/util.py +@@ -200,7 +200,7 @@ def apply_color_lut( + # IVs >= `first_map` are mapped by the Palette Color LUTs + # `first_map` may be negative, positive or 0 + mapped_pixels = arr >= first_map +- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map ++ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map) + # IVs > number of entries get set to last entry + np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv) + +@@ -276,7 +276,7 @@ def apply_modality_lut(arr: "np.ndarray" + # IVs >= `first_map` are mapped by the Modality LUT + # `first_map` may be negative, positive or 0 + mapped_pixels = arr >= first_map +- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map ++ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map) + # IVs > number of entries get set to last entry + np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv) + +@@ -458,7 +458,7 @@ def apply_voi( + # IVs >= `first_map` are mapped by the VOI LUT + # `first_map` may be negative, positive or 0 + mapped_pixels = arr >= first_map +- clipped_iv[mapped_pixels] = arr[mapped_pixels] - first_map ++ clipped_iv[mapped_pixels] = arr[mapped_pixels] - np.int32(first_map) + # IVs > number of entries get set to last entry + np.clip(clipped_iv, 0, nr_entries - 1, out=clipped_iv) + diff --git a/python-pydicom.changes b/python-pydicom.changes new file mode 100644 index 0000000..3a1ba90 --- /dev/null +++ b/python-pydicom.changes @@ -0,0 +1,195 @@ +------------------------------------------------------------------- +Wed Sep 4 07:18:47 UTC 2024 - Ben Greiner + +- Add pydicom-pr2076-np2.patch backport of gh#pydicom/pydicom#2076 + +------------------------------------------------------------------- +Mon Feb 19 10:16:16 UTC 2024 - Andreas Schwab + +- Skip TestPillowHandler_JPEG2K also on riscv64 + +------------------------------------------------------------------- +Thu Jan 25 17:55:25 UTC 2024 - Ben Greiner + +- Update to 2.4.4 + ## Changes + * Removed support for Python 3.6 (EOL since December 2021) + ## Enhancements + * Added attribute alphabetic (#1634) + * Added attribute json_key (#1648) + * Added value validation for numerical VRs, add type validation + for all validated VRs (#1414) + * CLI commands now accept pydicom charset test files and CLI help + shows Python Version (#1674) + * Added support for Python 3.11 (#1658) + * Added ISfloat to allow non-strict reading of existing files + with float IS values (#1661) + * Improved speed of creating and accessing highly nested + structures (#1728, #1734) + * Switched to a pyproject.toml build process (#1792) + * Updated DICOM and UID dicts to DICOM 2023b (#1803) + ## Fixes + * Fixed length validation of DS values with maximum length + without a leading zero (#1632) + * Increased download speed with progress bar for test data + (#1611) + * Fixed crash due to invalid private creator (#1638) + * Fixed extremely long BytesLengthException error messages + (#1683) + * In codify, ensure unique variable names for DICOM keywords + repeated in sequences, and handle unicode characters correctly + (#1670) + * Fixed handling of some invalid values in to_json_dict() if + suppress_invalid_tags is set to True (#1693) + * Fixed reading of data with 8 bits allocated, encoded in Big + Endian transfer syntax using VR OW (#1680) + * Fixed crash if reading regular dataset that has the SOP Class + of a DICOMDIR (#1702) + * Fixed wrong waveform data calculation when as_raw=False and + baseline!=0 (#1667) + * Fixed reading LUTData to expected size (#1747) + * Fixed handling of AT VRs when codifying data elements (#1738) + ## Pydicom Internals + * In test suites, renamed ‘setup’ and ‘teardown’ methods, + deprecated starting in pytest 7.2 + * Use own fork of CharPyLS to handle builds with Python 3.11 + (#1788) +- Go back do %{?sle15_python_module_pythons}. python- prefixed + packages for Python 3.6 should be handled by separate maintenance + request to python3-pydicom on SLE side +- Add pydicom-pr1908-fixpillow.patch + * gh#pydicom/pydicom#1908 fixes gh#pydicom/pydicom#1907 + +------------------------------------------------------------------- +Tue Jan 16 09:57:21 UTC 2024 - Axel Braun + +- switch to wheel and enable %{?sle15allpythons} + +------------------------------------------------------------------- +Sat Dec 3 20:04:13 UTC 2022 - Yogalakshmi Arunachalam + +- Update to version 2.3.1: + * Small fix to make 2.3.X compatible with Python 3.11. + +------------------------------------------------------------------- +Mon Oct 10 07:20:51 UTC 2022 - John Vandenberg + +- Add BD pydicom-data test data, and unskip many tests that now pass + +------------------------------------------------------------------- +Sat Sep 24 02:04:40 UTC 2022 - John Vandenberg + +- Skip a lot of tests, mostly due to missing test data, but there + are over 1900 still passing. +- Update to v2.3.0 + * See https://github.com/pydicom/pydicom/tree/master/doc/release_notes + +------------------------------------------------------------------- +Fri Dec 10 07:41:02 UTC 2021 - pgajdos@suse.com + +- do not require pytest-runner for build + +------------------------------------------------------------------- +Tue Mar 10 09:14:48 UTC 2020 - Tomáš Chvátal + +- Update to 1.4.2: + * no upstream changelog + +------------------------------------------------------------------- +Tue Jul 23 09:10:15 UTC 2019 - Tomáš Chvátal + +- Update to 1.3.0: + * no upstream changelog + +------------------------------------------------------------------- +Fri Mar 8 06:49:41 UTC 2019 - John Vandenberg + +- Reinstate test unit test_code_file which appears to be stable now +- Use PyPI sdist as source + +------------------------------------------------------------------- +Wed Jan 2 12:07:30 UTC 2019 - Tomáš Chvátal + +- Update to 1.2.2: + * more python 3.7 fixes + +------------------------------------------------------------------- +Thu Nov 1 14:01:20 UTC 2018 - Tomáš Chvátal + +- Update to 1.2.0: + * No obvious upstream changelog +- Drop python37.patch should be fixed upstream + +------------------------------------------------------------------- +Thu Aug 30 08:34:34 UTC 2018 - Tomáš Chvátal + +- Disable test_code_file as it randomly fails in OBS + +------------------------------------------------------------------- +Wed Aug 29 12:04:20 UTC 2018 - tchvatal@suse.com + +- Update to 1.1.0: + * License is distributed + * Various speed improvements +- Add patch to work with python 3.7: + * python37.patch + +------------------------------------------------------------------- +Mon Sep 11 15:14:49 UTC 2017 - jengelh@inai.de + +- Make package description neutral and compact it. + +------------------------------------------------------------------- +Mon Sep 11 14:47:43 UTC 2017 - toddrme2178@gmail.com + +- Implement single-spec version + +------------------------------------------------------------------- +Thu Oct 13 19:45:31 UTC 2016 - toddrme2178@gmail.com + +- Update to version 0.9.9 + + Major changes / enhancements + * All dicom dictionaries updated (standard dictionary, UID + dictionary, and private dictionaries) + * Dicom commands also added to dictionary + * Ability to work with DICOMDIR: read_dicomdir() function and + DicomDir class. Example file show_dicomdir.py file added to + examples subdirectory. + * codify.py: Produce python/pydicom source code from a dicom + file. + * a number of python 3 compatibility enhancements + * setup.py uses ez_setup only if setuptools not already + installed + * exceptions carry tag info with them, to aid in debugging + + Contrib file changes + * pydicom_series: force parameter added (Nil Goyette) + * dcm_qt_tree: switch to OrderedDict to preserve ordering of + tags (Padraig Looney) +- Rename package to python-dicom to python-pydicom to conform to python + package naming policies. +- spec file completely rewritten. +- Remove unneeded python-dicom-remove-obsolete-distribute-support.patch + +------------------------------------------------------------------- +Tue Dec 17 17:34:04 UTC 2013 - p.drouand@gmail.com + +- Update to version 0.9.8 + + No changelog available +- Add python-dicom-remove-obsolete-distribute-support.patch; setup + script try to import setuptools from distribute + +------------------------------------------------------------------- +Thu Oct 24 11:01:12 UTC 2013 - speilicke@suse.com + +- Require python-setuptools instead of distribute (upstreams merged) + +------------------------------------------------------------------- +Fri Aug 17 21:15:59 UTC 2012 - scorot@free.fr + +- fix build for SLE 11 x86_64 + +------------------------------------------------------------------- +Tue Aug 7 13:23:47 UTC 2012 - toddrme2178@gmail.com + +- Initial version + diff --git a/python-pydicom.spec b/python-pydicom.spec new file mode 100644 index 0000000..3d5ce76 --- /dev/null +++ b/python-pydicom.spec @@ -0,0 +1,111 @@ +# +# spec file for package python-pydicom +# +# Copyright (c) 2024 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +%{?sle15_python_module_pythons} +Name: python-pydicom +Version: 2.4.4 +Release: 0 +Summary: Pure python package for DICOM medical file reading and writing +License: MIT +URL: https://github.com/darcymason/pydicom +Source: https://github.com/pydicom/pydicom/archive/refs/tags/v%{version}.tar.gz#/pydicom-%{version}-gh.tar.gz +# PATCH-FIX-UPSTREAM pydicom-pr1908-fixpillow.patch gh#pydicom/pydicom#1908 fixes gh#pydicom/pydicom#1907 +Patch0: pydicom-pr1908-fixpillow.patch +# PATCH-FIX-UPSTREAM pydicom-pr2076-np2.patch gh#pydicom/pydicom#2076 +Patch1: pydicom-pr2076-np2.patch +BuildRequires: %{python_module base >= 3.7} +BuildRequires: %{python_module flit-core >= 3.2} +BuildRequires: %{python_module pip} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +# SECTION test requirements +BuildRequires: %{python_module numpy} +BuildRequires: %{python_module Pillow} +BuildRequires: %{python_module pydicom-data} +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module requests} +%if 0%{?suse_version} > 1550 +# GDCM is not multiflavor in Tumbleweed +BuildRequires: python3-gdcm +%endif +# /SECTION +BuildArch: noarch +Requires(post): update-alternatives +Requires(postun): update-alternatives +%python_subpackages + +%description +pydicom is a pure python package for parsing DICOM files +into natural pythonic structures for further manipulation. +Modified datasets can be written again to DICOM format files. + +DICOM is a standard (http://medical.nema.org) for communicating +medical images and related information such as reports +and radiotherapy objects. + +%prep +%autosetup -p1 -n pydicom-%{version} + +%build +%pyproject_wheel + +%install +%pyproject_install +%python_clone -a %{buildroot}%{_bindir}/pydicom +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +%check +export LANG=en_US.UTF-8 + +%{python_expand # see https://github.com/pydicom/pydicom/issues/1697 +mkdir build/locallib +cp -r %{$python_sitelib}/data_store %{$python_sitelib}/pydicom_data*.dist-info build/locallib/ +} +export PYTHONPATH=$PWD/build/locallib +# these assume that a cache is updatable from online downloads +skips="test_fetch_data_files" +skips="$skips or test_get_testdata_file_external_hash_mismatch" +skips="$skips or test_get_testdata_files_local_external_and_cache" +skips="$skips or test_get_testdata_files_hash_match" +skips="$skips or test_get_testdata_files_hash_mismatch" +skips="$skips or test_get_testdata_files_external_ignore_hash" + +if [ "$RPM_ARCH" = "ppc64le" -o "$RPM_ARCH" = "aarch64" -o "$RPM_ARCH" = "riscv64" ]; then + skips="$skips or TestPillowHandler_JPEG2K" +fi +if [ $(getconf LONG_BIT) -eq 32 ]; then + # Failures on i586 + skips="$skips or test_write_file_id or test_file_id or test_encapsulate_bot_large_raises or (TestPillowHandler_JPEG2K and test_array)" +fi + +%pytest -rsfR $ignores -k "not ($skips)" + +%post +%python_install_alternative pydicom + +%postun +%python_uninstall_alternative pydicom + +%files %{python_files} +%doc README.md +%license LICENSE +%python_alternative %{_bindir}/pydicom +%{python_sitelib}/pydicom +%{python_sitelib}/pydicom-%{version}.dist-info + +%changelog