[pygobject] Bug 589671 - Dont use generate-constants



commit 5d159a13d89587cba189a0ca3203ac003e2f1f2b
Author: John Stowers <john stowers gmail com>
Date:   Thu Apr 15 22:52:48 2010 +1200

    Bug 589671 - Dont use generate-constants
    
    This breaks the build using distutils, and it is
    largely unneeded. Just add the G_XXX constants
    to the module directly

 gobject/Makefile.am          |   16 +--------
 gobject/constants.py         |   83 ++++++++++++++++++++++++++++++++++++++++++
 gobject/constants.py.in      |   50 -------------------------
 gobject/generate-constants.c |   44 ----------------------
 gobject/gobjectmodule.c      |   35 ++++++++++++++++++
 setup.py                     |    2 +-
 tests/runtests.py            |    3 +-
 7 files changed, 121 insertions(+), 112 deletions(-)
---
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index e5d7f7b..aff1609 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -10,28 +10,15 @@ pkgpyexecdir = $(pyexecdir)/gtk-2.0
 pygobjectdir = $(pkgpyexecdir)/gobject
 pygobject_PYTHON = 	\
 	__init__.py 	\
+	constants.py	\
 	propertyhelper.py
 pygobject_LTLIBRARIES = _gobject.la 
-nodist_pygobject_PYTHON = constants.py
 
 common_ldflags = -module -avoid-version
 if PLATFORM_WIN32
 common_ldflags += -no-undefined
 endif
 
-constants.py: generate-constants$(EXEEXT) constants.py.in
-	rm -f constants.py
-	cp $(srcdir)/constants.py.in constants.py
-	chmod 644 constants.py
-	$(top_builddir)/gobject/generate-constants$(EXEEXT) >> constants.py
-	chmod 444 constants.py
-
-generate_constants_CFLAGS = $(GLIB_CFLAGS) $(PYTHON_INCLUDES)
-
-noinst_PROGRAMS = generate-constants
-CLEANFILES = constants.py
-EXTRA_DIST = constants.py.in
-
 _gobject_la_CFLAGS = \
 	-I$(top_srcdir)/glib \
 	$(PYTHON_INCLUDES) \
@@ -63,7 +50,6 @@ _gobject_la_SOURCES =           \
         pygtype.c               \
         pygtype.h		\
 	pygi-external.h
-_gobject_la_DEPENDENCIES = constants.py
 
 if HAVE_LIBFFI
 _gobject_la_SOURCES += ffi-marshaller.c ffi-marshaller.h
