|
| 1 | +""" idlelib.run |
| 2 | +
|
| 3 | +Simplified, pyshell.ModifiedInterpreter spawns a subprocess with |
| 4 | +f'''{sys.executable} -c "__import__('idlelib.run').run.main()"''' |
| 5 | +'.run' is needed because __import__ returns idlelib, not idlelib.run. |
| 6 | +""" |
1 | 7 | import io
|
2 | 8 | import linecache
|
3 | 9 | import queue
|
|
8 | 14 | import threading
|
9 | 15 | import warnings
|
10 | 16 |
|
11 |
| -import tkinter # Tcl, deletions, messagebox if startup fails |
12 |
| - |
13 | 17 | from idlelib import autocomplete # AutoComplete, fetch_encodings
|
14 | 18 | from idlelib import calltip # Calltip
|
15 | 19 | from idlelib import debugger_r # start_debugger
|
|
19 | 23 | from idlelib import stackviewer # StackTreeItem
|
20 | 24 | import __main__
|
21 | 25 |
|
22 |
| -for mod in ('simpledialog', 'messagebox', 'font', |
23 |
| - 'dialog', 'filedialog', 'commondialog', |
24 |
| - 'ttk'): |
25 |
| - delattr(tkinter, mod) |
26 |
| - del sys.modules['tkinter.' + mod] |
| 26 | +import tkinter # Use tcl and, if startup fails, messagebox. |
| 27 | +if not hasattr(sys.modules['idlelib.run'], 'firstrun'): |
| 28 | + # Undo modifications of tkinter by idlelib imports; see bpo-25507. |
| 29 | + for mod in ('simpledialog', 'messagebox', 'font', |
| 30 | + 'dialog', 'filedialog', 'commondialog', |
| 31 | + 'ttk'): |
| 32 | + delattr(tkinter, mod) |
| 33 | + del sys.modules['tkinter.' + mod] |
| 34 | + # Avoid AttributeError if run again; see bpo-37038. |
| 35 | + sys.modules['idlelib.run'].firstrun = False |
27 | 36 |
|
28 | 37 | LOCALHOST = '127.0.0.1'
|
29 | 38 |
|
@@ -523,4 +532,9 @@ def stackviewer(self, flist_oid=None):
|
523 | 532 | item = stackviewer.StackTreeItem(flist, tb)
|
524 | 533 | return debugobj_r.remote_object_tree_item(item)
|
525 | 534 |
|
526 |
| -capture_warnings(False) # Make sure turned off; see issue 18081 |
| 535 | + |
| 536 | +if __name__ == '__main__': |
| 537 | + from unittest import main |
| 538 | + main('idlelib.idle_test.test_run', verbosity=2) |
| 539 | + |
| 540 | +capture_warnings(False) # Make sure turned off; see bpo-18081. |
0 commit comments