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

Jannis Pohlmann jannis at xfce.org
Thu Aug 3 12:08:37 CEST 2006


Ho,

On Wed, 2 Aug 2006 23:05:40 -0300, Adriano Winter Bess wrote:

> On Wed, Aug 02, 2006 at 10:13:06PM +0200, Jannis Pohlmann wrote:
> > Hey Adriano,
> 
> Hey
> 
> > [...]
> > 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 necessary.

Yes, I noticed this. Good boy, hehe.

> > 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.

AFAIK, the pygtk lines are intended to select the GTK+ version you want
to use. On some systems, you may have PyGTK for GTK+ 1.x *and* 2.x
installed and with pygtk.require('1.0') you can then select the 1.0
version. I wonder if anyone ever used it for something different
than to get PyGTK 2.x working.

> > 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.

Seems to work fine.

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

Try to query auke, sofar, p0llux or kelnos - they all should be able to
grant you auto-voice.

Regards,
Jannis



More information about the Goodies-dev mailing list