[Pythonmac-SIG] [Numpy-discussion] Packaging numpy with py2app

Bob Ippolito bob at redivi.com
Wed Jul 19 01:28:14 CEST 2006


On Jul 18, 2006, at 2:36 PM, Josh Marshall wrote:

> On 18/07/2006, at 3:15 PM, Bob Ippolito wrote:
>>> def check(cmd, mf):
>>>     m = mf.findNode('matplotlib')
>>>     if m is None or m.filename is None:
>>>         return None
>>>     mf.import_hook('pytz.zoneinfo', m, ['UTC'])
>>>     return dict(
>>>         packages = ['matplotlib']
>>>     )
>>>
>>> If anyone needs to actual work with the plotting of time-zone  
>>> relative dates in matplotlib in embedded Cocoa, it'll die.  
>>> However, the likelihood of this occurring is low, but for future  
>>> reference for the Googlers of the future; add the time-zones you  
>>> need to the list in import_hook, ie ['UTC', 'Australia.Sydney'].
>>
>> If you were actually doing that, you should write the imports  
>> yourself. The right place to put that metadata is in your code  
>> with import statements, because that's cross-platform and cross- 
>> packager. py2exe and cx_Freeze will understand import statements too.
>
> Agreed. I searched through matplotlib and pytz, and found that you  
> can add a straightforward import of pytz.zoneinfo.UTC rather than  
> going through a loader function. I will submit as a patch to the  
> matplotlib developers. I suggest leaving the line in the recipe for  
> a while at least.

Yeah, that's fine.

>> You can't do that so long as scipy is wholly included with the  
>> packages option. The packages option does "cp -r" effectively, I'm  
>> not going to complicate it for this use case. I might accept a  
>> patch if it wasn't too horrible, but the effort is better spent  
>> making scipy work in a zip archive.
>
> Agreed, although with the latest version of py2app working out of  
> the box with the recipes, I'll probably let it slide.
>
> I spent a bit more time looking at matplotlib, and realised I just  
> need to include the data files (fonts, rc, icons) directory in the  
> Resources dir in the app. When I did this manually, it worked fine,  
> since there is code to detect frozen status in the initialisation,  
> and it searches the Resources dir.
>
> However, I can't figure out how to copy resources in the recipe. It  
> seems in recipes, you can return in the dict: packages,  
> flatpackages, filters, loader_files, and prescripts. Could you  
> enlighten me on the use of each of these?

The recipe mechanism doesn't allow for it because it doesn't  
generally make sense. There are very few packages that can find their  
resources in an alternative manner. I'm not totally opposed to adding  
another feature to support that use case, but throwing it directly in  
the resources dir seems like a bad idea to do automatically from a  
recipe. The files should sit under some kind of matplotlib hierarchy.  
It would be nicer to see matplotlib just figure out how to make their  
app work from a zip... pygame does, and it has fonts and icons.

packages wholly includes a package as-is, outside the zip.

flatpackages doesn't do anything useful, it inserts a false node into  
the graph to group "extra_path" packages together. PIL and PyObjC are  
the only two projects I can recall doing this. Changing the graph in  
such a way has no effect whatsoever, it's merely an aesthetic change  
to the graph which can be useful if you're visualizing it.

filters adds a dependency filter.. a function that gets called with  
every modulegraph node and decides whether to include it or not.  
There are several of these in py2app, but none demonstrated as a  
recipe. It usually doesn't make sense to use this in a recipe. See  
py2app.filters for examples of filters.

loader_files puts data files *in the zip*

prescripts are code that gets put in the bootstrap. The PIL recipe  
has one of these.

-bob



More information about the Pythonmac-SIG mailing list