| 1 | n/a | """ |
|---|
| 2 | n/a | Bootstrap script for IDLE as an application bundle. |
|---|
| 3 | n/a | """ |
|---|
| 4 | n/a | import sys, os |
|---|
| 5 | n/a | |
|---|
| 6 | n/a | # Change the current directory the user's home directory, that way we'll get |
|---|
| 7 | n/a | # a more useful default location in the open/save dialogs. |
|---|
| 8 | n/a | os.chdir(os.path.expanduser('~/Documents')) |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | # Make sure sys.executable points to the python interpreter inside the |
|---|
| 12 | n/a | # framework, instead of at the helper executable inside the application |
|---|
| 13 | n/a | # bundle (the latter works, but doesn't allow access to the window server) |
|---|
| 14 | n/a | # |
|---|
| 15 | n/a | # .../IDLE.app/ |
|---|
| 16 | n/a | # Contents/ |
|---|
| 17 | n/a | # MacOS/ |
|---|
| 18 | n/a | # IDLE (a python script) |
|---|
| 19 | n/a | # Python{-32} (symlink) |
|---|
| 20 | n/a | # Resources/ |
|---|
| 21 | n/a | # idlemain.py (this module) |
|---|
| 22 | n/a | # ... |
|---|
| 23 | n/a | # |
|---|
| 24 | n/a | # ../IDLE.app/Contents/MacOS/Python{-32} is symlinked to |
|---|
| 25 | n/a | # ..Library/Frameworks/Python.framework/Versions/m.n |
|---|
| 26 | n/a | # /Resources/Python.app/Contents/MacOS/Python{-32} |
|---|
| 27 | n/a | # which is the Python interpreter executable |
|---|
| 28 | n/a | # |
|---|
| 29 | n/a | # The flow of control is as follows: |
|---|
| 30 | n/a | # 1. IDLE.app is launched which starts python running the IDLE script |
|---|
| 31 | n/a | # 2. IDLE script exports |
|---|
| 32 | n/a | # PYTHONEXECUTABLE = .../IDLE.app/Contents/MacOS/Python{-32} |
|---|
| 33 | n/a | # (the symlink to the framework python) |
|---|
| 34 | n/a | # 3. IDLE script alters sys.argv and uses os.execve to replace itself with |
|---|
| 35 | n/a | # idlemain.py running under the symlinked python. |
|---|
| 36 | n/a | # This is the magic step. |
|---|
| 37 | n/a | # 4. During interpreter initialization, because PYTHONEXECUTABLE is defined, |
|---|
| 38 | n/a | # sys.executable may get set to an unuseful value. |
|---|
| 39 | n/a | # |
|---|
| 40 | n/a | # (Note that the IDLE script and the setting of PYTHONEXECUTABLE is |
|---|
| 41 | n/a | # generated automatically by bundlebuilder in the Python 2.x build. |
|---|
| 42 | n/a | # Also, IDLE invoked via command line, i.e. bin/idle, bypasses all of |
|---|
| 43 | n/a | # this.) |
|---|
| 44 | n/a | # |
|---|
| 45 | n/a | # Now fix up the execution environment before importing idlelib. |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | # Reset sys.executable to its normal value, the actual path of |
|---|
| 48 | n/a | # the interpreter in the framework, by following the symlink |
|---|
| 49 | n/a | # exported in PYTHONEXECUTABLE. |
|---|
| 50 | n/a | pyex = os.environ['PYTHONEXECUTABLE'] |
|---|
| 51 | n/a | sys.executable = os.path.join(sys.prefix, 'bin', 'python%d.%d'%(sys.version_info[:2])) |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | # Remove any sys.path entries for the Resources dir in the IDLE.app bundle. |
|---|
| 54 | n/a | p = pyex.partition('.app') |
|---|
| 55 | n/a | if p[2].startswith('/Contents/MacOS/Python'): |
|---|
| 56 | n/a | sys.path = [value for value in sys.path if |
|---|
| 57 | n/a | value.partition('.app') != (p[0], p[1], '/Contents/Resources')] |
|---|
| 58 | n/a | |
|---|
| 59 | n/a | # Unexport PYTHONEXECUTABLE so that the other Python processes started |
|---|
| 60 | n/a | # by IDLE have a normal sys.executable. |
|---|
| 61 | n/a | del os.environ['PYTHONEXECUTABLE'] |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | # Look for the -psn argument that the launcher adds and remove it, it will |
|---|
| 64 | n/a | # only confuse the IDLE startup code. |
|---|
| 65 | n/a | for idx, value in enumerate(sys.argv): |
|---|
| 66 | n/a | if value.startswith('-psn_'): |
|---|
| 67 | n/a | del sys.argv[idx] |
|---|
| 68 | n/a | break |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | # Now it is safe to import idlelib. |
|---|
| 71 | n/a | from idlelib.pyshell import main |
|---|
| 72 | n/a | if __name__ == '__main__': |
|---|
| 73 | n/a | main() |
|---|