Merge lp:~sinzui/bzr-dbus/gtk3-support into lp:bzr-dbus

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 52
Proposed branch: lp:~sinzui/bzr-dbus/gtk3-support
Merge into: lp:bzr-dbus
Diff against target: 305 lines (+68/-34)
3 files modified
activity.py (+8/-6)
setup.py (+32/-4)
tests/test_activity.py (+28/-24)
To merge this branch: bzr merge lp:~sinzui/bzr-dbus/gtk3-support
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) Approve
Review via email: mp+90952@code.launchpad.net

Description of the change

Update bzr-dbus to work with gtk3.

I see this error when I run gci from the command line or from
gedit-developer-plugins:

/usr/lib/python2.7/dist-packages/gobject/constants.py:24:
    Warning: g_boxed_type_register_static:
        assertion `g_type_from_name (name) == 0' failed
  import gobject._gobject

This is harmless from the command line, but when the code is embedded,
the whole app becomes unstable and is likely to crash the next time any
call to bzr-gtk is made.

I traced the issue to an import of gobject in bzr-dbus:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/bzrlib/commands.py", line 919, in exception_to_return_code
...
  File "/usr/lib/python2.7/dist-packages/bzrlib/plugins/dbus/activity.py", line 29, in <module>
    import gobject
  File "/usr/lib/python2.7/dist-packages/gobject/__init__.py", line 47, in <module>
    from gobject.constants import *

--------------------------------------------------------------------

RULES

    * Try to import from gi.repository and fallback for gobject.
    * Update the existing calls to gobject to use GObject, the
      three member calls are compatible with GObject.
    * ADDENDUM
      * Added a 'check' command to setup.py to run the tests
      * tests.test_activity.TestActivity.test_server fails in
        trunk and my branch. I do not know what I can do to fix
        the test or the code to make it pass. The server fails to
        start.`

QA

    * Using bzr-gtk trunk run `bzr gci` in a tree with changes.
    * Verify a warnging is not displayed on the commmand line
      Warning: g_boxed_type_register_static: ...

