[Pythonmac-SIG] py2app and nested packages

Ronald Oussoren ronaldoussoren at mac.com
Tue Apr 24 13:29:51 CEST 2012


On 23 Apr, 2012, at 20:42, Chris Barker wrote:

> Folks,
> 
> py2app doesn't seem to do "the right thing" with nested packages.
> However, it's not entirely clear what it should do...
> 
> example: the "pubsub" package is delivered with wxPython, so it is
> commonly imported thusly:
> 
> from wx.lib.pubsub import Publisher

wx.lib.pubsub is a bad example, it manipulates __path__ which causes problems with py2app because it cannot detect this.  I added a recipe to py2app's repository a while ago that should fix this particular problem.

> 
> However, in wx.lib.pubsub, there is some trickery in the __init___, so
> as py2app installs it, ot doesn't work (see previous messages to this
> and the wxPython list). However, if you do:
> 
> packages = ['wx.lib.pubsub']  ...
> 
> in your py2app setup.py, you get the entire pubsub package, but installed in :
> 
> Peppy.app/Contents/Resources/lib/python2.7/pubsub

That's a bug, the code that implements the packages options assumes that all mentioned packages are toplevel packages.  It should be fairly easy to fix that, although this requires some path manipulation trickery because the subpackage will be in a different location that the parent: the parent is in site-packages.zip while the child is not.
> 
> so it will work, but only if you now import it as:
> 
> from pubsub import Publisher
> 
> not too heinous, but it's really nice if we don't have to change
> imports for the bundled version.
> 
> if I add 'wx' to packages, It does work, but I've then got all of wx,
> all of wx.lib, etc, which is  really a bit much (the resulting app
> bundle is 124MB, vs. 60 without specifying the wx package)
> 
> At first, I thought I'd want:
> 
> wx/lib/pubsub/....
> 
> put on sys.path, with wx and lib empty except the specified dirs.
> However, that would put two "wx" dirs on sys.path, which would not be
> good (assuming wx is used...)
> 
> Would it be possible for the packages specification to be processed
> after modulegraph is run, and it would then see that "wx" and "wx.lib"
> are there, and then put all of pubsub in there? Or maybe put the parts
> of wx and wx.lib that were already going to be included outside the
> zip bundle?

The option "packages" currently always stores the included package outside of site-packages.zip to ensure that data files can be loaded in the old pre-pkgresources way (that is, by opening paths relative to somepackage.__file__). 

Ronald

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4788 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20120424/1eb68e73/attachment.bin>


More information about the Pythonmac-SIG mailing list