diff --git a/gobject/constants.py b/gobject/constants.py
new file mode 100644
index 0000000..a6d3ce9
--- /dev/null
+++ b/gobject/constants.py
@@ -0,0 +1,83 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# pygobject - Python bindings for the GObject library
+# Copyright (C) 2006-2007 Johan Dahlin
+#
+#   gobject/constants.py: GObject type constants
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+# USA
+
+import sys
+
+import gobject._gobject
+_gobject = sys.modules['gobject._gobject']
+
+# TYPE_INVALID defined in gobjectmodule.c
+TYPE_NONE = _gobject.type_from_name('void')
+TYPE_INTERFACE = _gobject.type_from_name('GInterface')
+TYPE_CHAR = _gobject.type_from_name('gchar')
+TYPE_UCHAR = _gobject.type_from_name('guchar')
+TYPE_BOOLEAN = _gobject.type_from_name('gboolean')
+TYPE_INT = _gobject.type_from_name('gint')
+TYPE_UINT = _gobject.type_from_name('guint')
+TYPE_LONG = _gobject.type_from_name('glong')
+TYPE_ULONG = _gobject.type_from_name('gulong')
+TYPE_INT64 = _gobject.type_from_name('gint64')
+TYPE_UINT64 = _gobject.type_from_name('guint64')
+TYPE_ENUM = _gobject.type_from_name('GEnum')
+TYPE_FLAGS = _gobject.type_from_name('GFlags')
+TYPE_FLOAT = _gobject.type_from_name('gfloat')
+TYPE_DOUBLE = _gobject.type_from_name('gdouble')
+TYPE_STRING = _gobject.type_from_name('gchararray')
+TYPE_POINTER = _gobject.type_from_name('gpointer')
+TYPE_BOXED = _gobject.type_from_name('GBoxed')
+TYPE_PARAM = _gobject.type_from_name('GParam')
+TYPE_OBJECT = _gobject.type_from_name('GObject')
+TYPE_PYOBJECT = _gobject.type_from_name('PyObject')
+TYPE_UNICHAR = TYPE_UINT
+
+# do a little dance to maintain API compatibility
+# as these were origianally defined here, and are
+# now defined in gobjectmodule.c
+G_MINFLOAT = _gobject.G_MINFLOAT
+G_MAXFLOAT = _gobject.G_MAXFLOAT
+G_MINDOUBLE = _gobject.G_MINDOUBLE
+G_MAXDOUBLE = _gobject.G_MAXDOUBLE
+G_MINSHORT = _gobject.G_MINSHORT
+G_MAXSHORT = _gobject.G_MAXSHORT
+G_MAXUSHORT = _gobject.G_MAXUSHORT
+G_MININT = _gobject.G_MININT
+G_MAXINT = _gobject.G_MAXINT
+G_MAXUINT = _gobject.G_MAXUINT
+G_MINLONG = _gobject.G_MINLONG
+G_MAXLONG = _gobject.G_MAXLONG
+G_MAXULONG = _gobject.G_MAXULONG
+G_MININT8 = _gobject.G_MININT8
+G_MAXINT8 = _gobject.G_MAXINT8
+G_MAXUINT8 = _gobject.G_MAXUINT8
+G_MININT16 = _gobject.G_MININT16
+G_MAXINT16 = _gobject.G_MAXINT16
+G_MAXUINT16 = _gobject.G_MAXUINT16
+G_MININT32 = _gobject.G_MININT32
+G_MAXINT32 = _gobject.G_MAXINT32
+G_MAXUINT32 = _gobject.G_MAXUINT32
+G_MININT64 = _gobject.G_MININT64
+G_MAXINT64 = _gobject.G_MAXINT64
+G_MAXUINT64 = _gobject.G_MAXUINT64
+G_MAXSIZE = _gobject.G_MAXSIZE
+G_MAXSSIZE = _gobject.G_MAXSSIZE
+G_MINOFFSET = _gobject.G_MINOFFSET
+G_MAXOFFSET = _gobject.G_MAXOFFSET
+
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index 73bfc3c..6fc7b51 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -2522,6 +2522,41 @@ pygobject_register_api(PyObject *d)
 static void
 pygobject_register_constants(PyObject *m)
 {
+    /* PyFloat_ return a new ref, and add object takes the ref */
+    PyModule_AddObject(m,       "G_MINFLOAT", PyFloat_FromDouble(G_MINFLOAT));
+    PyModule_AddObject(m,       "G_MAXFLOAT", PyFloat_FromDouble(G_MAXFLOAT));
+    PyModule_AddObject(m,       "G_MINDOUBLE", PyFloat_FromDouble(G_MINDOUBLE));
+    PyModule_AddObject(m,       "G_MAXDOUBLE", PyFloat_FromDouble(G_MAXDOUBLE));
+    PyModule_AddIntConstant(m,  "G_MINSHORT", G_MINSHORT);
+    PyModule_AddIntConstant(m,  "G_MAXSHORT", G_MAXSHORT);
+    PyModule_AddIntConstant(m,  "G_MAXUSHORT", G_MAXUSHORT);
+    PyModule_AddIntConstant(m,  "G_MININT", G_MININT);
+    PyModule_AddIntConstant(m,  "G_MAXINT", G_MAXINT);
+    PyModule_AddObject(m,       "G_MINLONG", PyLong_FromLong(G_MINLONG));
+    PyModule_AddObject(m,       "G_MAXLONG", PyLong_FromLong(G_MAXLONG));
+    PyModule_AddObject(m,       "G_MAXULONG", PyLong_FromUnsignedLong(G_MAXULONG));
+    PyModule_AddIntConstant(m,  "G_MININT8", G_MININT8);
+    PyModule_AddIntConstant(m,  "G_MAXINT8", G_MAXINT8);
+    PyModule_AddIntConstant(m,  "G_MAXUINT8", G_MAXUINT8);
+    PyModule_AddIntConstant(m,  "G_MININT16", G_MININT16);
+    PyModule_AddIntConstant(m,  "G_MAXINT16", G_MAXINT16);
+    PyModule_AddIntConstant(m,  "G_MAXUINT16", G_MAXUINT16);
+    PyModule_AddIntConstant(m,  "G_MININT32", G_MININT32);
+    PyModule_AddIntConstant(m,  "G_MAXINT32", G_MAXINT32);
+    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));
+    PyModule_AddObject(m,       "G_MAXSIZE", PyLong_FromSize_t(G_MAXSIZE));
+    PyModule_AddObject(m,       "G_MAXSSIZE", PyLong_FromSsize_t(G_MAXSSIZE));
+    PyModule_AddObject(m,       "G_MINOFFSET", PyLong_FromLongLong(G_MINOFFSET));
+    PyModule_AddObject(m,       "G_MAXOFFSET", PyLong_FromLongLong(G_MAXOFFSET));
+
+    /* in order for test_properties to pass, G_MAXUINT must be initialized using
+       PyLong_FromUnsignedLong, despite AFAICT it is unecessary for 32bit int types.
+       In the interests of consistancy I did the same for MAXUINT32 */
+    PyModule_AddObject(m,       "G_MAXUINT32", PyLong_FromUnsignedLong(G_MAXUINT32));
+    PyModule_AddObject(m,       "G_MAXUINT", PyLong_FromUnsignedLong(G_MAXUINT));
+
     PyModule_AddIntConstant(m, "SIGNAL_RUN_FIRST", G_SIGNAL_RUN_FIRST);
     PyModule_AddIntConstant(m, "SIGNAL_RUN_LAST", G_SIGNAL_RUN_LAST);
     PyModule_AddIntConstant(m, "SIGNAL_RUN_CLEANUP", G_SIGNAL_RUN_CLEANUP);
diff --git a/setup.py b/setup.py
index fcd7e63..50f7abe 100755
--- a/setup.py
+++ b/setup.py
@@ -207,7 +207,7 @@ if gobject.can_build():
     data_files.append((HTML_DIR, glob.glob('docs/html/*.html')))
     data_files.append((HTML_DIR, ['docs/style.css']))
     data_files.append((XSL_DIR,  glob.glob('docs/xsl/*.xsl')))
-    py_modules += ['gobject.__init__', 'gobject.propertyhelper']
+    py_modules += ['gobject.__init__', 'gobject.propertyhelper', 'gobject.constants']
 else:
     print
     print 'ERROR: Nothing to do, gobject could not be found and is essential.'
diff --git a/tests/runtests.py b/tests/runtests.py
index fc0558d..da5ade0 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -21,8 +21,7 @@ else:
 common.importModules(buildDir=buildDir,
                      srcDir=srcDir)
 
-SKIP_FILES = ['common', 'runtests',
-              'test_enum', 'test_conversion']
+SKIP_FILES = ['common', 'runtests']
 
 dir = os.path.split(os.path.abspath(__file__))[0]
 os.chdir(dir)



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