classification
Title: IDLE: exec IDLESTARTUP/PYTHONSTARTUP on restart
Type: behavior Stage: needs patch
Components: IDLE Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: MLModel, asvetlov, cben, gpolo, kbk, terry.reedy
Priority: normal Keywords: patch

Created on 2009-02-12 22:34 by MLModel, last changed 2020-01-07 21:02 by terry.reedy.

Files
File name Uploaded Description Edit
PyShell-2.7.diff MLModel, 2009-02-12 22:34 mods to enable IDLE's loading startup file on restart
PyShell-3.1.diff MLModel, 2009-03-09 14:45 mods to enable IDLE's loading startup file on restart in Python 3
startup-2.7.diff cben, 2010-03-16 20:15 and now actually run them after restart
Messages (9)
msg81831 - (view) Author: Mitchell Model (MLModel) Date: 2009-02-12 22:34
The main thing the patch does is:
	modify the subprocess restart procedure so that it reloads 
whatever file, if any, was loaded when IDLE first started and looked for 
IDLESTARTUP then PYTHONSTARTUP environment variables.

In addition:
	a -q option is added for starting IDLE on the command line to 
mean "quiet", as with Emacs, e.g., to suppress loading of IDLESTARTUP or 
PYTHONSTARTUP
	The former effect of -s would now be the default, which is 
desirable so double-clicking an IDLE icon to start it will cause the 
startup file to run.
	-s is changed to take an argument that is an alternate startup 
file to use

I am a bit concerned about changing -s to have a different meaning. 
Perhaps it's better to leave -s as an option that is simplhy superfluous 
and use a different letter for the alternate startup.
msg83386 - (view) Author: Mitchell Model (MLModel) Date: 2009-03-09 14:45
Adding patch for 3.1 from issue 5234 to this as per Martin's request.
msg83399 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-03-09 19:22
Assigning to kbk since 5234 was assigned to him.
msg101183 - (view) Author: Cherniavsky Beni (cben) * Date: 2010-03-16 20:15
Oops!  Mitchell's patch didn't actually run the startup code after restart.  Fixed patch attached (updated against 2.7 trunk).  Also added some doc updates.  Too lazy to produce a 3.2 version now.

[Apology to Mitchell: I removed most of your comments explaining the change and attributing it to you.  Nothing personal, just that's we have version control to store that info.]

Open questions / doubts:

* I described it in Lib/idlelib/NEWS.txt - correct?

* There is much duplication between the Doc/library/idle.rst, the command-line help string in PyShell.py and the option parsing code.  Maybe it should be rewritten with optparse?  [Doesn't block this patch.]

* There is much duplication between begin()/start_subprocess() and restart_subprocess().  These pieces of the code have a history of being fragile, and having subtle differences between them is a bad idea :-(  I didn't dare refactor them as I can't test such changes widely enough, so the startup call is duplicated.

* When a script is being run, should the startup file run before or after it (or at all)?  Currently it runs before the script, which is good because it can e.g. set the excepthook, and bad because it's different from running in a clean Python.   (Python doesn't run PYTHONSTARTUP at all when running a script, even in -i mode.)
Opinions?  Anyway, it's hard to implement otherwise with currect runcode().

[Unrelated to the patch but bothering me: it seems that runcode() sometimes restart the shell and sometimes not, and is used in both capacities?!  This is very confusing.  Or am I just reading it wrong?]
msg220123 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-09 21:45
This is at least 2 issues: startup and restart. I closed #8378 as a partial duplicate of the startup issue.

For startup, I reject the idea of changing the default and the meaning of -s. First, it would break the general back-compatibility policy and possibly break scripts of people who read the doc and proceeded accordingly. Second, while I generally prefer Idle to match the console interpreter, there is an important difference in having tkinter and idlelib modules involved. A startup script that works fine for the console could create subtle bugs in Idle. I suspect that whoever chose the current default had some thought like this. To put this a different way, running idle is similar to running 'python -i idle' and python does not run startup files with -i. Third, this change shuffles responsibilities around without any net gain that I see.

#5594 suggests adding startup options to the configuration file and dialog. I like this better and consider it possible.

For restart, the result of Restart Shell Cntl-F6 should be the same as an initial start (without running a file from the editor). On the other hand, I agree with Beni's concern about matching python -i when running editor files.

I also agree with Beni that the run... functions should be reviewed for possible refactoring, and, sadly, that testing is difficult. We would need a test script that documents both current and desired behavior and people to run it (by hand and eye) on Windows, Linux, and Mac.
msg243541 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-05-18 21:50
Related issue #22893 is about __future__ statements in startup code having effect on future interactive input in the same way as it does with Python itself. I think a pure Shell start/restart (cntl-F6) should be handled separately from a restart that is a side-effect of running an editor file.  There is a separate proposal to specify an individual file's startup condition (sys.args + STARTUP file).  For Shell restart, a possible reason might be to get rid of the effect of a STARTUP file.  Since ^F6 is rarely used (I think), asking whether to include the STARTUP might not be too intrusive.

I think default behaviors should follow Python, though we can add more.  On the other hand, Python has startup options not currently available with Idle.
msg247622 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-29 20:40
Re my comment about handling Shell restarts differently for Shell restart cntlF6 and Run module F5: Python only runs "PYTHONSTARTUP" for interactive move.  From the manual: "If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode."  When -s is passed, Idle opens Shell for sure and executes the file there.
msg247623 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-29 20:50
A new patch is needed to optionally rerun startup stuff (including future imports, see #22893) with ^F6 restarts. I think a combined patch might better be attached to the other issue, where I did some analysis on the changes needed.
msg247629 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-29 20:59
I guess the point of automatically reading is that python does also, at least for PYTHONSTARTUP.  I don't know Idle is different.  However, the main point of this issue is about restarts.
History
Date User Action Args
2020-01-07 21:02:32terry.reedysetversions: + Python 3.9, - Python 2.7, Python 3.4, Python 3.5, Python 3.6
2015-07-29 20:59:39terry.reedysetmessages: + msg247629
2015-07-29 20:50:19terry.reedysetstage: patch review -> needs patch
messages: + msg247623
versions: + Python 3.6
2015-07-29 20:40:29terry.reedysetmessages: + msg247622
2015-05-18 21:50:01terry.reedysetmessages: + msg243541
2014-10-02 20:24:22terry.reedysettitle: Enhance 2.7 IDLE to exec IDLESTARTUP/PYTHONSTARTUP on restart -> IDLE: exec IDLESTARTUP/PYTHONSTARTUP on restart
2014-06-09 21:45:01terry.reedysetversions: + Python 3.4, Python 3.5, - Python 2.6, Python 3.0, Python 3.1
nosy: + terry.reedy

messages: + msg220123

assignee: kbk ->
stage: patch review
2014-06-09 21:08:04terry.reedylinkissue8378 superseder
2012-03-26 19:35:21asvetlovsetnosy: + asvetlov
2010-03-16 20:15:09cbensetfiles: + startup-2.7.diff
nosy: + cben
messages: + msg101183

2009-03-09 19:22:22gpolosetassignee: kbk

messages: + msg83399
nosy: + gpolo, kbk
2009-03-09 19:21:38gpololinkissue5234 superseder
2009-03-09 14:45:28MLModelsetfiles: + PyShell-3.1.diff

messages: + msg83386
versions: + Python 2.6, Python 3.0, Python 3.1
2009-02-12 22:34:41MLModelcreate