[Idle-dev] use_subprocess issues...

Kurt B. Kaiser kbk@shore.net
23 Sep 2002 13:33:25 -0400


Tony Lownds <tony@lownds.com> writes:

> >How does PyShell get called by os.spawnv()?  What is sys.executable on
> >your Mac, and what is the test for .app doing?  On my Linux system
> >it's /usr/local/bin/python and the command (a user defined module)
> >gets passed to that executable, which is started as a subprocess
> >'execution server' to Idle.
> 
> Applications on OS X are directory trees. On Linux they are files in
> ELF format, on OSX they are directories. It's strange. The directory
> for an application must have a .app extension. Somewhere inside the
> directory is a normal executable file, the icon for the application,
> and anything else that a application wants to put in there. IDLE is
> installed inside it's own IDLE.app directory. The actual executable is
> *named* python on disk, but it does not have the same main() as the
> python you use. Instead the main() looks for startup code inside the
> IDLE.app directory.
> 
> The test for '.app' is looking for that magic extension. Its a
> marker to determine if the user is running on darwin/Aqua (a.k.a Mac
> OS X) or darwin/X11 (which does happen). 

Ah.  I didn't know if it was short for .apple or .app :)

> BTW, I would like to put that test somewhere in a function - is
> there an appropriate module?
> 

IMO a function like that should just be a ModifiedInterpreter class
method.  Put it close to the point of use.

> 
> sys.executable is something like
> '/Applications/Python/IDLE.app/Contents/MacOS/python'
> 
> So: running sys.executable runs the special* python in the IDLE.app
> directory. That looks for the __main__.pyc file, which is compiled
> from "idle.py"
> and idle.py runs PyShell.
> 
> Python's normal option processing never happens! I think this is an
> odd situation.

It seems to me that sys.executable is coming up with the wrong value.
It is supposed to be a string containing the name of the interpreter
executable, not Idle.  While it may be "python", from a practical
point of view it's "idle".

Isn't there a way to run Python from the command prompt in OS X?
That's the executable that should be called.

If sys.executable can't be fixed, then maybe special case the args
variable in spawn_subprocess() for OS X and feed it the location of
the Python command line interpreter.  (See below!)

> 
> The only fix I envision is for PyShell to add a new switch (say, -r)
> that runs run.main(), used only on Mac OS X. That is kinda ugly, and
> I want to discuss it more before working on it.

That's more than kinda ugly.  I don't recommend that approach!

> 
> It's possible the applet model should be fixed in python. I believe
> only Jack Jansen is qualified to make that determination. He is on
> vacation right now.

If there is no Python command line interpreter in OS X, then that's a
problem that Jack would have to be involved in.  There certainly 
should be one.

Regards, KBK