[Idle-dev] use_subprocess issues...

Tony Lownds tony@lownds.com
Tue, 24 Sep 2002 11:23:14 -0700


At 1:33 PM -0400 9/23/02, Kurt B. Kaiser wrote:
>Tony Lownds <tony@lownds.com> writes:
>  >
>>  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".

Well, it is an interpreter executable! In fact it actually runs 
python's Py_Main (I said otherwise earlier). But Py_Main, for OSX, 
when running inside an applet, does not process command line 
arguments.

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

Yes, sys.exec_prefix + 'bin/python' is reliable BUT unfortunately 
that will not include the magic .app directory in argv[0], so running 
Tkinter (or any other type of GUI) won't work. But it would work for 
non-GUI scripts.

>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!


I doubt you will find it any less ugly, but: how about special casing 
the idle.py file (or rather, a Mac OS X specific idle.py equivalent?) 
Something like:

## check to see if we should load idle.py or run.py
## by looking at sys.argv

if we_were_spawned:
   # Load idlelib/run.py which runs the user's code
   # or interactive interpreter
   del sys.argv[...]
   import run
   run.main()
else:
   # Load idlelib/idle.py which starts the application.
   import idle

>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.

I wonder if py2exe have the same issues? It stems from running as an 
applet (python source and interpreter bundled into one file somehow).

-Tony