After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 310563 - pygtk.require() enhancement
pygtk.require() enhancement
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
2.8.0
Other Linux
: Normal enhancement
: ---
Assigned To: Gustavo Carneiro
Python bindings maintainers
: 318300 320221 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2005-07-16 03:28 UTC by Steve Chaplin
Modified: 2007-07-05 11:49 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
suggested patch (1.14 KB, patch)
2005-07-16 03:30 UTC, Steve Chaplin
none Details | Review
patch (7.27 KB, patch)
2006-04-01 19:12 UTC, Yevgen Muntyan
none Details | Review

Description Steve Chaplin 2005-07-16 03:28:16 UTC
>>> import gtk
>>> gtk.pygtk_version
(2, 6, 0)
>>> import pygtk
>>> pygtk.require('2.0')
Traceback (most recent call last):
  • File "<stdin>", line 1 in ?
  • File "/usr/lib/python2.4/site-packages/pygtk.py", line 69 in require
    assert not sys.modules.has_key('gtk'), \
AssertionError: pygtk.require() must be called before importing gtk


If the required version of gtk has already been successfully imported 
before calling pygtk.require() (perhaps in a different 3rd party module), 
then sys.path is already OK and does not need 'fixing'.
In this case pygtk.require() raises an exception and terminates a program
which would otherwise run successfully. It could be a bit more forgiving and 
allow the program to continue rather than raising the exception.
Comment 1 Steve Chaplin 2005-07-16 03:30:15 UTC
Created attachment 49277 [details] [review]
suggested patch
Comment 2 Gustavo Carneiro 2005-07-16 10:58:40 UTC
pygtk.require sucks, I think we all agree :|

Your patch looks fine to me (not sure about jdahlin), although I had an idea
once to deprecate pygtk.require and instead create a pygtk2 module more or less
equivalent to pygtk.require("2.0"); this module would also be generated when
building pygtk so as to contain the hardcoded path to the gtk-2.0 dir created by
pygtk, instead o searching sys.path for it.
Comment 3 Johan (not receiving bugmail) Dahlin 2005-07-18 19:40:06 UTC
I guess this can go in, don't think we want to add yet another module, .pth
files  seems to work fine in most cases.
Comment 4 Yevgen Muntyan 2006-04-01 19:12:54 UTC
Created attachment 62559 [details] [review]
patch

A patch by Gustavo, he's too lazy to attach it himself.
Comment 5 Gustavo Carneiro 2006-04-01 19:30:52 UTC
The main point of my patch is that it makes pygtk.require("2.0") not only more robust, since it doesn't search sys.path for gtk-2.0 dirs, but also extremely fast, for the same reason.  The new code looks like this:

def require20():
    if _pygtk_2_0_dir not in sys.path:
        sys.path.insert(0, _pygtk_2_0_dir)

def require(version):
    if version == '2.0':
        return require20()
     # otherwise use old method
     ....

and _pygtk_2_0_dir is defined at installation time.
Comment 6 Gustavo Carneiro 2006-04-01 20:01:27 UTC
OK, committed the patch with a couple more minor fixes to pygobject HEAD.
Comment 7 Gustavo Carneiro 2006-04-02 17:13:03 UTC
*** Bug 320221 has been marked as a duplicate of this bug. ***
Comment 8 Gustavo Carneiro 2006-04-02 21:44:34 UTC
*** Bug 318300 has been marked as a duplicate of this bug. ***
Comment 9 Loïc Minier 2007-07-05 11:49:47 UTC
(Reassigning to pygobject.)