[pygobject] Move gobject sub-module Python files into the main gi package



commit 2624bd2b4a465a2d234951dd5b855fe8a0d46e1c
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Oct 31 03:13:53 2013 -0700

    Move gobject sub-module Python files into the main gi package
    
    This moves the signalhelper, propertyhelper, and constants Python modules
    from gi/_gobject into gi. Keep gi/_gobject/__init__.py around because it is
    still needed to maintain the "_PyGObject_API" exposed by pygobject.h. This
    allows external modules compiled with prior versions of PyGObject to
    continue working with newer versions.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712197

 Makefile.am                                        |    5 ++-
 gi/__init__.py                                     |   19 +++++----
 gi/{_gobject/constants.py => _constants.py}        |    5 +-
 gi/_gobject/Makefile.am                            |    5 +--
 gi/_gobject/__init__.py                            |   42 +-------------------
 .../propertyhelper.py => _propertyhelper.py}       |    4 +-
 gi/{_gobject/signalhelper.py => _signalhelper.py}  |    5 +-
 gi/module.py                                       |   16 ++++----
 gi/overrides/GObject.py                            |    7 ++-
 gi/overrides/__init__.py                           |    2 +-
 gi/types.py                                        |   41 +++++++++++++++----
 pygtkcompat/pygtkcompat.py                         |    4 +-
 tests/test_gi.py                                   |    2 +-
 tests/test_gobject.py                              |    4 +-
 tests/test_properties.py                           |    2 +-
 tests/test_signal.py                               |    2 +-
 16 files changed, 78 insertions(+), 87 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index ffcdc6a..1c74126 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -58,7 +58,10 @@ nobase_pyexec_PYTHON = \
        gi/module.py \
        gi/importer.py \
        gi/pygtkcompat.py \
-       gi/docstring.py
+       gi/docstring.py \
+       gi/_constants.py \
+       gi/_propertyhelper.py \
+       gi/_signalhelper.py
 
 # if we build in a separate tree, we need to symlink the *.py files from the
 # source tree; Python does not accept the extensions and modules in different
diff --git a/gi/__init__.py b/gi/__init__.py
index 0645d44..7c1a279 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -24,24 +24,27 @@ from __future__ import absolute_import
 from pkgutil import extend_path
 __path__ = extend_path(__path__, __name__)
 
+import sys
+import os
+
+# we can't have pygobject 2 loaded at the same time we load the internal _gobject
+if 'gobject' in sys.modules:
+    raise ImportError('When using gi.repository you must not import static '
+                      'modules like "gobject". Please change all occurrences '
+                      'of "import gobject" to "from gi.repository import GObject".')
+
+from ._gi import _gobject
 from ._gi import _API
 from ._gi import Repository
 from ._gi import PyGIDeprecationWarning
 
-# Force loading the GObject typelib so we have available the wrappers for
-# base classes such as GInitiallyUnowned
-import gi._gobject
-gi  # pyflakes
-
 _API = _API  # pyflakes
 PyGIDeprecationWarning = PyGIDeprecationWarning
 
-import os
-
 _versions = {}
 _overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
 
-version_info = gi._gobject.pygobject_version[:]
+version_info = _gobject.pygobject_version[:]
 __version__ = "{0}.{1}.{2}".format(*version_info)
 
 
diff --git a/gi/_gobject/constants.py b/gi/_constants.py
similarity index 95%
rename from gi/_gobject/constants.py
rename to gi/_constants.py
index 5bb8665..495c6e1 100644
--- a/gi/_gobject/constants.py
+++ b/gi/_constants.py
@@ -2,7 +2,7 @@
 # pygobject - Python bindings for the GObject library
 # Copyright (C) 2006-2007 Johan Dahlin
 #
-#   gobject/constants.py: GObject type constants
+#   gi/_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
@@ -19,8 +19,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 # USA
 
-import gi._gi
-_gobject = gi._gi._gobject
+from ._gi import _gobject
 
 TYPE_INVALID = _gobject.TYPE_INVALID
 TYPE_NONE = _gobject.type_from_name('void')
diff --git a/gi/_gobject/Makefile.am b/gi/_gobject/Makefile.am
index b128acc..37068b8 100644
--- a/gi/_gobject/Makefile.am
+++ b/gi/_gobject/Makefile.am
@@ -4,10 +4,7 @@ PLATFORM_VERSION = 3.0
 pygobjectdir = $(pyexecdir)/gi/_gobject
 
 pygobject_PYTHON = \
-       __init__.py \
-       constants.py \
-       propertyhelper.py \
-       signalhelper.py
+       __init__.py
 
 # if we build in a separate tree, we need to symlink the *.py files from the
 # source tree; Python does not accept the extensions and modules in different
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 0bd5742..d559e74 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -19,44 +19,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 # USA
 
