From 7566b4cd05a4989d5ecc1a7914476e202b92bbbd05773aa31b5b8e1cc5d983cd Mon Sep 17 00:00:00 2001 From: Nico Krapp Date: Wed, 27 Nov 2024 16:10:59 +0000 Subject: [PATCH] - Update to 0.5.7 * Renamed np.product to np.prod as the old name is deprecated in NumPy 2.0. - Add patch new-pythons.patch to fix build with Python 3.13 - Python 2 can be finally gone OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-mrcz?expand=0&rev=9 --- .gitattributes | 23 ++++ .gitignore | 1 + new-pythons.patch | 67 ++++++++++ numpy2.patch | 265 +++++++++++++++++++++++++++++++++++++++ python-mrcz-0.5.6.tar.gz | 3 + python-mrcz-0.5.7.tar.gz | 3 + python-mrcz.changes | 42 +++++++ python-mrcz.spec | 72 +++++++++++ 8 files changed, 476 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 new-pythons.patch create mode 100644 numpy2.patch create mode 100644 python-mrcz-0.5.6.tar.gz create mode 100644 python-mrcz-0.5.7.tar.gz create mode 100644 python-mrcz.changes create mode 100644 python-mrcz.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/new-pythons.patch b/new-pythons.patch new file mode 100644 index 0000000..6b2b09a --- /dev/null +++ b/new-pythons.patch @@ -0,0 +1,67 @@ +From ce031b069262cfd1a21c76bf2d54f7bf31a178c6 Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sun, 13 Oct 2024 11:21:06 +0100 +Subject: [PATCH 1/2] Remove use of distutils, use packaging library instead + +--- + mrcz/ioMRC.py | 8 ++++---- + requirements.txt | 1 + + utils/update_mrcz_to_0.5.0.py | 1 - + 3 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/utils/update_mrcz_to_0.5.0.py b/utils/update_mrcz_to_0.5.0.py +index ba84d2b..515bd01 100644 +--- a/utils/update_mrcz_to_0.5.0.py ++++ b/utils/update_mrcz_to_0.5.0.py +@@ -1,7 +1,6 @@ + import glob, sys, os, os.path as path + import numpy as np + import mrcz +-from distutils.version import StrictVersion + import shutil + + args = sys.argv + +From 6c196f6602a50f14545c197234e0b8fdd7711e0f Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sun, 13 Oct 2024 11:57:13 +0100 +Subject: [PATCH 2/2] Fix deprecated `unittest.makeSuite` and explicitly list + python supported version + +--- + mrcz/test_mrcz.py | 4 ++-- + setup.py | 5 +++++ + 2 files changed, 7 insertions(+), 2 deletions(-) + +diff --git a/mrcz/test_mrcz.py b/mrcz/test_mrcz.py +index d76f5fa..fe58e38 100644 +--- a/mrcz/test_mrcz.py ++++ b/mrcz/test_mrcz.py +@@ -573,9 +573,9 @@ def test(verbosity=2): + + theSuite = unittest.TestSuite() + +- theSuite.addTest(unittest.makeSuite(PythonMrczTests)) ++ theSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(PythonMrczTests)) + if cmrczProg is not None: +- theSuite.addTest(unittest.makeSuite(PythonToCMrczTests)) ++ theSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(PythonToCMrczTests)) + + test_result = unittest.TextTestRunner(verbosity=verbosity).run(theSuite) + return test_result +diff --git a/setup.py b/setup.py +index ebda8b3..47914a7 100644 +--- a/setup.py ++++ b/setup.py +@@ -62,6 +62,11 @@ def exit_with_error(message): + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 ++Programming Language :: Python :: 3.9 ++Programming Language :: Python :: 3.10 ++Programming Language :: Python :: 3.11 ++Programming Language :: Python :: 3.12 ++Programming Language :: Python :: 3.13 + Topic :: Software Development :: Libraries :: Python Modules + Topic :: System :: Archiving :: Compression + Operating System :: Microsoft :: Windows diff --git a/numpy2.patch b/numpy2.patch new file mode 100644 index 0000000..ee5bb28 --- /dev/null +++ b/numpy2.patch @@ -0,0 +1,265 @@ +From 07c01ce360fd3bad884f2a3c03c5f33c0f8348cf Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sat, 22 Jun 2024 20:05:46 +0100 +Subject: [PATCH 2/5] Replace `==/!=` with `is`/`is not` when comparing to + `None` + +--- + mrcz/ReliablePy.py | 8 ++++---- + mrcz/ioMRC.py | 20 ++++++++++---------- + mrcz/test_mrcz.py | 2 +- + 3 files changed, 15 insertions(+), 15 deletions(-) + +diff --git a/mrcz/ReliablePy.py b/mrcz/ReliablePy.py +index 64e3274..db0dc6e 100644 +--- a/mrcz/ReliablePy.py ++++ b/mrcz/ReliablePy.py +@@ -398,7 +398,7 @@ def pruneParticlesNearImageEdge( self, box = None, shapeImage = [3838,3710] ): + Image size is not stored anywhere obvious in Relion, so it must be passed in in terms of + it's shape in [y,x] + """ +- if box == None: ++ if box is None: + try: + box = self.star[b'data_model_general'][b'OriginalImageSize'] + except: +@@ -570,7 +570,7 @@ def saveDataStar( self, outputName, particleKey = b"data_" ): + Outputs a relion ..._data.star file that has been pruned, regrouped, etc. to outputName + """ + +- if outputName == None: ++ if outputName is None: + # Need to store input star names, and figure out which was the last loaded particles.star file. + # [outFront, outExt] = os.path.splitext() + raise IOError( "Default filenames for saveDataStar not implemented yet" ) +@@ -652,11 +652,11 @@ def saveDataAsPar( self, outputPrefix, N_classes = 1, mag = None, pixelsize=None + # kept track of in Relion with Magnification and DetectorPixelSize (which + # defaults to 14.0) + +- if pixelsize == None: ++ if pixelsize is None: + # Detector pixel size in um, we need pixelsize in Angstrom + pixelsize = self.star[b'data_'][b'DetectorPixelSize'][0]*1E4 / self.star[b'data_'][b'Magnification'][0] + print( "Found pixelsize of %0.f" % pixelsize ) +- if mag == None: ++ if mag is None: + print( "Using Relion magnification of %.f and DSTEP=%.1f" % ( self.star[b'data_'][b'Magnification'][0], self.star[b'data_'][b'DetectorPixelSize'][0]) ) + print( "For a K2 (DSTEP=5.0) the appropriate magnification would be %0.f" % 50000/pixelsize ) + else: +diff --git a/mrcz/ioMRC.py b/mrcz/ioMRC.py +index 998de75..c5b234b 100644 +--- a/mrcz/ioMRC.py ++++ b/mrcz/ioMRC.py +@@ -282,16 +282,16 @@ def readMRC(MRCfilename, idx=None, endian='le', + + if ( (header['compressor'] in REVERSE_COMPRESSOR_ENUM) + and (REVERSE_COMPRESSOR_ENUM[header['compressor']] > 0) +- and idx == None ): ++ and idx is None ): + return __MRCZImport(f, header, slices, endian=endian, fileConvention=fileConvention, + n_threads=n_threads) + # Else load as uncompressed MRC file + +- if idx != None: ++ if idx is not None: + # If specific images were requested: + # TO DO: add support to read all images within a range at once + +- if header['compressor'] != None: ++ if header['compressor'] is not None: + raise RuntimeError('Reading from arbitrary positions not supported for compressed files. Compressor = %s'%header['compressor']) + if np.isscalar( idx ): + indices = np.array([idx, idx], dtype='int') +@@ -370,7 +370,7 @@ def __MRCZImport(f, header, slices, endian='le', fileConvention='ccpem', + if not BLOSC_PRESENT: + raise ImportError( '`blosc` is not installed, cannot decompress file.' ) + +- if n_threads == None: ++ if n_threads is None: + blosc.nthreads = DEFAULT_N_THREADS + else: + blosc.nthreads = n_threads +@@ -751,7 +751,7 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + # the file exists, but idx is 'None', it will be replaced by a new file + # with new header anyway: + if os.path.isfile(MRCfilename): +- if idx == None: ++ if idx is None: + idxnewfile = True + else: + idxnewfile = False +@@ -760,11 +760,11 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + + + if idxnewfile: +- if dtype == 'uint4' and compressor != None: ++ if dtype == 'uint4' and compressor is not None: + raise TypeError('uint4 packing is not compatible with compression, use int8 datatype.') + + header = {'meta': meta} +- if dtype == None: ++ if dtype is None: + if slices > 0: + header['dtype'] = endchar + input_image[0].dtype.descr[0][1].strip('<>|') + else: +@@ -816,7 +816,7 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + + header['compressor'] = compressor + header['clevel'] = clevel +- if n_threads == None and BLOSC_PRESENT: ++ if n_threads is None and BLOSC_PRESENT: + n_threads = DEFAULT_N_THREADS + header['n_threads'] = n_threads + +@@ -848,8 +848,8 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + header['meta'] = meta + + # Now that we have a proper header, we go into the details of writing to a specific position: +- if idx != None: +- if header['compressor'] != None: ++ if idx is not None: ++ if header['compressor'] is not None: + raise RuntimeError('Writing at arbitrary positions not supported for compressed files. Compressor = %s' % header['compressor']) + + idx = int(idx) +diff --git a/mrcz/test_mrcz.py b/mrcz/test_mrcz.py +index d76f5fa..9701cdc 100644 +--- a/mrcz/test_mrcz.py ++++ b/mrcz/test_mrcz.py +@@ -23,7 +23,7 @@ def which(program): + program_ext = os.path.splitext(program)[1] + if program_ext == '': + prog_exe = which(program + '.exe') +- if prog_exe != None: ++ if prog_exe is not None: + return prog_exe + return which(program + '.com') + + +From 92e1b2397e2024c25b61d9eef1ed700c5bc00a4e Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sat, 22 Jun 2024 20:18:25 +0100 +Subject: [PATCH 3/5] Replace deprecated `disutils.version.StrictVersion` with + `packaging.version.Version` + +--- + mrcz/ioMRC.py | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/mrcz/ioMRC.py b/mrcz/ioMRC.py +index c5b234b..115044e 100644 +--- a/mrcz/ioMRC.py ++++ b/mrcz/ioMRC.py +@@ -27,7 +27,7 @@ + raise ImportError('Get the backport for `concurrent.futures` for Py2.7 as `pip install futures`') + raise e + from mrcz.__version__ import __version__ +-from distutils.version import StrictVersion ++from packaging.version import Version + + import logging + logger = logging.getLogger('MRCZ') +@@ -195,7 +195,7 @@ def _getMRCZVersion(label): + + Returns + ------- +- version: Optional[distutils.version.StrictVersion] ++ version: Optional[packaging.version.Version] + areturns ``None`` if `label` cannot be parsed. + """ + if isinstance(label, bytes): +@@ -207,7 +207,7 @@ def _getMRCZVersion(label): + + label = label[4:] + try: +- version = StrictVersion(label) ++ version = Version(label) + return version + except ValueError: + return None +@@ -537,7 +537,7 @@ def readMRCHeader(MRCfilename, slices=None, endian='le', fileConvention = 'ccpem + # is essentially unknown (and wrong). So we have this version + # check where we force slices to be 1 (i.e. we assume it is a + # stack of 2D images). +- if mrcz_version is not None and mrcz_version < StrictVersion('0.5.0'): ++ if mrcz_version is not None and mrcz_version < Version('0.5.0'): + logger.warning('MRCZ version < 0.5.0 for file {}, assuming slices == 1.'.format(MRCfilename)) + slices = 1 + else: + +From 1c367b3c3a5bfbffbebf36e2bf6a1eab9a668252 Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sat, 22 Jun 2024 20:20:13 +0100 +Subject: [PATCH 4/5] Replace deprecated `warn` method with `warning` + +--- + mrcz/ioMRC.py | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/mrcz/ioMRC.py b/mrcz/ioMRC.py +index 115044e..872ee2e 100644 +--- a/mrcz/ioMRC.py ++++ b/mrcz/ioMRC.py +@@ -711,12 +711,12 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + + if z_slice.dtype == np.float64 or z_slice.dtype == float: + if not WARNED_ABOUT_CASTING_F64: +- logger.warn('Casting {} to `numpy.float32`, further warnings will be suppressed.'.format(MRCfilename)) ++ logger.warning('Casting {} to `numpy.float32`, further warnings will be suppressed.'.format(MRCfilename)) + WARNED_ABOUT_CASTING_F64 = True + input_image[J] = z_slice.astype(np.float32) + elif z_slice.dtype == np.complex128: + if not WARNED_ABOUT_CASTING_C128: +- logger.warn('Casting {} to `numpy.complex64`, further warnings will be suppressed.'.format(MRCfilename)) ++ logger.warning('Casting {} to `numpy.complex64`, further warnings will be suppressed.'.format(MRCfilename)) + WARNED_ABOUT_CASTING_C128 = True + input_image[J] = z_slice.astype(np.complex64) + else: +@@ -732,12 +732,12 @@ def writeMRC(input_image, MRCfilename, meta=None, endian='le', dtype=None, + # Cast float64 -> float32, and complex128 -> complex64 + if input_image.dtype == np.float64 or input_image.dtype == float: + if not WARNED_ABOUT_CASTING_F64: +- logger.warn('Casting {} to `numpy.float64`'.format(MRCfilename)) ++ logger.warning('Casting {} to `numpy.float64`'.format(MRCfilename)) + WARNED_ABOUT_CASTING_F64 = True + input_image = input_image.astype(np.float32) + elif input_image.dtype == np.complex128: + if not WARNED_ABOUT_CASTING_C128: +- logger.warn('Casting {} to `numpy.complex64`'.format(MRCfilename)) ++ logger.warning('Casting {} to `numpy.complex64`'.format(MRCfilename)) + WARNED_ABOUT_CASTING_C128 = True + input_image = input_image.astype(np.complex64) + + +From 97644c4a957946deb1c510d83dba3d3e2fa155ba Mon Sep 17 00:00:00 2001 +From: Eric Prestat +Date: Sat, 22 Jun 2024 20:23:15 +0100 +Subject: [PATCH 5/5] Fix numpy deprecation warning on conversion of an array + with ndim > 0 to a scalar + +--- + mrcz/ioMRC.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/mrcz/ioMRC.py b/mrcz/ioMRC.py +index 872ee2e..7a61b16 100644 +--- a/mrcz/ioMRC.py ++++ b/mrcz/ioMRC.py +@@ -542,7 +542,7 @@ def readMRCHeader(MRCfilename, slices=None, endian='le', fileConvention = 'ccpem + slices = 1 + else: + f.seek(36) +- slices = int(np.fromfile(f, dtype=dtype_i4, count=1)) ++ slices = int(np.fromfile(f, dtype=dtype_i4, count=1)[0]) + + # Read in pixelsize + f.seek(40) +@@ -572,7 +572,7 @@ def readMRCHeader(MRCfilename, slices=None, endian='le', fileConvention = 'ccpem + + # Size of meta-data + f.seek(92) +- header['extendedBytes'] = int(np.fromfile(f, dtype=dtype_i4, count=1)) ++ header['extendedBytes'] = int(np.fromfile(f, dtype=dtype_i4, count=1)[0]) + if header['extendedBytes'] > 0: + f.seek(104) + header['metaId'] = f.read(4) diff --git a/python-mrcz-0.5.6.tar.gz b/python-mrcz-0.5.6.tar.gz new file mode 100644 index 0000000..0f28d56 --- /dev/null +++ b/python-mrcz-0.5.6.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8568a9d9fbf3fa8d1097f4b00edd0ed7ab9dcfda97fe236e05076e67b62fae13 +size 56897 diff --git a/python-mrcz-0.5.7.tar.gz b/python-mrcz-0.5.7.tar.gz new file mode 100644 index 0000000..2f0bc74 --- /dev/null +++ b/python-mrcz-0.5.7.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfb729604436942e912d5034ea2df72ba0055e00b31ec403b113222b827f4fa4 +size 56956 diff --git a/python-mrcz.changes b/python-mrcz.changes new file mode 100644 index 0000000..1bd6c93 --- /dev/null +++ b/python-mrcz.changes @@ -0,0 +1,42 @@ +------------------------------------------------------------------- +Wed Nov 27 11:40:39 UTC 2024 - Markéta Machová + +- Update to 0.5.7 + * Renamed np.product to np.prod as the old name is deprecated in NumPy 2.0. +- Add patch new-pythons.patch to fix build with Python 3.13 +- Python 2 can be finally gone + +------------------------------------------------------------------- +Mon Sep 9 13:39:13 UTC 2024 - Markéta Machová + +- Add patch numpy2.patch to fix build with the new numpy + +------------------------------------------------------------------- +Thu Apr 22 06:21:32 UTC 2021 - Steve Kowalik + +- Do not build for Python 3.6, due to no NumPy. + +------------------------------------------------------------------- +Tue May 12 08:26:00 UTC 2020 - Tomáš Chvátal + +- Fix python2 conditions to pull deps correctly + +------------------------------------------------------------------- +Mon May 11 16:19:40 UTC 2020 - andy great + +- Bring back build for python 2. +- Fix dependencies for building with python 2. + +------------------------------------------------------------------- +Sat May 9 15:21:11 UTC 2020 - andy great + +- Update to version 0.5.6 + * In 0.5.5 a for-loop was omitted which lead to every frame being + the zeroth frame in the stack. For this reason, upgrading from + 0.5.5 is _strongly_ recommended. +- Clean up spec file. + +------------------------------------------------------------------- +Tue Dec 10 16:30:58 UTC 2019 - Todd R + +- initial version diff --git a/python-mrcz.spec b/python-mrcz.spec new file mode 100644 index 0000000..872bf2a --- /dev/null +++ b/python-mrcz.spec @@ -0,0 +1,72 @@ +# +# spec file for package python-mrcz +# +# 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-mrcz +Version: 0.5.7 +Release: 0 +Summary: MRCZ meta-compressed image file-format library +License: BSD-3-Clause +URL: https://github.com/em-MRCZ/python-mrcz +Source: https://github.com/em-MRCZ/python-mrcz/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz +# PATCH-FIX-UPSTREAM https://github.com/em-MRCZ/python-mrcz/pull/15 Numpy 2.0 and deprecation fixes +Patch: numpy2.patch +# PATCH-FIX-UPSTREAM https://github.com/em-MRCZ/python-mrcz/pull/16 Remove distutils / support python >=3.12 +Patch: new-pythons.patch +BuildRequires: %{python_module blosc} +BuildRequires: %{python_module numpy} +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module setuptools} +BuildRequires: dos2unix +BuildRequires: fdupes +BuildRequires: python-rpm-macros +Requires: python-numpy +Recommends: python-blosc +BuildArch: noarch +%python_subpackages + +%description +mrcz is a package designed to supplement the venerable MRC image file +format with a highly efficient compressed variant, using the blosc +meta-compressor library to shrink files on disk and greatly accelerate +file input/output for the era of "Big Data" in electron and optical +microscopy. + +%prep +%autosetup -p1 +dos2unix README.rst + +%build +%python_build + +%install +%python_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +%check +%pytest + +%files %{python_files} +%doc AUTHORS.txt README.rst +%license LICENSE.txt +%dir %{python_sitelib}/mrcz/ +%pycache_only %{python_sitelib}/mrcz-%{version}-py%{python_version}.egg-info/ +%pycache_only %{python_sitelib}/mrcz/*.py +%pycache_only %{python_sitelib}/mrcz/__pycache__/ + +%changelog