[Pythonmac-SIG] Building multiple command-line( ( CLI ) programs with py2app

Read Roberts rroberts at adobe.com
Wed Jan 18 17:35:50 CET 2006


One good reason for a stand-alone Python is when the distribution contains
third=-party extension modules, which are of necessity bound to a particular
version of Python, and the interval between updates is likely to be several
years. 

However, the need can be met with a py2app program which just assumes the
first command-line argument is a Python script file and executes it, much as
does the _boot_.py script inside the py2app-generated bundle app. py2app
does allow you to include all the modules you could ever need. The only
extension that might be useful would be a py2app switch which says "include
every module possible".

I have so far found only two issues to work around in the scenario above:
- the command-line program at
<program-name>.app/Conyents/MacOS/<program-name> cannot be accessed via a
symbolic link; to make it accessible to the user, you must provide a shell
script which invokes it by an absolute path.

- when your Python file is executed, the current working directory has been
changed to <program-name>.app/Conyents/Resource. This happens before
_boot_.py is called. Fortunately, the Unix environment variable PWD still
holds the original current working directory,  so adding
os.chdir(os.environ["PWD"]) to your py2app'd script restores this bit of
lost context.

Apart from these two issues, my "pythonFDK" works as expected, which is
great.


On the separate issue of distributing many py2app'd Python programs, It has
also occurred to me than frameworks can be accessed via symbolic link, so
you can avoid the file-size overhead of a a Python distribution  for each
app just by building one of the apps with the modules necessary for any app,
and in all the other apps, replacing the
<program-name>.app/Conyents/Resource/Python/pythonframework directory with a
symbolic link to the matching directory in the first app. Of course, all the
apps must then stay in a fixed relative position within a directory tree,
but this is a common requirement.


- Read Roberts

On 1/17/06 11:11 AM, "Bob Ippolito" <bob at redivi.com> wrote:

> 
> On Jan 17, 2006, at 10:11 AM, Christopher Barker wrote:
> 
>> Bob Ippolito wrote:
>>> What do you want to happen, ideally?  Clearly you don't want 30
>>> CLI  apps with 30 full Python distributions.  There are several
>>> workarounds, but in order to make py2app serve your needs I'm
>>> going  to need to know what that is.
>> 
>> I've thought about this, and I think the solutions proposed will
>> probably work well for the OP. However,  I'd like to have another
>> option. I'd like to be able to install a complete Python
>> distribution that has all the packages my apps need, all in one
>> bundle. Then the individual scripts would use that, rather than the
>> regular installed python. Perhaps you'd have a #! line like:
>> 
>> /usr/bin/env MySpecialPython
> ...
>> Does anyone else think this would be useful?
> 
> Not really... this would require an installer, so you might as well
> use a regular Python distro.  There's no way I'm gonna implement it,
> but patches accepted if enough people want it.
> 
> -bob
> 
> 

Read Roberts Adobe SJ on Weds, home office 415-642-5642 other days



More information about the Pythonmac-SIG mailing list