diff options
Diffstat (limited to 'silx/io')
-rw-r--r-- | silx/io/commonh5.py | 8 | ||||
-rw-r--r-- | silx/io/fabioh5.py | 4 | ||||
-rw-r--r-- | silx/io/specfile.c | 55 | ||||
-rw-r--r-- | silx/io/test/test_specfile.py | 13 | ||||
-rw-r--r-- | silx/io/test/test_spech5.py | 11 | ||||
-rw-r--r-- | silx/io/test/test_spectoh5.py | 4 | ||||
-rw-r--r-- | silx/io/test/test_utils.py | 20 | ||||
-rw-r--r-- | silx/io/utils.py | 7 |
8 files changed, 100 insertions, 22 deletions
diff --git a/silx/io/commonh5.py b/silx/io/commonh5.py index 2956714..b624816 100644 --- a/silx/io/commonh5.py +++ b/silx/io/commonh5.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2018 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -29,6 +29,10 @@ files. They are used in :mod:`spech5` and :mod:`fabioh5`. library, which is not a mandatory dependency for `silx`. """ import collections +try: + from collections import abc +except ImportError: # Python2 support + import collections as abc import weakref import h5py @@ -42,7 +46,7 @@ __license__ = "MIT" __date__ = "02/07/2018" -class _MappingProxyType(collections.MutableMapping): +class _MappingProxyType(abc.MutableMapping): """Read-only dictionary This class is available since Python 3.3, but not on earlyer Python diff --git a/silx/io/fabioh5.py b/silx/io/fabioh5.py index 27ef3fd..351b981 100644 --- a/silx/io/fabioh5.py +++ b/silx/io/fabioh5.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2018 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -474,7 +474,7 @@ class FabioReader(object): while len(location) < max_dim: location.append(0) normalized_image = numpy.zeros(max_shape, dtype=image.dtype) - normalized_image[location] = image + normalized_image[tuple(location)] = image images[index] = normalized_image # create a cube diff --git a/silx/io/specfile.c b/silx/io/specfile.c index 0cc1195..f8e7ed8 100644 --- a/silx/io/specfile.c +++ b/silx/io/specfile.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.7 */ +/* Generated by Cython 0.29.11 */ /* BEGIN: Cython Metadata { @@ -41,8 +41,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_7" -#define CYTHON_HEX_VERSION 0x001D07F0 +#define CYTHON_ABI "0_29_11" +#define CYTHON_HEX_VERSION 0x001D0BF0 #define CYTHON_FUTURE_DIVISION 1 #include <stddef.h> #ifndef offsetof @@ -344,8 +344,16 @@ END: Cython Metadata */ #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#if PY_VERSION_HEX < 0x030800A4 #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#elif PY_VERSION_HEX >= 0x030800B2 + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES @@ -28176,6 +28184,9 @@ static PyTypeObject __pyx_type_4silx_2io_8specfile_SpecFile = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static struct __pyx_obj_4silx_2io_8specfile___pyx_scope_struct____iter__ *__pyx_freelist_4silx_2io_8specfile___pyx_scope_struct____iter__[8]; @@ -28271,6 +28282,9 @@ static PyTypeObject __pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static struct __pyx_obj_4silx_2io_8specfile___pyx_scope_struct_1___iter__ *__pyx_freelist_4silx_2io_8specfile___pyx_scope_struct_1___iter__[8]; @@ -28366,6 +28380,9 @@ static PyTypeObject __pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__ #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static struct __pyx_vtabstruct_array __pyx_vtable_array; @@ -28544,6 +28561,9 @@ static PyTypeObject __pyx_type___pyx_array = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static PyObject *__pyx_tp_new_Enum(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { @@ -28652,6 +28672,9 @@ static PyTypeObject __pyx_type___pyx_MemviewEnum = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static struct __pyx_vtabstruct_memoryview __pyx_vtable_memoryview; @@ -28902,6 +28925,9 @@ static PyTypeObject __pyx_type___pyx_memoryview = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static struct __pyx_vtabstruct__memoryviewslice __pyx_vtable__memoryviewslice; @@ -29037,6 +29063,9 @@ static PyTypeObject __pyx_type___pyx_memoryviewslice = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif }; static PyMethodDef __pyx_methods[] = { @@ -30192,7 +30221,9 @@ static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ if (PyType_Ready(&__pyx_type_4silx_2io_8specfile_SpecFile) < 0) __PYX_ERR(0, 629, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type_4silx_2io_8specfile_SpecFile.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_4silx_2io_8specfile_SpecFile.tp_dictoffset && __pyx_type_4silx_2io_8specfile_SpecFile.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_4silx_2io_8specfile_SpecFile.tp_getattro = __Pyx_PyObject_GenericGetAttr; } @@ -30240,13 +30271,17 @@ static int __Pyx_modinit_type_init_code(void) { if (__Pyx_setup_reduce((PyObject*)&__pyx_type_4silx_2io_8specfile_SpecFile) < 0) __PYX_ERR(0, 629, __pyx_L1_error) __pyx_ptype_4silx_2io_8specfile_SpecFile = &__pyx_type_4silx_2io_8specfile_SpecFile; if (PyType_Ready(&__pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__) < 0) __PYX_ERR(0, 300, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__.tp_dictoffset && __pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } __pyx_ptype_4silx_2io_8specfile___pyx_scope_struct____iter__ = &__pyx_type_4silx_2io_8specfile___pyx_scope_struct____iter__; if (PyType_Ready(&__pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__) < 0) __PYX_ERR(0, 680, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__.tp_dictoffset && __pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_4silx_2io_8specfile___pyx_scope_struct_1___iter__.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; } @@ -30254,12 +30289,16 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_vtabptr_array = &__pyx_vtable_array; __pyx_vtable_array.get_memview = (PyObject *(*)(struct __pyx_array_obj *))__pyx_array_get_memview; if (PyType_Ready(&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 105, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type___pyx_array.tp_print = 0; + #endif if (__Pyx_SetVtable(__pyx_type___pyx_array.tp_dict, __pyx_vtabptr_array) < 0) __PYX_ERR(1, 105, __pyx_L1_error) if (__Pyx_setup_reduce((PyObject*)&__pyx_type___pyx_array) < 0) __PYX_ERR(1, 105, __pyx_L1_error) __pyx_array_type = &__pyx_type___pyx_array; if (PyType_Ready(&__pyx_type___pyx_MemviewEnum) < 0) __PYX_ERR(1, 279, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type___pyx_MemviewEnum.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_MemviewEnum.tp_dictoffset && __pyx_type___pyx_MemviewEnum.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type___pyx_MemviewEnum.tp_getattro = __Pyx_PyObject_GenericGetAttr; } @@ -30274,7 +30313,9 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_vtable_memoryview.convert_item_to_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *))__pyx_memoryview_convert_item_to_object; __pyx_vtable_memoryview.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryview_assign_item_from_object; if (PyType_Ready(&__pyx_type___pyx_memoryview) < 0) __PYX_ERR(1, 330, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type___pyx_memoryview.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryview.tp_dictoffset && __pyx_type___pyx_memoryview.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type___pyx_memoryview.tp_getattro = __Pyx_PyObject_GenericGetAttr; } @@ -30287,7 +30328,9 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_vtable__memoryviewslice.__pyx_base.assign_item_from_object = (PyObject *(*)(struct __pyx_memoryview_obj *, char *, PyObject *))__pyx_memoryviewslice_assign_item_from_object; __pyx_type___pyx_memoryviewslice.tp_base = __pyx_memoryview_type; if (PyType_Ready(&__pyx_type___pyx_memoryviewslice) < 0) __PYX_ERR(1, 961, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type___pyx_memoryviewslice.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type___pyx_memoryviewslice.tp_dictoffset && __pyx_type___pyx_memoryviewslice.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type___pyx_memoryviewslice.tp_getattro = __Pyx_PyObject_GenericGetAttr; } @@ -35245,6 +35288,9 @@ static PyTypeObject __pyx_CyFunctionType_type = { #if PY_VERSION_HEX >= 0x030400a1 0, #endif +#if PY_VERSION_HEX >= 0x030800b1 + 0, +#endif }; static int __pyx_CyFunction_init(void) { __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); @@ -37223,6 +37269,9 @@ static PyTypeObject __pyx_GeneratorType_type = { #elif PY_VERSION_HEX >= 0x030400a1 0, #endif +#if PY_VERSION_HEX >= 0x030800b1 + 0, +#endif }; static int __pyx_Generator_init(void) { __pyx_GeneratorType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; diff --git a/silx/io/test/test_specfile.py b/silx/io/test/test_specfile.py index 55850f1..79d5544 100644 --- a/silx/io/test/test_specfile.py +++ b/silx/io/test/test_specfile.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2017 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -224,14 +224,21 @@ class TestSpecFile(unittest.TestCase): with self.assertRaises(specfile.SfErrScanNotFound): self.sf.index(99) + def assertRaisesRegex(self, *args, **kwargs): + # Python 2 compatibility + if sys.version_info.major >= 3: + return super(TestSpecFile, self).assertRaisesRegex(*args, **kwargs) + else: + return self.assertRaisesRegexp(*args, **kwargs) + def test_getitem(self): self.assertIsInstance(self.sf[2], Scan) self.assertIsInstance(self.sf["1.2"], Scan) # int out of range - with self.assertRaisesRegexp(IndexError, 'Scan index must be in ran'): + with self.assertRaisesRegex(IndexError, 'Scan index must be in ran'): self.sf[107] # float indexing not allowed - with self.assertRaisesRegexp(TypeError, 'The scan identification k'): + with self.assertRaisesRegex(TypeError, 'The scan identification k'): self.sf[1.2] # non existant scan with "N.M" indexing with self.assertRaises(KeyError): diff --git a/silx/io/test/test_spech5.py b/silx/io/test/test_spech5.py index 7c8ed5d..0263c3c 100644 --- a/silx/io/test/test_spech5.py +++ b/silx/io/test/test_spech5.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2018 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -272,6 +272,13 @@ class TestSpecH5(unittest.TestCase): self.assertEqual(self.sfh5["25.1/start_time"], u"2015-03-14T03:53:50") + def assertRaisesRegex(self, *args, **kwargs): + # Python 2 compatibility + if sys.version_info.major >= 3: + return super(TestSpecH5, self).assertRaisesRegex(*args, **kwargs) + else: + return self.assertRaisesRegexp(*args, **kwargs) + def testDatasetInstanceAttr(self): """The SpecH5Dataset objects must implement some dummy attributes to improve compatibility with widgets dealing with h5py datasets.""" @@ -279,7 +286,7 @@ class TestSpecH5(unittest.TestCase): self.assertIsNone(self.sfh5["1.1"]["measurement"]["MRTSlit UP"].chunks) # error message must be explicit - with self.assertRaisesRegexp( + with self.assertRaisesRegex( AttributeError, "SpecH5Dataset has no attribute tOTo"): dummy = self.sfh5["/1.1/start_time"].tOTo diff --git a/silx/io/test/test_spectoh5.py b/silx/io/test/test_spectoh5.py index 2b79704..44b59e0 100644 --- a/silx/io/test/test_spectoh5.py +++ b/silx/io/test/test_spectoh5.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2018 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -132,7 +132,7 @@ class TestConvertSpecHDF5(unittest.TestCase): def testTitle(self): """Test the value of a dataset""" - title12 = self.h5f["/1.2/title"].value + title12 = self.h5f["/1.2/title"][()] self.assertEqual(title12, u"aaaaaa") diff --git a/silx/io/test/test_utils.py b/silx/io/test/test_utils.py index 5a4c629..56f89fc 100644 --- a/silx/io/test/test_utils.py +++ b/silx/io/test/test_utils.py @@ -1,6 +1,6 @@ # coding: utf-8 # /*########################################################################## -# Copyright (C) 2016-2018 European Synchrotron Radiation Facility +# Copyright (C) 2016-2019 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ import re import shutil import tempfile import unittest +import sys from .. import utils import silx.io.url @@ -102,6 +103,13 @@ class TestSave(unittest.TestCase): os.unlink(self.npy_fname) shutil.rmtree(self.tempdir) + def assertRegex(self, *args, **kwargs): + # Python 2 compatibility + if sys.version_info.major >= 3: + return super(TestSave, self).assertRegex(*args, **kwargs) + else: + return self.assertRegexpMatches(*args, **kwargs) + def test_save_csv(self): utils.save1D(self.csv_fname, self.x, self.y, xlabel=self.xlab, ylabels=self.ylabs, @@ -112,7 +120,7 @@ class TestSave(unittest.TestCase): actual_csv = csvf.read() csvf.close() - self.assertRegexpMatches(actual_csv, expected_csv) + self.assertRegex(actual_csv, expected_csv) def test_save_npy(self): """npy file is saved with numpy.save after building a numpy array @@ -138,7 +146,7 @@ class TestSave(unittest.TestCase): actual_spec = specf.read() specf.close() - self.assertRegexpMatches(actual_spec, expected_spec1) + self.assertRegex(actual_spec, expected_spec1) def test_savespec_file_handle(self): """Save SpecFile using savespec(), passing a file handle""" @@ -158,7 +166,7 @@ class TestSave(unittest.TestCase): actual_spec = specf.read() specf.close() - self.assertRegexpMatches(actual_spec, expected_spec2) + self.assertRegex(actual_spec, expected_spec2) def test_save_spec(self): """Save SpecFile using save()""" @@ -168,7 +176,7 @@ class TestSave(unittest.TestCase): specf = open(self.spec_fname) actual_spec = specf.read() specf.close() - self.assertRegexpMatches(actual_spec, expected_spec2) + self.assertRegex(actual_spec, expected_spec2) def test_save_csv_no_labels(self): """Save csv using save(), with autoheader=True but @@ -189,7 +197,7 @@ class TestSave(unittest.TestCase): csvf = open(self.csv_fname) actual_csv = csvf.read() csvf.close() - self.assertRegexpMatches(actual_csv, expected_csv2) + self.assertRegex(actual_csv, expected_csv2) def assert_match_any_string_in_list(test, pattern, list_of_strings): diff --git a/silx/io/utils.py b/silx/io/utils.py index 930c84e..f294101 100644 --- a/silx/io/utils.py +++ b/silx/io/utils.py @@ -52,7 +52,7 @@ except ImportError as e: logger = logging.getLogger(__name__) -NEXUS_HDF5_EXT = [".h5", ".nx5", ".nxs", ".hdf", ".hdf5", ".cxi"] +NEXUS_HDF5_EXT = [".h5", ".nx5", ".nxs", ".hdf", ".hdf5", ".cxi"] """List of possible extensions for HDF5 file formats.""" @@ -460,7 +460,10 @@ def _open_local_file(filename): "File '%s' can't be read as a numpy file." % filename)) if h5py.is_hdf5(filename): - return h5py.File(filename, "r") + try: + return h5py.File(filename, "r") + except OSError: + return h5py.File(filename, "r", libver='latest', swmr=True) try: from . import fabioh5 |