[pygobject] refactor to use the new internal _glib and _gobject modules
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] refactor to use the new internal _glib and _gobject modules
- Date: Thu, 11 Aug 2011 12:48:40 +0000 (UTC)
commit 65ac35cca8d24f4c133991e1c6ac02f49416a9a4
Author: John (J5) Palmieri <johnp redhat com>
Date: Fri Jul 22 11:10:46 2011 -0400
refactor to use the new internal _glib and _gobject modules
* use relative imports instead of aboslute
* fix the C imports to import the internal _gobject libs
* add a check to see if the PyGObject 2 gobject module
was already imported
https://bugzilla.gnome.org/show_bug.cgi?id=642048
gi/_gobject/__init__.py | 20 +++++++++++++-------
gi/_gobject/constants.py | 3 +--
gi/_gobject/gobjectmodule.c | 2 +-
gi/_gobject/propertyhelper.py | 11 +++++------
gi/_gobject/pygobject.c | 16 ++++++++--------
gi/_gobject/pygobject.h | 2 +-
6 files changed, 29 insertions(+), 25 deletions(-)
---
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 1858d18..4406463 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -23,14 +23,14 @@
import sys
-from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
+from .._glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \
io_add_watch, source_remove, child_watch_add, markup_escape_text, \
get_current_time, filename_display_name, filename_display_basename, \
filename_from_utf8, get_application_name, set_application_name, \
get_prgname, set_prgname, main_depth, Pid, GError, glib_version, \
MainLoop, MainContext, main_context_default, IOChannel, Source, Idle, \
Timeout, PollFD, OptionGroup, OptionContext, option, uri_list_extract_uris
-from glib import SPAWN_LEAVE_DESCRIPTORS_OPEN, SPAWN_DO_NOT_REAP_CHILD, \
+from .._glib import SPAWN_LEAVE_DESCRIPTORS_OPEN, SPAWN_DO_NOT_REAP_CHILD, \
SPAWN_SEARCH_PATH, SPAWN_STDOUT_TO_DEV_NULL, SPAWN_STDERR_TO_DEV_NULL, \
SPAWN_CHILD_INHERITS_STDIN, SPAWN_FILE_AND_ARGV_ZERO, PRIORITY_HIGH, \
PRIORITY_DEFAULT, PRIORITY_HIGH_IDLE, PRIORITY_DEFAULT_IDLE, \
@@ -44,13 +44,18 @@ from glib import SPAWN_LEAVE_DESCRIPTORS_OPEN, SPAWN_DO_NOT_REAP_CHILD, \
OPTION_ERROR_UNKNOWN_OPTION, OPTION_ERROR_BAD_VALUE, \
OPTION_ERROR_FAILED, OPTION_REMAINING, OPTION_ERROR
-from gobject.constants import *
-from gobject._gobject import *
+from .constants import *
+from ._gobject import *
+
+# we can't have pygobject 2 loaded at the same time we load the internal _gobject
+if 'gobject' is sys.modules:
+ raise ImportError("The gobject module is already imported. PyGObject 3 can not be run in the same namespace as PyGObject 2")
+
_PyGObject_API = _gobject._PyGObject_API
-from gobject.propertyhelper import property
+from .propertyhelper import property
-sys.modules['gobject.option'] = option
+sys.modules['gi._gobject.option'] = option
class GObjectMeta(type):
"Metaclass for automatically registering GObject classes"
@@ -112,6 +117,7 @@ class GObjectMeta(type):
return
type_register(cls, namespace.get('__gtype_name__'))
+
_gobject._install_metaclass(GObjectMeta)
-del _gobject
+#del _gobject
diff --git a/gi/_gobject/constants.py b/gi/_gobject/constants.py
index a6d3ce9..ff970ae 100644
--- a/gi/_gobject/constants.py
+++ b/gi/_gobject/constants.py
@@ -21,8 +21,7 @@
import sys
-import gobject._gobject
-_gobject = sys.modules['gobject._gobject']
+from . import _gobject
# TYPE_INVALID defined in gobjectmodule.c
TYPE_NONE = _gobject.type_from_name('void')
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index 65ae730..ac0a6f4 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -2606,7 +2606,7 @@ pygobject_register_warnings(PyObject *d)
}
-PYGLIB_MODULE_START(_gobject, "gobject._gobject")
+PYGLIB_MODULE_START(_gobject, "_gobject")
{
PyObject *d;
diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py
index b9b587a..4fb6ee9 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_gobject/propertyhelper.py
@@ -21,17 +21,16 @@
import sys
-import gobject._gobject
-_gobject = sys.modules['gobject._gobject']
+from . import _gobject
-from gobject.constants import \
+from .constants import \
TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, \
TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, \
TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, \
TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, \
TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \
TYPE_PYOBJECT
-from gobject.constants import \
+from .constants import \
G_MINFLOAT, G_MAXFLOAT, G_MINDOUBLE, G_MAXDOUBLE, \
G_MININT, G_MAXINT, G_MAXUINT, G_MINLONG, G_MAXLONG, \
G_MAXULONG
@@ -226,10 +225,10 @@ class property(object):
elif ptype == TYPE_PYOBJECT:
if default is not None:
raise TypeError("object types does not have default values")
- elif gobject.type_is_a(ptype, TYPE_ENUM):
+ elif _gobject.type_is_a(ptype, TYPE_ENUM):
if default is None:
raise TypeError("enum properties needs a default value")
- elif not gobject.type_is_a(default, ptype):
+ elif not _gobject.type_is_a(default, ptype):
raise TypeError("enum value %s must be an instance of %r" %
(default, ptype))
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 3193890..56b9aef 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -200,7 +200,7 @@ typedef struct {
guint index;
} PyGPropsIter;
-PYGLIB_DEFINE_TYPE("gobject.GPropsIter", PyGPropsIter_Type, PyGPropsIter);
+PYGLIB_DEFINE_TYPE("gi._gobject.GPropsIter", PyGPropsIter_Type, PyGPropsIter);
static void
pyg_props_iter_dealloc(PyGPropsIter *self)
@@ -360,7 +360,7 @@ set_property_from_pspec(GObject *obj,
return TRUE;
}
-PYGLIB_DEFINE_TYPE("gobject.GProps", PyGProps_Type, PyGProps);
+PYGLIB_DEFINE_TYPE("gi._gobject.GProps", PyGProps_Type, PyGProps);
static int
PyGProps_setattro(PyGProps *self, PyObject *attr, PyObject *pvalue)
@@ -454,7 +454,7 @@ static PySequenceMethods _PyGProps_as_sequence = {
0
};
-PYGLIB_DEFINE_TYPE("gobject.GPropsDescr", PyGPropsDescr_Type, PyObject);
+PYGLIB_DEFINE_TYPE("gi._gobject.GPropsDescr", PyGPropsDescr_Type, PyObject);
static PyObject *
pyg_props_descr_descr_get(PyObject *self, PyObject *obj, PyObject *type)
@@ -1023,7 +1023,7 @@ pygobject_watch_closure(PyObject *self, GClosure *closure)
/* -------------- PyGObject behaviour ----------------- */
-PYGLIB_DEFINE_TYPE("gobject.GObject", PyGObject_Type, PyGObject);
+PYGLIB_DEFINE_TYPE("gi._gobject.GObject", PyGObject_Type, PyGObject);
static void
pygobject_dealloc(PyGObject *self)
@@ -1976,7 +1976,7 @@ static PyObject *
pygobject_copy(PyGObject *self)
{
PyErr_SetString(PyExc_TypeError,
- "gobject.GObject descendants' instances are non-copyable");
+ "GObject descendants' instances are non-copyable");
return NULL;
}
@@ -1984,7 +1984,7 @@ static PyObject *
pygobject_deepcopy(PyGObject *self, PyObject *args)
{
PyErr_SetString(PyExc_TypeError,
- "gobject.GObject descendants' instances are non-copyable");
+ "GObject descendants' instances are non-copyable");
return NULL;
}
@@ -2173,7 +2173,7 @@ typedef struct {
gboolean have_floating_ref;
} PyGObjectWeakRef;
-PYGLIB_DEFINE_TYPE("gobject.GObjectWeakRef", PyGObjectWeakRef_Type, PyGObjectWeakRef);
+PYGLIB_DEFINE_TYPE("gi._gobject.GObjectWeakRef", PyGObjectWeakRef_Type, PyGObjectWeakRef);
static int
pygobject_weak_ref_traverse(PyGObjectWeakRef *self, visitproc visit, void *arg)
@@ -2373,7 +2373,7 @@ pygobject_object_register_types(PyObject *d)
descr = PyObject_New(PyObject, &PyGPropsDescr_Type);
PyDict_SetItemString(PyGObject_Type.tp_dict, "props", descr);
PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__",
- o=PYGLIB_PyUnicode_FromString("gobject._gobject"));
+ o=PYGLIB_PyUnicode_FromString("gi._gobject._gobject"));
Py_DECREF(o);
/* GPropsIter */
diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h
index 21743ba..7952e5e 100644
--- a/gi/_gobject/pygobject.h
+++ b/gi/_gobject/pygobject.h
@@ -308,7 +308,7 @@ pygobject_init(int req_major, int req_minor, int req_micro)
{
PyObject *gobject, *cobject;
- gobject = PyImport_ImportModule("gobject");
+ gobject = PyImport_ImportModule("gi._gobject");
if (!gobject) {
if (PyErr_Occurred())
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]