Skip to content

Commit 48b4d1d

Browse files
committed
Lib: Improve IDLE launcher script for clarity and safety
1 parent ffe8598 commit 48b4d1d

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

Doc/tutorial/introduction.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ For example::
6363
5.0
6464
>>> 8 / 5 # division always returns a floating-point number
6565
1.6
66-
>>> 2 ** 9 #2 raised to the power of 9
67-
512
6866

6967
The integer numbers (e.g. ``2``, ``4``, ``20``) have type :class:`int`,
7068
the ones with a fractional part (e.g. ``5.0``, ``1.6``) have type

Lib/idlelib/idle.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
import os.path
1+
import os
22
import sys
33

4+
def add_idlelib_to_path():
5+
"""
6+
Adds the parent directory of the current file's parent directory
7+
to sys.path to allow running IDLE from a non-standard location.
8+
"""
9+
idlelib_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
10+
if idlelib_dir not in sys.path:
11+
sys.path.insert(0, idlelib_dir)
12+
return idlelib_dir
413

5-
# Enable running IDLE with idlelib in a non-standard location.
6-
# This was once used to run development versions of IDLE.
7-
# Because PEP 434 declared idle.py a public interface,
8-
# removal should require deprecation.
9-
idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10-
if idlelib_dir not in sys.path:
11-
sys.path.insert(0, idlelib_dir)
14+
def main():
15+
"""
16+
Import and run IDLE's main shell.
17+
"""
18+
add_idlelib_to_path()
19+
try:
20+
from idlelib.pyshell import main as idle_main
21+
except ImportError as e:
22+
print("Could not import idlelib.pyshell:", e)
23+
sys.exit(1)
24+
idle_main()
1225

13-
from idlelib.pyshell import main # This is subject to change
14-
main()
26+
if __name__ == "__main__":
27+
main()

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,4 @@ This Python distribution contains *no* GNU General Public License (GPL) code,
232232
so it may be used in proprietary projects. There are interfaces to some GNU
233233
code but these are entirely optional.
234234

235-
All trademarks referenced herein are property of their respective holders.
235+
All trademarks referenced herein are property of their respective holders.

iOS/testbed/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def clone_testbed(
9999
print(f"{target} already exists; aborting without creating project.")
100100
sys.exit(10)
101101

102+
102103
if framework is None:
103104
if not (
104105
source / "Python.xcframework/ios-arm64_x86_64-simulator/bin"

0 commit comments

Comments
 (0)