[Pythonmac-SIG] shrink app bundle size (removing unused stuff)?

Chris Barker chris.barker at noaa.gov
Sun Mar 11 00:02:06 CET 2012


On Fri, Mar 9, 2012 at 7:22 AM, Ronald Oussoren
> Py2app will never be able to do everything, but I'd prefer to get closer than we're currently.

A laudable goal, for sure -- and we much appreciate your work on py2app.

> Are there things you have to do every time that could
> (easily) be expressed as configuration for py2app?

As suggested, 'include', 'excludes', and 'packages' could perhaps be
more robust.

I haven't checked recently -- have you fixed the issue where you had
to explicitly include the parent package when you want to includ ea
sub-package?

ie. you want to be able to :

import libA.libB

(but nothing else in libA)

IN the past, I've had to do:

packages = ['libA', 'libA.libB']

ANother major thought:

I've thought that maybe we need a way to build a module graph from
run-time information, rather than code inspection -- that would
address both:

importing packages you don't need
and
fancy dynamic imports.

The trick is that you'd need to have a way to run your code that
guaranteed that eveything ws imported that might be needed (i.e.
dynamci import), but it seems that you'd want test code that did that
anyway.

I may be missing something, but it seems all you'd need to do is look
at sys.modules, and write out a modulegraph (or would it even need to
be  graph? a simple list would do...)

Then Py2app would need a way to load the modulegraph (or list) from a file.

Even without a runtime inspector -- this could be handy as you could:

1) only re-run the code inspection part when you knew you'd added a
module, rather than on every build

2) you could tweak the module graph by hand and re-use it, rather than
tweaking the resulting package.

Anyway, maybe too much architectural work for now...

> 1) I added a py2app recipe that does the right thing
> with the pubsub library in wxPython. That library uses
> __path__ hacks and that confuses modulegraph (and
> hence py2app). Because of this you no longer have to
> explicitly include 'wx' in the application bundle

Very nice! I happen to need that for a project right now.

> 2) I tweaked the matplotlib recipe in py2app, it no
> longer copies the entire package but adds a hook to
> tell matplotlib where its data is. This solution is not fully
> complete yet, I'm currently including mpl-data twice
> (once in Resources, once in site-packages.zip) and
> the later copy is not needed.

also nice -- did you use:

matplotlib.get_py2exe_datafiles()

That is handy for py2exe.

Thanks for you work...

-Chris













  It seems that python is slowly moving towards a more declarative way
of specifying builds using a setup.cfg file instead of setup.py though
the distutils2/packaging project and py2app should do the same when
that happens (without dropping support for setup.py files of course).
>
> Ronald
>



-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Pythonmac-SIG mailing list