[pygobject] Fix for python 2.6, drop support for < 2.6



commit 6123e6f5001ca5eaea18123d8a53525abab31a45
Author: Martin Pitt <martinpitt gnome org>
Date:   Thu Aug 23 06:44:27 2012 +0200

    Fix for python 2.6, drop support for < 2.6
    
    Replace sys.version_info.major access to tuple access which also works for
    Python 2.6.
    
    When building for Python 2.6, inject some missing unittest API such as
    @unittest.skipUnless and assertGreaterEqual() into the unittest module in
    runtests.py, so that the tests have a chance to run.
    
    As building with Python 2.5 has been broken for a long time with nobody
    complaining, and 2.5 is ancient, bump minimum Python requirement to 2.6. Drop
    obsolete #ifdef paths which only apply to <= 2.5.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=682422

 configure.ac                    |    2 +-
 gi/_glib/pyglib-python-compat.h |    8 --------
 gi/_gobject/gobjectmodule.c     |    8 --------
 gi/module.py                    |    2 +-
 tests/runtests.py               |   27 +++++++++++++++++++++++++++
 tests/test_gi.py                |    2 +-
 6 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e1f9330..0c1a3bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AC_PREREQ(2.52)
 # Python 3 as python3 to configure to compile pygobject under Python 3
 # you would do this:
 # $> PYTHON=python3 ./configure
-m4_define(python_min_ver, 2.5.2)
+m4_define(python_min_ver, 2.6)
 m4_define(python3_min_ver, 3.1)
 
 dnl the pygobject version number
diff --git a/gi/_glib/pyglib-python-compat.h b/gi/_glib/pyglib-python-compat.h
index 8c1dd51..5af14f8 100644
--- a/gi/_glib/pyglib-python-compat.h
+++ b/gi/_glib/pyglib-python-compat.h
@@ -33,14 +33,6 @@
         } while (0)
 #endif
 
-/* Compilation on Python 2.4 */
-#if PY_VERSION_HEX < 0x02050000
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-typedef inquiry lenfunc;
-#endif
-
 /* PyCObject superceded by PyCapsule on Python >= 2.7
  * However since this effects header files used by
  * static bindings we are only applying the change to
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 441b9c7..2b976aa 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -2445,16 +2445,8 @@ pygobject_register_constants(PyObject *m)
     PyModule_AddObject(m,       "G_MININT64", PyLong_FromLongLong(G_MININT64));
     PyModule_AddObject(m,       "G_MAXINT64", PyLong_FromLongLong(G_MAXINT64));
     PyModule_AddObject(m,       "G_MAXUINT64", PyLong_FromUnsignedLongLong(G_MAXUINT64));
-#if PY_VERSION_HEX < 0x02050000 /* 2.3, 2.4 */
-    PyModule_AddObject(m,       "G_MAXSIZE", PyLong_FromUnsignedLongLong(G_MAXSIZE));
-    PyModule_AddObject(m,       "G_MAXSSIZE", PyLong_FromUnsignedLongLong(G_MAXSSIZE));
-#elif PY_VERSION_HEX < 0x02060000 /* 2.5 */
-    PyModule_AddObject(m,       "G_MAXSIZE", PYGLIB_PyLong_FromSize_t(G_MAXSIZE));
-    PyModule_AddObject(m,       "G_MAXSSIZE", PYGLIB_PyLong_FromSsize_t(G_MAXSSIZE));
-#else /* 2.6+ */
     PyModule_AddObject(m,       "G_MAXSIZE", PyLong_FromSize_t(G_MAXSIZE));
     PyModule_AddObject(m,       "G_MAXSSIZE", PyLong_FromSsize_t(G_MAXSSIZE));
-#endif
     PyModule_AddObject(m,       "G_MINOFFSET", PyLong_FromLongLong(G_MINOFFSET));
     PyModule_AddObject(m,       "G_MAXOFFSET", PyLong_FromLongLong(G_MAXOFFSET));
 
diff --git a/gi/module.py b/gi/module.py
index 0fccbe6..e115fc7 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -25,7 +25,7 @@ from __future__ import absolute_import
 import sys
 import types
 
-_have_py3 = (sys.version_info.major >= 3)
+_have_py3 = (sys.version_info[0] >= 3)
 
 from . import _glib, _gobject
 try:
diff --git a/tests/runtests.py b/tests/runtests.py
index b821c26..efc2e1c 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -7,6 +7,33 @@ import sys
 
 import unittest
 
+# provide missing unittest decorators and API for python 2.6; these decorators
+# do not actually work, just avoid the syntax failure
+if sys.version_info[:2] == (2, 6):
+    def skipUnless(condition, reason):
+        if not condition:
+            sys.stderr.write('[expected failure] ')
+        return lambda obj: obj
+
+    unittest.skipUnless = skipUnless
+    unittest.expectedFailure = lambda obj: obj
+
+    def assertGreater(self, a, b, msg=None):
+        if not a > b:
+            self.fail('%s not greater than %s' % (repr(a), repr(b)))
+
+    def assertGreaterEqual(self, a, b, msg=None):
+        if not a >= b:
+            self.fail('%s not greater than or equal to %s' % (repr(a), repr(b)))
+
+    def assertIsInstance(self, obj, cls, msg=None):
+        if not isinstance(obj, cls):
+            self.fail('%s is not an instance of %r' % (repr(obj), cls))
+
+    unittest.TestCase.assertGreaterEqual = assertGreaterEqual
+    unittest.TestCase.assertGreater = assertGreater
+    unittest.TestCase.assertIsInstance = assertIsInstance
+
 if '--help' in sys.argv:
     print("Usage: ./runtests.py <testfiles>")
     sys.exit(0)
diff --git a/tests/test_gi.py b/tests/test_gi.py
index fbe832c..c22a488 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2358,7 +2358,7 @@ class TestModule(unittest.TestCase):
     def test_help(self):
         orig_stdout = sys.stdout
         try:
-            if sys.version_info.major < 3:
+            if sys.version_info < (3, 0):
                 sys.stdout = BytesIO()
             else:
                 sys.stdout = StringIO()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]