GNOME Bugzilla – Bug 330013
deskbar-applet will not compile without connection to the display
Last modified: 2006-02-13 16:37:36 UTC
deskbar-applet checks for the existence of gnomeapplet by running python and trying to import it. As a side effect, this imports gtk. Apparently, gtk tries to open a connection to the display when imported and fails if it is unsuccessful. This prevents me from building remotely; I'm guessing my setup is similar to Luis' past tinderbox setups (which we would like to start up again), in which case this would cause problems there too. Would it be possible to just do a pkg-config check for gnome-python-desktop, similar to how the pygtk dependency is currently handled?
I think this is more ignorance of my part :) The problem is that the gnomeapplet module is either in gnome-python-desktop in post 2.13.? releases, and is in gnome-python-extras before that. The second problem is that the pkg-config exists even if only one module from g-p-e or g-p-d is built, meaning that there could be situations where there is the pkgconfig file, but not the gnomeapplet module. Do you have suggestions on how to improve that ? And if it involves autoconf, a patch is apreciated, cause i don't master at all conditional stuff etc, i steal them from others :)
Unfortunately, I probably know less than you about autoconf, and definitely know less than you about the relevant python stuff. I'll cc Gustavo and James to see if they have any good ideas.
Raphael: if no display is set, "import gtk" will fail with a RuntimeError. If the gtk module does not exist, then it will fail with ImportError. This should be quite easy to test for in your configure script. Something like: AC_MSG_CHECKING([for gnomeapplet module]) if AC_RUN_LOG([python -c ' try: import gnomeapplet except ImportError: raise except: pass ']); then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([gnomeapplet module required to build deskbar]) fi You could also try using the AM_CHECK_PYMOD() macro in pygtk/m4/python.m4
I'm already using AM_CHECK_PYMOD: AM_CHECK_PYMOD(gnomeapplet,,AC_MSG_RESULT([yes]),AC_MSG_ERROR([gnomeapplet not found])) which does exactly what you write above (excepts it sys.exit(0)). Elijah how exactly is it failing ? Maybe a PYTHONPATH problem ? i had those using jhbuild because jhbuild doesn't set pythonpath correctly, at least that's what i think..
You are correct that jhbuild doesn't set PYTHONPATH by default, but I manually set that in my ~/.jhbuildrc. Also, that can't be the problem because if I ssh in with X forwarding, then the build completes just fine. I ran some stuff inside python, and it looks to me like the trick behind AM_CHECK_PYMOD doesn't work: >>> try: ... import gtk ... except ImportError: ... print "import error" ... except: ... print "no import error" ... no import error >>> try: ... import gnomeapplet ... except ImportError: ... print "import error" ... except: ... print "no import error" ... import error If I run the above commands from a shell where I have ssh'ed in with X forwarding, nothing is printed. Also, going back to the shell without X forwarding, I get the following (though you probably already knew this): >>> import gnomeapplet Traceback (most recent call last):
+ Trace 66004
ImportError: could not import gtk >>> import gtk; Traceback (most recent call last):
from _gtk import * RuntimeError: could not open display
A trick that does work is trying to import gnomeapplet twice -- the second time succeeds without any problem for such a setup, whereas the second time will still fail if gnomeapplet really doesn't exist (or equivalently, if PYTHONPATH isn't setup correctly). Maybe AM_CHECK_PYMOD should be altered to do this?
Created attachment 58891 [details] [review] Patch to python.m4 that fixes this bug The exact same patch also applies to gnome-python/pygtk/m4/python.m4 (not too surprisingly -- the files appear to be copies of one another), so it may be useful there too.
Doing a double import as a check is a bad idea. It is relying on the fact that the import is not atomic, so you see the left overs of the failed import the second time. This is not guaranteed by the language spec, and may get fixed in a future version. A better check might be to check the message of the import error to make sure it is talking about the module in question. Something like: try: import gnomeapplets except ImportError, e: if str(e).find('gnomeapplets') >= 0: raise except: pass This makes sure that the ImportError refelates to the module in question rather than some other module.
I used the following snippet as per James and Elijah suggestion. Comitted in HEAD, please re-open if it still doesn't work.. AM_PATH_PYTHON AC_MSG_CHECKING([for gnomeapplet module]) if AC_RUN_LOG([$PYTHON -c ' try: import gnomeapplet except ImportError, e: if str(e).find('gnomeapplets') >= 0: raise except: pass ']); then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) AC_MSG_ERROR([gnomeapplet module required to build deskbar]) fi
Sorry to be such a pain, but this fails too -- in a strange way. From config.log: configure:23287: checking for gnomeapplet module configure:23297: $PYTHON -c ' try: import gnomeapplet except ImportError, e: if str(e).find('gnomeapplets') >= 0: raise except: pass ' Traceback (most recent call last):
+ Trace 66022
configure:23308: $? = 1 configure:23313: result: no configure:23315: error: gnomeapplet module required to build deskbar Why would the name gnomeapplets have to be defined?
You have ... $PYTHON -c ' ... if str(e).find('gnomeapplets') >= 0: '... i.e. you use the same quote (') for shell escaping and for python string literal. Try changing one of the '' pairs to "".
Thanks gustavo, and beides it must check for 'gnomeapplet' and not 'gnomeapplet*s*'. I comitted the changes, elijah is it working now ?
Indeed, it works now. Thanks everyone!
*** Bug 330998 has been marked as a duplicate of this bug. ***