From 28e8d7bdcf8f44cf32033b3f352dbe30ea716590 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 23 May 2019 21:42:49 -0400 Subject: [PATCH 1/2] run.py changes --- Lib/idlelib/run.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index b4a2b54a33c850b..568f6649fee9823 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -8,8 +8,6 @@ import threading import warnings -import tkinter # Tcl, deletions, messagebox if startup fails - from idlelib import autocomplete # AutoComplete, fetch_encodings from idlelib import calltip # Calltip from idlelib import debugger_r # start_debugger @@ -19,11 +17,15 @@ from idlelib import stackviewer # StackTreeItem import __main__ -for mod in ('simpledialog', 'messagebox', 'font', - 'dialog', 'filedialog', 'commondialog', - 'ttk'): - delattr(tkinter, mod) - del sys.modules['tkinter.' + mod] +import tkinter # Tcl, deletions, messagebox if startup fails +if not hasattr(sys.modules['idlelib.run'], 'firstrun'): + # Undo modifications of tkinter by idlelib imports. + for mod in ('simpledialog', 'messagebox', 'font', + 'dialog', 'filedialog', 'commondialog', + 'ttk'): + delattr(tkinter, mod) + del sys.modules['tkinter.' + mod] + sys.modules['idlelib.run'].firstrun = False LOCALHOST = '127.0.0.1' From 5fb04ca1c98fe6fe40902a0a5501d79b17148205 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Fri, 24 May 2019 18:58:51 -0400 Subject: [PATCH 2/2] bpo-37038: Make idlelib.run runnable; add test clause. --- Lib/idlelib/NEWS.txt | 2 ++ Lib/idlelib/run.py | 18 +++++++++++++++--- .../2019-05-24-18-57-57.bpo-37038.AJ3RwQ.rst | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2019-05-24-18-57-57.bpo-37038.AJ3RwQ.rst diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 3f19ce737396308..e1bc009ae933323 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,6 +3,8 @@ Released on 2019-10-20? ====================================== +bpo-37038: Make idlelib.run runnable; add test clause. + bpo-36958: Print any argument other than None or int passed to SystemExit or sys.exit(). diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 568f6649fee9823..4075deec51d8ed1 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -1,3 +1,9 @@ +""" idlelib.run + +Simplified, pyshell.ModifiedInterpreter spawns a subprocess with +f'''{sys.executable} -c "__import__('idlelib.run').run.main()"''' +'.run' is needed because __import__ returns idlelib, not idlelib.run. +""" import io import linecache import queue @@ -17,14 +23,15 @@ from idlelib import stackviewer # StackTreeItem import __main__ -import tkinter # Tcl, deletions, messagebox if startup fails +import tkinter # Use tcl and, if startup fails, messagebox. if not hasattr(sys.modules['idlelib.run'], 'firstrun'): - # Undo modifications of tkinter by idlelib imports. + # Undo modifications of tkinter by idlelib imports; see bpo-25507. for mod in ('simpledialog', 'messagebox', 'font', 'dialog', 'filedialog', 'commondialog', 'ttk'): delattr(tkinter, mod) del sys.modules['tkinter.' + mod] + # Avoid AttributeError if run again; see bpo-37038. sys.modules['idlelib.run'].firstrun = False LOCALHOST = '127.0.0.1' @@ -525,4 +532,9 @@ def stackviewer(self, flist_oid=None): item = stackviewer.StackTreeItem(flist, tb) return debugobj_r.remote_object_tree_item(item) -capture_warnings(False) # Make sure turned off; see issue 18081 + +if __name__ == '__main__': + from unittest import main + main('idlelib.idle_test.test_run', verbosity=2) + +capture_warnings(False) # Make sure turned off; see bpo-18081. diff --git a/Misc/NEWS.d/next/IDLE/2019-05-24-18-57-57.bpo-37038.AJ3RwQ.rst b/Misc/NEWS.d/next/IDLE/2019-05-24-18-57-57.bpo-37038.AJ3RwQ.rst new file mode 100644 index 000000000000000..762e9f1e43749db --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-05-24-18-57-57.bpo-37038.AJ3RwQ.rst @@ -0,0 +1 @@ +Make idlelib.run runnable; add test clause.