[PATCH] Fix: don't attempt on-demand import with gobject._gobject as it will fail

Alan Franzoni mailing at franzoni.eu
Wed Oct 27 10:29:00 CDT 2010


Hello,
the wiki doesn't say it *that* clearly were should patches be sent, So
i'm re-sending this to the mercurial-devel list as well. I hope I'm
not wrong.


Hello,
this is a very simple patch. Basically, it seems that
gobject/gobject.constants relies on some import magic to properly
work; using demandimport will break it:

I've got a test case but I think it makes little sense to add it into
Mercurial's own unit tests:


#!/usr/bin/python
from mercurial import demandimport
demandimport.enable()
from gobject._gobject import *
#from gnomekeyring import find_network_password_sync

Output:
Traceback (most recent call last):
 File "../example_gobject_crash.py", line 4, in <module>
   from gobject._gobject import *
 File "/home/alan/temp/hg-bleedingedge/mercurial/demandimport.py",
line 91, in _demandimport
   return _origimport(name, globals, locals, fromlist)
 File "/usr/lib/pymodules/python2.6/gtk-2.0/gobject/__init__.py",
line 47, in <module>
   from gobject.constants import *
 File "/home/alan/temp/hg-bleedingedge/mercurial/demandimport.py",
line 91, in _demandimport
   return _origimport(name, globals, locals, fromlist)
 File "/usr/lib/pymodules/python2.6/gtk-2.0/gobject/constants.py",
line 25, in <module>
   _gobject = sys.modules['gobject._gobject']
KeyError: 'gobject._gobject'


You can check that removing the demandimport.enable() call the problem vanishes.

Of course I was working with gnomekeyring when I hit that, I've
narrowed the case down to gobject for whoever hasn't got gnome but has
got gobject/gtk installed. Feel free to uncomment the proper lines
from the testcase to verify what's happening.

Verified on Ubuntu 10.04 64 bit, python 2.6.5, mercurial 1.6.4 from PPA.

Patch against bleedingedge (can be applied easly to stable as well
since it's really basic, just adds the module to the ignore list):

# HG changeset patch
# User Alan Franzoni <username at franzoni.eu>
# Date 1288190015 -7200
# Node ID 503d1f07a0f1800b263f8390d20f2e22fe8467d7
# Parent  6bf8d48bec8e1ab2e0462ce14a914d06e64f7117
Fix: don't attempt on-demand import with gobject._gobject as it will fail.

diff -r 6bf8d48bec8e -r 503d1f07a0f1 mercurial/demandimport.py
--- a/mercurial/demandimport.py Wed Oct 20 23:48:33 2010 +0200
+++ b/mercurial/demandimport.py Wed Oct 27 16:33:35 2010 +0200
@@ -148,6 +148,7 @@
    # raise ImportError if x not defined
    '__main__',
    '_ssl', # conditional imports in the stdlib, issue1964
+    'gobject._gobject',
    ]

 def enable():



--
Alan Franzoni
--
contact me at public@[mysurname].eu



-- 
Alan Franzoni
--
contact me at public@[mysurname].eu


More information about the Mercurial-devel mailing list