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 651998 - gdbus-codegen: Use relative Python imports
gdbus-codegen: Use relative Python imports
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-06-06 15:39 UTC by Colin Walters
Modified: 2011-06-09 15:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdbus-codegen: Use relative Python imports (4.42 KB, patch)
2011-06-06 15:39 UTC, Colin Walters
none Details | Review

Description Colin Walters 2011-06-06 15:39:16 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.
Comment 1 Colin Walters 2011-06-06 15:39:17 UTC
Created attachment 189332 [details] [review]
gdbus-codegen: Use relative Python imports
Comment 2 Colin Walters 2011-06-06 21:55:42 UTC
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.
Comment 3 David Zeuthen (not reading bugmail) 2011-06-09 15:22:56 UTC
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):
  • File "../../gio/gdbus-codegen/gdbus-codegen", line 33 in <module>
    sys.exit(codegen_main())
  • File "/home/davidz/Hacking/glib/gio/gdbus-codegen/codegen_main.py", line 171 in codegen_main
    parsed_ifaces = parser.parse_dbus_xml(xml_data)
TypeError: parse_dbus_xml() takes exactly 3 arguments (1 given)

Comment 4 David Zeuthen (not reading bugmail) 2011-06-09 15:23:38 UTC
(Not sure how to fix it otherwise I'd just commit the fix instead of complaining here)
Comment 5 David Zeuthen (not reading bugmail) 2011-06-09 15:42:53 UTC
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?
Comment 6 David Zeuthen (not reading bugmail) 2011-06-09 15:48:14 UTC
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...
Comment 7 David Zeuthen (not reading bugmail) 2011-06-09 15:53:57 UTC
Fixed with this commit

http://git.gnome.org/browse/glib/commit/?id=f819aa5f1715bb67fd4e269a6e8021144ecf91a6