-# this can go when things are a little further along
-
-import sys
-
-# we can't have pygobject 2 loaded at the same time we load the internal _gobject
-if 'gobject' in sys.modules:
-    raise ImportError('When using gi.repository you must not import static modules like "gobject". Please 
change all occurrences of "import gobject" to "from gi.repository import GObject".')
-
+# Needed for compatibility with "pygobject.h"
 import gi._gi
-_gobject = gi._gi._gobject
-
-from . import propertyhelper
-from . import signalhelper
-
-GObject = _gobject.GObject
-GType = _gobject.GType
-_PyGObject_API = _gobject._PyGObject_API
-pygobject_version = _gobject.pygobject_version
-
-
-class GObjectMeta(type):
-    "Metaclass for automatically registering GObject classes"
-    def __init__(cls, name, bases, dict_):
-        type.__init__(cls, name, bases, dict_)
-        propertyhelper.install_properties(cls)
-        signalhelper.install_signals(cls)
-        cls._type_register(cls.__dict__)
-
-    def _type_register(cls, namespace):
-        ## don't register the class if already registered
-        if '__gtype__' in namespace:
-            return
-
-        # Do not register a new GType for the overrides, as this would sort of
-        # defeat the purpose of overrides...
-        if cls.__module__.startswith('gi.overrides.'):
-            return
-
-        _gobject.type_register(cls, namespace.get('__gtype_name__'))
-
-_gobject._install_metaclass(GObjectMeta)
+_PyGObject_API = gi._gi._gobject._PyGObject_API
diff --git a/gi/_gobject/propertyhelper.py b/gi/_propertyhelper.py
similarity index 99%
rename from gi/_gobject/propertyhelper.py
rename to gi/_propertyhelper.py
index 0ee0d37..ddc81cc 100644
--- a/gi/_gobject/propertyhelper.py
+++ b/gi/_propertyhelper.py
@@ -2,7 +2,7 @@
 # pygobject - Python bindings for the GObject library
 # Copyright (C) 2007 Johan Dahlin
 #
-#   gobject/propertyhelper.py: GObject property wrapper/helper
+#   gi/_propertyhelper.py: GObject property wrapper/helper
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,7 @@ import sys
 import gi._gi
 _gobject = gi._gi._gobject
 
-from .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, \
diff --git a/gi/_gobject/signalhelper.py b/gi/_signalhelper.py
similarity index 98%
rename from gi/_gobject/signalhelper.py
rename to gi/_signalhelper.py
index 19207cc..79de301 100644
--- a/gi/_gobject/signalhelper.py
+++ b/gi/_signalhelper.py
@@ -2,7 +2,7 @@
 # pygobject - Python bindings for the GObject library
 # Copyright (C) 2012 Simon Feltman
 #
-#   gobject/signalhelper.py: GObject signal binding decorator object
+#   gi/_signalhelper.py: GObject signal binding decorator object
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -22,8 +22,7 @@
 import sys
 import inspect
 
-import gi._gi
-_gobject = gi._gi._gobject
+from ._gi import _gobject
 
 # Callable went away in python 3.0 and came back in 3.2.
 # Use versioning to figure out when to define it, otherwise we have to deal with
diff --git a/gi/module.py b/gi/module.py
index 22ae551..0032774 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -54,15 +54,15 @@ from ._gi import \
     enum_add, \
     enum_register_new_gtype_and_add, \
     flags_add, \
-    flags_register_new_gtype_and_add
+    flags_register_new_gtype_and_add, \
+    _gobject
 from .types import \
-    GObjectMeta, \
+    GIObjectMeta, \
     StructMeta
 
-import gi._gi
-GInterface = gi._gi._gobject.GInterface
+GInterface = _gobject.GInterface
 
-from ._gobject.constants import \
+from ._constants import \
     TYPE_NONE, \
     TYPE_BOXED, \
     TYPE_POINTER, \
@@ -183,13 +183,13 @@ class IntrospectionModule(object):
                 interfaces = tuple(interface for interface in get_interfaces_for_object(info)
                                    if not issubclass(parent, interface))
                 bases = (parent,) + interfaces
-                metaclass = GObjectMeta
+                metaclass = GIObjectMeta
             elif isinstance(info, CallbackInfo):
                 bases = (CCallback,)
-                metaclass = GObjectMeta
+                metaclass = GIObjectMeta
             elif isinstance(info, InterfaceInfo):
                 bases = (GInterface,)
-                metaclass = GObjectMeta
+                metaclass = GIObjectMeta
             elif isinstance(info, (StructInfo, UnionInfo)):
                 if g_type.is_a(TYPE_BOXED):
                     bases = (Boxed,)
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 147a452..fe172ca 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -31,9 +31,10 @@ from gi.overrides import override
 from gi.repository import GLib
 from gi import PyGIDeprecationWarning
 
-from gi._gobject import _gobject
-from gi._gobject import propertyhelper
-from gi._gobject import signalhelper
+from gi import _propertyhelper as propertyhelper
+from gi import _signalhelper as signalhelper
+
+_gobject = gi._gi._gobject
 
 GObjectModule = gi.module.get_introspection_module('GObject')
 
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 9e7a0f1..2cd1345 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -3,7 +3,7 @@ import warnings
 
 from gi import PyGIDeprecationWarning
 from gi._gi import CallableInfo
-from gi._gobject.constants import \
+from gi._constants import \
     TYPE_NONE, \
     TYPE_INVALID
 
diff --git a/gi/types.py b/gi/types.py
index c5b4bd5..0ccfe27 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -25,8 +25,7 @@ from __future__ import absolute_import
 import sys
 import warnings
 
-from . import _gobject
-from ._gobject.constants import TYPE_INVALID
+from ._constants import TYPE_INVALID
 from .docstring import generate_doc_string
 
 from ._gi import \
@@ -35,13 +34,16 @@ from ._gi import \
     StructInfo, \
     VFuncInfo, \
     register_interface_info, \
-    hook_up_vfunc_implementation
+    hook_up_vfunc_implementation, \
+    _gobject
 
-import gi._gi
-GInterface = gi._gi._gobject.GInterface
+GInterface = _gobject.GInterface
 
 StructInfo  # pyflakes
 
+from . import _propertyhelper as propertyhelper
+from . import _signalhelper as signalhelper
+
 if (3, 0) <= sys.version_info < (3, 3):
     # callable not available for python 3.0 thru 3.2
     def callable(obj):
@@ -171,16 +173,39 @@ def find_vfunc_conflict_in_bases(vfunc, bases):
     return None
 
 
-class GObjectMeta(_gobject.GObjectMeta, MetaClassHelper):
+class GObjectMeta(type):
+    "Metaclass for automatically registering GObject classes"
+    def __init__(cls, name, bases, dict_):
+        type.__init__(cls, name, bases, dict_)
+        propertyhelper.install_properties(cls)
+        signalhelper.install_signals(cls)
+        cls._type_register(cls.__dict__)
+
+    def _type_register(cls, namespace):
+        ## don't register the class if already registered
+        if '__gtype__' in namespace:
+            return
+
+        # Do not register a new GType for the overrides, as this would sort of
+        # defeat the purpose of overrides...
+        if cls.__module__.startswith('gi.overrides.'):
+            return
+
+        _gobject.type_register(cls, namespace.get('__gtype_name__'))
+
+_gobject._install_metaclass(GObjectMeta)
+
+
+class GIObjectMeta(GObjectMeta, MetaClassHelper):
 
     def __init__(cls, name, bases, dict_):
-        super(GObjectMeta, cls).__init__(name, bases, dict_)
+        super(GIObjectMeta, cls).__init__(name, bases, dict_)
         is_gi_defined = False
         if cls.__module__ == 'gi.repository.' + cls.__info__.get_namespace():
             is_gi_defined = True
 
         is_python_defined = False
-        if not is_gi_defined and cls.__module__ != GObjectMeta.__module__:
+        if not is_gi_defined and cls.__module__ != GIObjectMeta.__module__:
             is_python_defined = True
 
         if is_python_defined:
diff --git a/pygtkcompat/pygtkcompat.py b/pygtkcompat/pygtkcompat.py
index 67571ac..d5b7b94 100644
--- a/pygtkcompat/pygtkcompat.py
+++ b/pygtkcompat/pygtkcompat.py
@@ -90,8 +90,8 @@ def enable():
     # gobject
     from gi.repository import GObject
     sys.modules['gobject'] = GObject
-    from gi._gobject import propertyhelper
-    sys.modules['gobject.propertyhelper'] = propertyhelper
+    from gi import _propertyhelper
+    sys.modules['gobject.propertyhelper'] = _propertyhelper
 
     # gio
     from gi.repository import Gio
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 2411a49..3af086d 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2406,7 +2406,7 @@ class TestMRO(unittest.TestCase):
             pass
 
         expected = (E, D, B, C, A, GIMarshallingTests.Object,
-                    GObject.Object, GObject.Object.__base__, gi._gobject.GObject,
+                    GObject.Object, GObject.Object.__base__, gi._gi._gobject.GObject,
                     object)
         self.assertEqual(expected, E.__mro__)
 
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index d49011f..a88a4bc 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -8,7 +8,9 @@ import warnings
 from gi.repository import GObject, GLib
 from gi import PyGIDeprecationWarning
 from gi.module import get_introspection_module
-from gi._gobject import _gobject
+
+import gi
+_gobject = gi._gi._gobject
 
 import testhelper
 
diff --git a/tests/test_properties.py b/tests/test_properties.py
index ef6b867..d7ceb89 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -23,7 +23,7 @@ from gi.repository import Gio
 from gi.repository import GLib
 from gi.repository import Regress
 from gi.repository import GIMarshallingTests
-from gi._gobject import propertyhelper
+from gi import _propertyhelper as propertyhelper
 
 if sys.version_info < (3, 0):
     TEST_UTF8 = "\xe2\x99\xa5"
diff --git a/tests/test_signal.py b/tests/test_signal.py
index e90264a..429afc9 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -5,7 +5,7 @@ import unittest
 import sys
 
 from gi.repository import GObject, GLib
-from gi._gobject import signalhelper
+from gi import _signalhelper as signalhelper
 import testhelper
 from compathelper import _long
 


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