From d99db7b3d170168cd716c274546c6d9383c602bf Mon Sep 17 00:00:00 2001 From: lelguedd Date: Thu, 14 Nov 2019 14:20:45 +0100 Subject: [PATCH 1/4] [Import Error]: Fixing the incompatibilities with the different python version --- modopt/math/metrics.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modopt/math/metrics.py b/modopt/math/metrics.py index caa8599a..07bd6b42 100644 --- a/modopt/math/metrics.py +++ b/modopt/math/metrics.py @@ -10,12 +10,24 @@ import numpy as np from scipy.ndimage import uniform_filter, gaussian_filter -try: - from skimage.metrics import structural_similarity as compare_ssim -except ImportError: # pragma: no cover - import_skimage = False -else: - import_skimage = True +import sys + +if sys.version_info.major == 3: + if sys.version_info.minor == 5: + try: + from skimage.measure import compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True + + elif sys.version_info.minor > 5: + try: + from skimage.metrics import structural_similarity as compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True def min_max_normalize(img): From c22d5b2bd0efb5514070f51d1644e22120b411b1 Mon Sep 17 00:00:00 2001 From: lelguedd Date: Thu, 14 Nov 2019 14:36:05 +0100 Subject: [PATCH 2/4] [Tests]: testing the version of python for skimage imports --- modopt/tests/test_math.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/modopt/tests/test_math.py b/modopt/tests/test_math.py index b9e412c5..f4cd705f 100644 --- a/modopt/tests/test_math.py +++ b/modopt/tests/test_math.py @@ -11,6 +11,7 @@ from unittest import TestCase, skipIf, skipUnless import numpy as np import numpy.testing as npt +import sys from modopt.math import * try: import astropy @@ -18,12 +19,22 @@ import_astropy = False else: # pragma: no cover import_astropy = True -try: - from skimage.metrics import structural_similarity -except ImportError: # pragma: no cover - import_skimage = False -else: - import_skimage = True +if sys.version_info.major == 3: + if sys.version_info.minor == 5: + try: + from skimage.measure import compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True + + elif sys.version_info.minor > 5: + try: + from skimage.metrics import structural_similarity as compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True class ConvolveTestCase(TestCase): From 84ef0226f64b3722cc376453d095f8cf151a15b0 Mon Sep 17 00:00:00 2001 From: lelguedd Date: Tue, 19 Nov 2019 16:40:56 +0100 Subject: [PATCH 3/4] Only test minor version --- modopt/math/metrics.py | 31 +++++++++++++++---------------- modopt/tests/test_math.py | 31 +++++++++++++++---------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/modopt/math/metrics.py b/modopt/math/metrics.py index 07bd6b42..f9dee059 100644 --- a/modopt/math/metrics.py +++ b/modopt/math/metrics.py @@ -12,22 +12,21 @@ from scipy.ndimage import uniform_filter, gaussian_filter import sys -if sys.version_info.major == 3: - if sys.version_info.minor == 5: - try: - from skimage.measure import compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True - - elif sys.version_info.minor > 5: - try: - from skimage.metrics import structural_similarity as compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True +if sys.version_info.minor == 5: + try: + from skimage.measure import compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True + +elif sys.version_info.minor > 5: + try: + from skimage.metrics import structural_similarity as compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True def min_max_normalize(img): diff --git a/modopt/tests/test_math.py b/modopt/tests/test_math.py index f4cd705f..2944a573 100644 --- a/modopt/tests/test_math.py +++ b/modopt/tests/test_math.py @@ -19,22 +19,21 @@ import_astropy = False else: # pragma: no cover import_astropy = True -if sys.version_info.major == 3: - if sys.version_info.minor == 5: - try: - from skimage.measure import compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True - - elif sys.version_info.minor > 5: - try: - from skimage.metrics import structural_similarity as compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True +if sys.version_info.minor == 5: + try: + from skimage.measure import compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True + +elif sys.version_info.minor > 5: + try: + from skimage.metrics import structural_similarity as compare_ssim + except ImportError: # pragma: no cover + import_skimage = False + else: + import_skimage = True class ConvolveTestCase(TestCase): From 7a4d04ba8e9ea5142cce67a75283b9a8d0cc60ff Mon Sep 17 00:00:00 2001 From: lelguedd Date: Wed, 20 Nov 2019 16:17:51 +0100 Subject: [PATCH 4/4] Reducing the number of lines --- modopt/math/metrics.py | 20 +++++++------------- modopt/tests/test_math.py | 20 +++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/modopt/math/metrics.py b/modopt/math/metrics.py index f9dee059..7beb154b 100644 --- a/modopt/math/metrics.py +++ b/modopt/math/metrics.py @@ -12,21 +12,15 @@ from scipy.ndimage import uniform_filter, gaussian_filter import sys -if sys.version_info.minor == 5: - try: +try: + if sys.version_info.minor == 5: from skimage.measure import compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True - -elif sys.version_info.minor > 5: - try: + elif sys.version_info.minor > 5: from skimage.metrics import structural_similarity as compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True +except ImportError: # pragma: no cover + import_skimage = False +else: + import_skimage = True def min_max_normalize(img): diff --git a/modopt/tests/test_math.py b/modopt/tests/test_math.py index 2944a573..9aa76f44 100644 --- a/modopt/tests/test_math.py +++ b/modopt/tests/test_math.py @@ -19,21 +19,15 @@ import_astropy = False else: # pragma: no cover import_astropy = True -if sys.version_info.minor == 5: - try: +try: + if sys.version_info.minor == 5: from skimage.measure import compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True - -elif sys.version_info.minor > 5: - try: + elif sys.version_info.minor > 5: from skimage.metrics import structural_similarity as compare_ssim - except ImportError: # pragma: no cover - import_skimage = False - else: - import_skimage = True +except ImportError: # pragma: no cover + import_skimage = False +else: + import_skimage = True class ConvolveTestCase(TestCase):