GNOME Bugzilla – Bug 651998
gdbus-codegen: Use relative Python imports
Last modified: 2011-06-09 15:53:57 UTC
This avoids blowing up if someone adds a module named say "parser" to Python or a third party module. Also, it helps fix srcdir != builddir issues.
Created attachment 189332 [details] [review] gdbus-codegen: Use relative Python imports
I ended up fixing this in a different way: commit 62072b2a043ab872e45c89b6f7f9073cd7035bf5 Author: Colin Walters <walters@verbum.org> Date: Mon Jun 6 17:14:45 2011 -0400 gdbus codegen: Ensure PYTHONPATH is set correctly for srcdir != builddir We need to pick up the Python files from the source directory, so set PYTHONPATH.
This doesn't work (see below) because the installed version looks like this $ tail -3 /usr/lib64/gdbus-codegen/parser.py def parse_dbus_xml(xml_data, dbus_strip_prefix, dbus_namespace): parser = DBusXMLParser(xml_data, dbus_strip_prefix, dbus_namespace) return parser.parsed_interfaces PYTHONPATH=../../gio/gdbus-codegen${PYTHONPATH:+:$PYTHONPATH} ../../gio/gdbus-codegen/gdbus-codegen \ --interface-prefix org.project. \ --generate-c-code gdbus-test-codegen-generated \ --c-generate-object-manager \ --c-namespace Foo \ --generate-docbook gdbus-test-codegen-generated-doc \ --annotate "org.project.Bar" Key1 Value1 \ --annotate "org.project.Bar" org.gtk.GDBus.Internal Value2 \ --annotate "org.project.Bar.HelloWorld()" Key3 Value3 \ --annotate "org.project.Bar::TestSignal" Key4 Value4 \ --annotate "org.project.Bar:ay" Key5 Value5 \ --annotate "org.project.Bar.TestPrimitiveTypes()[val_int32]" Key6 Value6 \ --annotate "org.project.Bar.TestPrimitiveTypes()[ret_uint32]" Key7 Value7 \ --annotate "org.project.Bar::TestSignal[array_of_strings]" Key8 Value8 \ test-codegen.xml \ Traceback (most recent call last):
+ Trace 227421
sys.exit(codegen_main())
parsed_ifaces = parser.parse_dbus_xml(xml_data)
(Not sure how to fix it otherwise I'd just commit the fix instead of complaining here)
Further research landed me at http://www.linuxjournal.com/article/8919 Operator: ${foo:+bar} Function: If $foo exists and is not null, return bar. If it doesn't exist or is null, return a null. Is this even portable shell? Or is it a bash(1)ism? So you basically just want to put something in front of the PYTHONPATH variable and properly deal with the situation where it's set (it normally isn't) (why?). Are you sure that it's not good enough to just do PYTHONPATH=$(top_srcdir)/gio/gdbus-codegen:$$PYTHONPATH If no, isn't there a make feature to achieve this so we can avoid doing shell tricks?
Of course, the problem is that you run gio/gdbus-codegen/gdbus-codegen which does path = os.path.join('/usr/lib64', 'gdbus-codegen') sys.path.insert(0, path) from codegen_main import codegen_main sys.exit(codegen_main()) so it completely doesn't matter whether we set PYTHONPATH correctly or not...
Fixed with this commit http://git.gnome.org/browse/glib/commit/?id=f819aa5f1715bb67fd4e269a6e8021144ecf91a6