diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2009-02-12 15:01:44 (GMT) |
---|---|---|
committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2009-02-12 15:01:44 (GMT) |
commit | 827822ef3f389548ca2ac11b11c5e498f45fe78a (patch) | |
tree | 94532be2aa8126ef966cff4f1f7c0d7d35871b37 /Mac | |
parent | de09acf2984b6699aa7a45c2ea2429c6da5f046e (diff) | |
download | cpython-827822ef3f389548ca2ac11b11c5e498f45fe78a.zip cpython-827822ef3f389548ca2ac11b11c5e498f45fe78a.tar.gz cpython-827822ef3f389548ca2ac11b11c5e498f45fe78a.tar.bz2 |
Fix for issue5194, based on a patch by Ned Deily.
Diffstat (limited to 'Mac')
-rwxr-xr-x | Mac/IDLE/IDLE.app/Contents/MacOS/IDLE | 2 | ||||
-rw-r--r-- | Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py | 57 | ||||
-rw-r--r-- | Mac/Makefile.in | 2 |
3 files changed, 52 insertions, 9 deletions
diff --git a/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE b/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE index ecf29bf..61b02ff 100755 --- a/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE +++ b/Mac/IDLE/IDLE.app/Contents/MacOS/IDLE @@ -1,4 +1,4 @@ -#!%prefix%/Resources/Python.app/Contents/MacOS/Python3 +#!%prefix%/Resources/Python.app/Contents/MacOS/%exe% import sys, os execdir = os.path.dirname(sys.argv[0]) diff --git a/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py b/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py index 9b52738..d6803ba 100644 --- a/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py +++ b/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py @@ -3,8 +3,6 @@ Bootstrap script for IDLE as an application bundle. """ import sys, os -from idlelib.PyShell import main - # Change the current directory the user's home directory, that way we'll get # a more useful default location in the open/save dialogs. os.chdir(os.path.expanduser('~/Documents')) @@ -13,10 +11,54 @@ os.chdir(os.path.expanduser('~/Documents')) # Make sure sys.executable points to the python interpreter inside the # framework, instead of at the helper executable inside the application # bundle (the latter works, but doesn't allow access to the window server) -if sys.executable.endswith('-32'): - sys.executable = os.path.join(sys.prefix, 'bin', 'python-32') -else: - sys.executable = os.path.join(sys.prefix, 'bin', 'python') +# +# .../IDLE.app/ +# Contents/ +# MacOS/ +# IDLE (a python script) +# Python{-32} (symlink) +# Resources/ +# idlemain.py (this module) +# ... +# +# ../IDLE.app/Contents/MacOS/Python{-32} is symlinked to +# ..Library/Frameworks/Python.framework/Versions/m.n +# /Resources/Python.app/Contents/MacOS/Python{-32} +# which is the Python interpreter executable +# +# The flow of control is as follows: +# 1. IDLE.app is launched which starts python running the IDLE script +# 2. IDLE script exports +# PYTHONEXECUTABLE = .../IDLE.app/Contents/MacOS/Python{-32} +# (the symlink to the framework python) +# 3. IDLE script alters sys.argv and uses os.execve to replace itself with +# idlemain.py running under the symlinked python. +# This is the magic step. +# 4. During interpreter initialization, because PYTHONEXECUTABLE is defined, +# sys.executable may get set to an unuseful value. +# +# (Note that the IDLE script and the setting of PYTHONEXECUTABLE is +# generated automatically by bundlebuilder in the Python 2.x build. +# Also, IDLE invoked via command line, i.e. bin/idle, bypasses all of +# this.) +# +# Now fix up the execution environment before importing idlelib. + +# Reset sys.executable to its normal value, the actual path of +# the interpreter in the framework, by following the symlink +# exported in PYTHONEXECUTABLE. +pyex = os.environ['PYTHONEXECUTABLE'] +sys.executable = os.path.join(os.path.dirname(pyex), os.readlink(pyex)) + +# Remove any sys.path entries for the Resources dir in the IDLE.app bundle. +p = pyex.partition('.app') +if p[2].startswith('/Contents/MacOS/Python'): + sys.path = [value for value in sys.path if + value.partition('.app') != (p[0], p[1], '/Contents/Resources')] + +# Unexport PYTHONEXECUTABLE so that the other Python processes started +# by IDLE have a normal sys.executable. +del os.environ['PYTHONEXECUTABLE'] # Look for the -psn argument that the launcher adds and remove it, it will # only confuse the IDLE startup code. @@ -25,6 +67,7 @@ for idx, value in enumerate(sys.argv): del sys.argv[idx] break -#argvemulator.ArgvCollector().mainloop() +# Now it is safe to import idlelib. +from idlelib.PyShell import main if __name__ == '__main__': main() diff --git a/Mac/Makefile.in b/Mac/Makefile.in index f28d1ea..e847ba9 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -215,7 +215,7 @@ install_Python4way: install_Python install_IDLE: test -d "$(DESTDIR)$(PYTHONAPPSDIR)" || mkdir -p "$(DESTDIR)$(PYTHONAPPSDIR)" - -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -r "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" + -test -d "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" && rm -rf "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app" /bin/cp -PR "$(srcdir)/IDLE/IDLE.app" "$(DESTDIR)$(PYTHONAPPSDIR)" ln -sf $(INSTALLED_PYTHONAPP) "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/Python" sed -e "s!%prefix%!$(prefix)!g" -e 's!%exe%!$(PYTHONFRAMEWORK)!g' < "$(srcdir)/IDLE/IDLE.app/Contents/MacOS/IDLE" > "$(DESTDIR)$(PYTHONAPPSDIR)/IDLE.app/Contents/MacOS/IDLE" |