From cc729dd579b828eb05e3f3a1c9e25bc301fa0373 Mon Sep 17 00:00:00 2001 From: jevans Date: Sat, 14 Sep 2013 21:46:58 -0400 Subject: [PATCH] Added version module. Closes #113 --- glymur/__init__.py | 3 ++ glymur/jp2k.py | 22 ++++++------ glymur/test/fixtures.py | 7 ---- glymur/test/test_config.py | 6 ++-- glymur/test/test_jp2k.py | 11 ++---- glymur/test/test_opj_suite.py | 18 ++++++---- glymur/test/test_opj_suite_write.py | 4 +-- glymur/version.py | 53 +++++++++++++++++++++++++++++ setup.py | 3 +- 9 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 glymur/version.py diff --git a/glymur/__init__.py b/glymur/__init__.py index cc80a72..bf2f625 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -2,6 +2,9 @@ """ import sys +from glymur import version +__version__ = version.version + from .jp2k import Jp2k from .jp2dump import jp2dump diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 72fc4ff..f3127bc 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -1,4 +1,8 @@ -"""Access to JPEG2000 files. +"""This file is part of glymur, a Python interface for accessing JPEG 2000. + +http://glymur.readthedocs.org + +Copyright 2013 John Evans License: MIT """ @@ -31,15 +35,9 @@ from .jp2box import ColourSpecificationBox, ContiguousCodestreamBox from .jp2box import ImageHeaderBox from .lib import openjpeg as opj from .lib import openjp2 as opj2 +from . import version from .lib import c as libc -if opj.OPENJPEG is None and opj2.OPENJP2 is None: - OPENJPEG_VERSION = '0.0.0' -elif opj2.OPENJP2 is None: - OPENJPEG_VERSION = opj.version() -else: - OPENJPEG_VERSION = opj2.version() - class Jp2k(Jp2kBox): """JPEG 2000 file. @@ -192,7 +190,7 @@ class Jp2k(Jp2kBox): cparams : CompressionParametersType(ctypes.Structure) Corresponds to cparameters_t type in openjp2 headers. """ - if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + if version.openjpeg_version_tuple[0] == 1: cparams = opj.set_default_encoder_parameters() else: cparams = opj2.set_default_encoder_parameters() @@ -998,8 +996,8 @@ class Jp2k(Jp2kBox): glymur.LibraryNotFoundError If glymur is unable to load the openjp2 library. """ - if opj2.OPENJP2 is None: - raise LibraryNotFoundError("You must have the development version " + if version.openjpeg_version_tuple[0] < 2: + raise LibraryNotFoundError("You must have at least version 2.0.0" "of OpenJP2 installed before using " "this functionality.") @@ -1341,7 +1339,7 @@ def _populate_comptparms(img_array, cparams): comp_prec = 16 numrows, numcols, num_comps = img_array.shape - if re.match(r"""1\.\d\.\d""", OPENJPEG_VERSION): + if version.openjpeg_version_tuple[0] == 1: comptparms = (opj.ImageComptParmType * num_comps)() else: comptparms = (opj2.ImageComptParmType * num_comps)() diff --git a/glymur/test/fixtures.py b/glymur/test/fixtures.py index 933222a..b872f1d 100644 --- a/glymur/test/fixtures.py +++ b/glymur/test/fixtures.py @@ -10,13 +10,6 @@ import numpy as np import glymur -# Need to know the version of the openjpeg software. If openjpeg is not -# installed, we use # '0.0.0' -OPENJPEG_VERSION = '0.0.0' -if glymur.lib.openjp2.OPENJP2 is not None: - OPENJPEG_VERSION = glymur.lib.openjp2.version() -elif glymur.lib.openjpeg.OPENJPEG is not None: - OPENJPEG_VERSION = glymur.lib.openjpeg.version() # Need to know of the libopenjp2 version is the official 2.0.0 release and NOT # the 2.0+ development version. diff --git a/glymur/test/test_config.py b/glymur/test/test_config.py index af95bd3..16af663 100644 --- a/glymur/test/test_config.py +++ b/glymur/test/test_config.py @@ -117,8 +117,10 @@ class TestConfig(unittest.TestCase): """ with patch('glymur.lib.openjp2.OPENJP2', new=None): with patch('glymur.lib.openjpeg.OPENJPEG', new=None): - with self.assertRaises(glymur.jp2k.LibraryNotFoundError): - glymur.Jp2k(self.jp2file).read_bands() + with patch('glymur.version.openjpeg_version_tuple', + new=(0, 0, 0)): + with self.assertRaises(glymur.jp2k.LibraryNotFoundError): + glymur.Jp2k(self.jp2file).read_bands() @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_write_without_library(self): diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 8e4a74c..bbf551b 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -34,7 +34,6 @@ import glymur from glymur import Jp2k from .fixtures import OPENJP2_IS_V2_OFFICIAL -from .fixtures import OPENJPEG_VERSION from .fixtures import OPJ_DATA_ROOT, opj_data_file @@ -192,7 +191,7 @@ class TestJp2k_2_1(unittest.TestCase): j.read(rlevel=1) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Not tested for 1.x") class TestJp2k_2_0(unittest.TestCase): """Test suite requiring at least version 2.0""" @@ -679,8 +678,7 @@ class TestJp2k15(unittest.TestCase): j2k.read(layer=1) @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match(r"""1\.[01234]\.\d""", - OPENJPEG_VERSION) is not None, + @unittest.skipIf(glymur.version.openjpeg_version_tuple[1] < 5, "Writing only supported with openjpeg version 1.5+.") def test_2d_rgb(self): """RGB must have at least 3 components.""" @@ -723,8 +721,7 @@ class TestJp2k15(unittest.TestCase): b'this is a test') @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") - @unittest.skipIf(re.match(r"""1\.[345]\.\d""", - OPENJPEG_VERSION) is not None, + @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Segfault on official v1.x series.") def test_openjpeg_library_message(self): """Verify the error message produced by the openjpeg library""" @@ -760,8 +757,6 @@ class TestJp2k15(unittest.TestCase): j.read(rlevel=1) -@unittest.skipIf(re.match(r"""1\.[012]\.\d""", OPENJPEG_VERSION), - "Unsupported version of openjpeg.") class TestJp2k(unittest.TestCase): """Test suite for openjpeg software starting at 1.3""" diff --git a/glymur/test/test_opj_suite.py b/glymur/test/test_opj_suite.py index 3c6b5d2..36f0a7b 100644 --- a/glymur/test/test_opj_suite.py +++ b/glymur/test/test_opj_suite.py @@ -45,7 +45,7 @@ import numpy as np from glymur import Jp2k import glymur -from .fixtures import OPENJPEG_VERSION, OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT +from .fixtures import OPENJP2_IS_V2_OFFICIAL, OPJ_DATA_ROOT from .fixtures import mse, peak_tolerance, read_pgx, opj_data_file @@ -601,7 +601,7 @@ class TestSuite(unittest.TestCase): jpdata = jp2k.read() self.assertEqual(jpdata.shape, (640, 480, 3)) - @unittest.skipIf(re.match(r"""1\.[0125]\.\d""", OPENJPEG_VERSION), + @unittest.skipIf(glymur.version.openjpeg_version_tuple[0] < 2, "Functionality not implemented for 1.x") def test_ETS_JP2_file3(self): jfile = opj_data_file('input/conformance/file3.jp2') @@ -6720,7 +6720,7 @@ class TestSuiteDump(unittest.TestCase): [8, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 10]) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Feature not supported in glymur until openjpeg 2.0") class TestSuite_bands(unittest.TestCase): """Runs tests introduced in version 1.x but only pass in glymur with 2.0 @@ -6849,7 +6849,7 @@ class TestSuite_bands(unittest.TestCase): self.assertTrue(True) -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Tests not passing until 2.0") class TestSuite2point0(unittest.TestCase): """Runs tests introduced in version 2.0 or that pass only in 2.0""" @@ -6901,13 +6901,19 @@ class TestSuite2point0(unittest.TestCase): # messages that cannot be turned off? relpath = 'input/nonregression/kakadu_v4-4_openjpegv2_broken.j2k' jfile = opj_data_file(relpath) - Jp2k(jfile).read() + if glymur.version.openjpeg_version_tuple[0] < 2: + with warnings.catch_warnings(): + # Incorrect warning issued about tile parts. + warnings.simplefilter("ignore") + Jp2k(jfile).read() + else: + Jp2k(jfile).read() self.assertTrue(True) @unittest.skipIf(OPENJP2_IS_V2_OFFICIAL, "Test not in done in v2.0.0 official") -@unittest.skipIf(re.match(r"""1\.\d.\d""", OPENJPEG_VERSION), +@unittest.skipIf(glymur.version.openjpeg_version_tuple[0] == 1, "Tests not introduced until 2.1") class TestSuite2point1(unittest.TestCase): """Runs tests introduced in version 2.0+ or that pass only in 2.0+""" diff --git a/glymur/test/test_opj_suite_write.py b/glymur/test/test_opj_suite_write.py index e187d34..2f699e6 100644 --- a/glymur/test/test_opj_suite_write.py +++ b/glymur/test/test_opj_suite_write.py @@ -20,7 +20,7 @@ else: import unittest from .fixtures import read_image, NO_READ_BACKEND, NO_READ_BACKEND_MSG -from .fixtures import OPJ_DATA_ROOT, OPENJPEG_VERSION, opj_data_file +from .fixtures import OPJ_DATA_ROOT, opj_data_file from glymur import Jp2k import glymur @@ -28,7 +28,7 @@ import glymur @unittest.skipIf(os.name == "nt", "no write support on windows, period") @unittest.skipIf(re.match(r"""1\.[01234]\.\d""", - OPENJPEG_VERSION) is not None, + glymur.version.openjpeg_version) is not None, "Writing only supported with openjpeg version 1.5+.") @unittest.skipIf(NO_READ_BACKEND, NO_READ_BACKEND_MSG) @unittest.skipIf(OPJ_DATA_ROOT is None, diff --git a/glymur/version.py b/glymur/version.py new file mode 100644 index 0000000..256ed4e --- /dev/null +++ b/glymur/version.py @@ -0,0 +1,53 @@ +# This file is part of glymur, a Python interface for accessing JPEG 2000. +# +# http://glymur.readthedocs.org +# +# Copyright 2013 John Evans +# +# License: MIT + +import sys +import numpy as np +from distutils.version import StrictVersion + +from .lib import openjpeg as opj +from .lib import openjp2 as opj2 + +version = "0.4.1" +_sv = StrictVersion(version) +version_tuple = _sv.version + + +if opj.OPENJPEG is None and opj2.OPENJP2 is None: + openjpeg_version = '0.0.0' +elif opj2.OPENJP2 is None: + openjpeg_version = opj.version() +else: + openjpeg_version = opj2.version() + +_sv = StrictVersion(openjpeg_version) +openjpeg_version_tuple = _sv.version + +__doc__ = """\ +This is glymur **{glymur_version}** + +* OPENJPEG version: **{openjpeg}** +""".format(glymur_version=version, + openjpeg=openjpeg_version) + +info = """\ +Summary of glymur configuration +------------------------------- + +glymur {glymur} +OPENJPEG {openjpeg} +Python {python} +sys.platform {platform} +sys.maxsize {maxsize} +numpy {numpy} +""".format(glymur=version, + openjpeg=openjpeg_version, + python=sys.version, + platform=sys.platform, + maxsize=sys.maxsize, + numpy=np.__version__) diff --git a/setup.py b/setup.py index ff533a7..8e6233c 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,7 @@ kwargs = {'name': 'Glymur', 'package_data': {'glymur': ['data/*.jp2', 'data/*.j2k']}, 'scripts': ['bin/jp2dump'], 'license': 'MIT', - 'test_suite': 'glymur.test', - 'platforms': ['darwin']} + 'test_suite': 'glymur.test'} instllrqrs = ['numpy>=1.4.1'] if sys.hexversion < 0x03030000: