ยปCore Development>Code coverage>Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py

Python code coverage for Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py

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