TEST

    ./setup.py check

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks again Curtis!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'activity.py'
2--- activity.py 2008-02-13 00:29:52 +0000
3+++ activity.py 2012-01-31 21:03:29 +0000
4@@ -26,7 +26,10 @@
5 import time
6
7 import dbus.service
8-import gobject
9+try:
10+ from gi.repository import GObject
11+except ImportError:
12+ import gobject as GObject
13
14 from bzrlib.plugins.dbus import mapper
15 from bzrlib.revision import NULL_REVISION
16@@ -116,8 +119,7 @@
17 # make a non-blocking call, which we can then ignore as we dont
18 # care about responses: Apparently there is some dbus foo to help
19 # make this not need the stub function
20- import gobject
21- mainloop = gobject.MainLoop()
22+ mainloop = GObject.MainLoop()
23 def handle_reply():
24 # quit our loop.
25 mainloop.quit()
26@@ -160,7 +162,7 @@
27 is ready to handle requests.
28 """
29 broadcaster = Broadcast(self.bus)
30- mainloop = gobject.MainLoop()
31+ mainloop = GObject.MainLoop()
32 if when_ready:
33 when_ready()
34 mainloop.run()
35@@ -237,7 +239,7 @@
36 """
37 self.bus = _get_bus(bus)
38 if mainloop is None:
39- self.mainloop = gobject.MainLoop()
40+ self.mainloop = GObject.MainLoop()
41 else:
42 self.mainloop = mainloop
43 if activity is None:
44@@ -326,7 +328,7 @@
45 self.port = self.sock.getsockname()[1]
46 else:
47 self.port = _port
48- gobject.io_add_watch(self.sock, gobject.IO_IN, self.handle_network_packet)
49+ GObject.io_add_watch(self.sock, GObject.IO_IN, self.handle_network_packet)
50 # listen for dbus events
51 self.activity.listen_for_revisions(self.catch_dbus_revision)
52
53
54=== modified file 'setup.py'
55--- setup.py 2010-03-01 05:04:36 +0000
56+++ setup.py 2012-01-31 21:03:29 +0000
57@@ -1,16 +1,44 @@
58-#!/usr/bin/env python2.4
59-from distutils.core import setup
60+#!/usr/bin/env python
61+
62+from distutils.core import (
63+ Command,
64+ setup,
65+ )
66+import subprocess
67+import sys
68+
69+
70+class Check(Command):
71+ description = "run all tests or a single test module"
72+ user_options = [
73+ ('module=', 'm', 'The test module to run'),
74+ ]
75+
76+ def initialize_options(self):
77+ self.module = 'discover'
78+
79+ def finalize_options(self):
80+ self.module = [self.module]
81+
82+ def run(self):
83+ command = [sys.executable, '-m', 'testtools.run']
84+ command += self.module
85+ raise SystemExit(subprocess.call(command))
86+
87+
88 if __name__ == '__main__':
89 setup(name="bzr-dbus",
90 version="0.1~",
91 description="dbus core plugin for bzr.",
92 author="Robert Collins",
93 author_email="robert.collins@canonical.com",
94- license = "GPLV2",
95+ license="GPLV2",
96 url="https://launchpad.net/bzr-dbus",
97 data_files=[('share/dbus-1/services',
98 ['org.bazaarvcs.plugins.dbus.Broadcast.service'])],
99 packages=['bzrlib.plugins.dbus',
100 'bzrlib.plugins.dbus.tests',
101 ],
102- package_dir={'bzrlib.plugins.dbus': '.'})
103+ package_dir={'bzrlib.plugins.dbus': '.'},
104+ cmdclass={'check': Check},
105+ )
106
107=== modified file 'tests/test_activity.py'
108--- tests/test_activity.py 2011-07-19 12:17:37 +0000
109+++ tests/test_activity.py 2012-01-31 21:03:29 +0000
110@@ -30,7 +30,11 @@
111 import dbus
112 import dbus.bus
113 import dbus.mainloop.glib
114-import gobject
115+try:
116+ from gi.repository import GObject
117+except ImportError:
118+ import gobject as GObject
119+
120
121 import bzrlib.plugins
122 from bzrlib.smart.protocol import _encode_tuple, _decode_tuple
123@@ -271,7 +275,7 @@
124 dbus_iface.announce_revision('revision2', 'url2',
125 reply_handler=handle_reply,
126 error_handler=handle_error)
127- mainloop = gobject.MainLoop()
128+ mainloop = GObject.MainLoop()
129 mainloop.run()
130 if errors:
131 raise errors[0]
132@@ -345,7 +349,7 @@
133 dbus_iface.announce_revision_urls('revision2', ['url2'],
134 reply_handler=handle_reply,
135 error_handler=handle_error)
136- mainloop = gobject.MainLoop()
137+ mainloop = GObject.MainLoop()
138 mainloop.run()
139 if errors:
140 raise errors[0]
141@@ -404,7 +408,7 @@
142 dbus_iface.add_url_map('foo/', 'baz/',
143 reply_handler=handle_reply,
144 error_handler=handle_error)
145- mainloop = gobject.MainLoop()
146+ mainloop = GObject.MainLoop()
147 mainloop.run()
148 if errors:
149 raise errors[0]
150@@ -446,7 +450,7 @@
151 dbus_iface.remove_url_map('foo/', 'baz/',
152 reply_handler=handle_reply,
153 error_handler=handle_error)
154- mainloop = gobject.MainLoop()
155+ mainloop = GObject.MainLoop()
156 mainloop.run()
157 if errors:
158 raise errors[0]
159@@ -468,7 +472,7 @@
160
161 def test_run_binds(self):
162 self.error = None
163- mainloop = gobject.MainLoop()
164+ mainloop = GObject.MainLoop()
165 # we want run to: open a listening socket on localhost:4155 udp, the
166 # bzr protocol port number.
167 # to test this we want to check the port is in use during the loop.
168@@ -481,8 +485,8 @@
169 except Exception, e:
170 self.error = e
171 finally:
172- gobject.timeout_add(0, mainloop.quit)
173- gobject.timeout_add(0, check_socket_bound)
174+ GObject.timeout_add(0, mainloop.quit)
175+ GObject.timeout_add(0, check_socket_bound)
176 gateway = activity.LanGateway(self.bus, mainloop)
177 # disable talking to dbus by making it a noop
178 gateway.activity.listen_for_revisions = lambda x:x
179@@ -491,7 +495,7 @@
180 raise self.error
181
182 def test_network_packets_trigger_handle_network_packet(self):
183- mainloop = gobject.MainLoop()
184+ mainloop = GObject.MainLoop()
185 # we want network packets to call handle_network_packet,
186 # so we override that to shutdown the mainloop and log the call.
187 def send_packet():
188@@ -499,13 +503,13 @@
189 sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
190 sock.sendto('data_to_handle', ('127.0.0.1', gateway.port))
191 sock.close()
192- gobject.timeout_add(0, send_packet)
193- gobject.timeout_add(1000, mainloop.quit)
194+ GObject.timeout_add(0, send_packet)
195+ GObject.timeout_add(1000, mainloop.quit)
196 gateway = activity.LanGateway(self.bus, mainloop)
197 calls = []
198 def handle_data(data):
199 calls.append(('handle', data))
200- gobject.timeout_add(0, mainloop.quit)
201+ GObject.timeout_add(0, mainloop.quit)
202 gateway.handle_network_data = handle_data
203 # disable talking to dbus by making it a noop
204 gateway.activity.listen_for_revisions = lambda x:x
205@@ -515,7 +519,7 @@
206 def test_broadcast_data_calls_sock(self):
207 # the method broadcast_data on a LanGateway should invoke
208 # socket.sendto(data, ('<broadcast>', 4155))
209- mainloop = gobject.MainLoop()
210+ mainloop = GObject.MainLoop()
211 gateway = activity.LanGateway(self.bus, mainloop)
212 calls = []
213 class StubSocket(object):
214@@ -527,8 +531,8 @@
215 calls)
216
217 def test_run_listens_for_revisions(self):
218- mainloop = gobject.MainLoop()
219- gobject.timeout_add(0, mainloop.quit)
220+ mainloop = GObject.MainLoop()
221+ GObject.timeout_add(0, mainloop.quit)
222 # avoid asking dbus if something is subscribed.
223 class StubActivity(object):
224 def listen_for_revisions(self, callback):
225@@ -541,7 +545,7 @@
226
227 def test_catch_dbus_revision_ignore_file_only(self):
228 """catch_dbus_revision should ignore file:/// urls."""
229- mainloop = gobject.MainLoop()
230+ mainloop = GObject.MainLoop()
231 gateway = activity.LanGateway(self.bus, mainloop)
232 # instrument the transmission apis used by the LanGateway.
233 calls = []
234@@ -553,7 +557,7 @@
235
236 def test_catch_dbus_revision_strip_file(self):
237 """catch_dbus_revision should strip file:/// urls if others exist."""
238- mainloop = gobject.MainLoop()
239+ mainloop = GObject.MainLoop()
240 gateway = activity.LanGateway(self.bus, mainloop)
241 # instrument the transmission apis used by the LanGateway.
242 calls = []
243@@ -568,7 +572,7 @@
244
245 def test_catch_dbus_revision_encodes_smart_tuple(self):
246 """catch_dbus_revision should encode as _encode_tuple does."""
247- mainloop = gobject.MainLoop()
248+ mainloop = GObject.MainLoop()
249 gateway = activity.LanGateway(self.bus, mainloop)
250 # instrument the transmission apis used by the LanGateway.
251 calls = []
252@@ -583,7 +587,7 @@
253
254 def test_catch_dbus_revision_ignores_revision_url_all_from_network(self):
255 """There is a time limited window within which revisions are remembered."""
256- mainloop = gobject.MainLoop()
257+ mainloop = GObject.MainLoop()
258 gateway = activity.LanGateway(self.bus, mainloop)
259 # instrument the transmission apis used by the LanGateway.
260 calls = []
261@@ -597,7 +601,7 @@
262
263 def test_catch_dbus_revision_preserves_non_network_urls(self):
264 """When some urls for a revision were not from the network the rest are sent."""
265- mainloop = gobject.MainLoop()
266+ mainloop = GObject.MainLoop()
267 gateway = activity.LanGateway(self.bus, mainloop)
268 # instrument the transmission apis used by the LanGateway.
269 calls = []
270@@ -614,7 +618,7 @@
271
272 def test_catch_dbus_revision_notes_revision(self):
273 """Revisions coming in from dbus are noted too, to prevent reemission."""
274- mainloop = gobject.MainLoop()
275+ mainloop = GObject.MainLoop()
276 gateway = activity.LanGateway(self.bus, mainloop)
277 # instrument the transmission apis used by the LanGateway.
278 calls = []
279@@ -637,7 +641,7 @@
280 self.assertTrue(calls[0][1] <= finish)
281
282 def test_note_network_revision(self):
283- mainloop = gobject.MainLoop()
284+ mainloop = GObject.MainLoop()
285 gateway = activity.LanGateway(self.bus, mainloop)
286 now = time.time()
287 # noting the we've seen 'rev' now should cache it at minute granularity.
288@@ -646,7 +650,7 @@
289 gateway.seen_revisions)
290
291 def test_note_network_revision_trims_cache(self):
292- mainloop = gobject.MainLoop()
293+ mainloop = GObject.MainLoop()
294 gateway = activity.LanGateway(self.bus, mainloop)
295 now = time.time()
296 # noting a time when there are stale entries should remove them.
297@@ -662,7 +666,7 @@
298 def test_handle_network_data(self):
299 """data from the network is deserialised, passed to note_revision and dbus."""
300
301- mainloop = gobject.MainLoop()
302+ mainloop = GObject.MainLoop()
303 # instrument the transmission apis used by the LanGateway.
304 calls = []
305 start = time.time()

Subscribers

People subscribed via source and target branches

to all changes: