[Goodies-dev] RSS plugin: Properly detect the xfce4 Python module

Adriano Winter Bess awbess at gmail.com
Thu Aug 3 04:05:40 CEST 2006

On Wed, Aug 02, 2006 at 10:13:06PM +0200, Jannis Pohlmann wrote:
> Hey Adriano,


> [...]
> First of all, it's a known "problem" (some call it a feature) that on
> some systems, you have to call "import pygtk.require('2.0')" before you
> can run "import gtk" or import any gtk submodules. This has some
> drawbacks, of course. Some authors forget to do this and it makes
> detecting Python modules slightly more complicated. 

Indeed I already knew about this. The RSS plugin code properly loads pygtk and
asserts pygtk.require("2.0") before importing gtk wherever theses modules are

> The latter is the case in your RSS plugin, which tries to detect the
> xfce4 Python module via AM_CHECK_PYMOD. AM_CHECK_PYMOD mainly
> constructs a simple Python script which tries to import the passed
> module and returns 0 on success or 1 when an ImportError occured.

I've checked the inner workings of AM_CHECK_PYMOD before adding acinclude.m4 to
the plugin sources, but I didn't realize about this issue by that time. Thanks a
lot for calling my attention into it.

> So if you call AM_CHECK_PYMOD(xfce4, ...), the generated script will
> roughly look like this:
>   try:
>     import xfce4
>     sys.exit(0)
>   except ImportError:
>     sys.exit(1)
> As xfce4 needs the gtk module (and its submodules), the script needs to
> look like this to work on all systems:
>   try:
>     try:
>       import pygtk
>       pygtk.require("2.0")
>     except: # Some systems (like Windows) don't need the pygtk stuff
>       pass
>     import gtk
>     import xfce4
>     sys.exit(0)
>   except ImportError:
>     sys.exit(1)

Here's where I'm curious: in which systems does the python interpreter fail to
import xfce4 if pygtk and gtk are not imported before it? I run GNU/Linux
(Debian unstable) on a x86 machine and it simply doesn't complain:

$ python
Python 2.3.5 (#2, Jun 13 2006, 23:12:55) 
[GCC 4.1.2 20060613 (prerelease) (Debian 4.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xfce4

If you didn't tell me about this, I would probably never knew about it.

> To achieve this, you have (at least) two possibilities: You can either
> just execute this script inside of configure.ac(.in) and check its exit
> code or you can tweak acinclude.m4 to add the needed stuff for you.
> Here are two (slightly different) approaches to change AM_CHECK_PYMOD
> to support the pygtk stuff:
>   http://numexp.cvs.sourceforge.net/numexp/gnumexp/acinclude.m4?revision=1.4&view=markup
> and
>   http://svn.sourceforge.net/viewvc/ecell/ecell3/trunk/modeleditor/acinclude.m4?revision=2480&view=markup&pathrev=2558

I've chosen the first one. Since it is indifferent on my system, I'd like you to
check it on your system to see if it works fine.

> I hope this helps and compensates my chaotic monolog I talked in a few
> minutes ago.

Hehe, thanks a lot for your help :)

PS: [OT] How does one get voice on #xfce-dev?

Adriano Winter Bess
ICQ: 21569917
MSN: awbess-at-gmail.com
IRC: nyquide

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.xfce.org/pipermail/goodies-dev/attachments/20060802/18094684/attachment.pgp>

More information about the Goodies-dev mailing list