This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Idle: Print filename when running a file from editor
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Adnan.Umer, benjamin.peterson, larry, python-dev, rhettinger, terry.reedy
Priority: normal Keywords: patch

Created on 2014-04-09 21:24 by terry.reedy, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
PyShell.py Adnan.Umer, 2014-04-10 15:13
@restart.diff terry.reedy, 2015-08-27 21:31 one line change review
Messages (25)
msg215846 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-04-09 21:24
Upon restarting the user process, Idle prints a separator bar in the shell:
====================================== RESTART=====================....
When restart is due to running a file with F5, print "RUN filename" instead of "RESTART". Idea from Adnan Umer, pydev list. For Shell / Restart Shell Cntl+F6, maybe change to "RESTART Shell" (my additional idea).
msg215888 - (view) Author: Adnan Umer (Adnan.Umer) * Date: 2014-04-10 15:13
Method: runcode
Class: ModifiedInterpreter
Line: 752

Added
if code.co_filename[0] != '<':
            self.tkconsole.write('Executing ' + code.co_filename + '\n')

To print file path that is executed
msg216277 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-04-15 05:29
I have not tried your patch yet, but the relevant code seems to be

class ModifiedInterpreter(InteractiveInterpreter):
    def runcode(self, code):
        if code.co_filename[0] != '<': ## your patch
            self.tkconsole.write('Executing ' + code.co_filename + '\n')
        if self.tkconsole.executing:
            self.interp.restart_subprocess()

     def restart_subprocess(self, with_cwd=False):
        if was_executing:
            console.write('\n')
            console.showprompt()
        halfbar = ((int(console.width) - 16) // 2) * '='
        console.write(halfbar + ' RESTART ' + halfbar)

The 2 problems I see with the patch are that 1) it prints prematurely and 2) it does not replace RESTART. Both should be solved by passing the title string to restart_process as a new 'title' arg (title=' RESTART ').

The halfbar expression should use len(title). I believe 16 is 9 (len(' RESTART ')) + 4 (len('>>> ')) + 3 (console.width (80) - 77). So
        halfbar = ((int(console.width) - len(title) - 7) // 2) * '='

I think the bar would be better without a prompt before it. If console.showprompt() is deleted, 7 becomes 3.
I will code this later.
msg216497 - (view) Author: Adnan Umer (Adnan.Umer) * Date: 2014-04-16 16:50
I tried to replace RESTART by doing these little changing

# PyShell.Py
class ModifiedInterpreter(InteractiveInterpreter):
    def restart_subprocess(self, with_cwd=False, with_msg=True):
        ...
        if with_msg:
            halfbar = ((int(console.width) - 16) // 2) * '='
            console.write(halfbar + ' RESTART ' + halfbar)

    def runcode(self, code):
        with_msg = True
        if code.co_filename[0] != '<':
            self.tkconsole.write('Executing ' + code.co_filename + '\n')
            with_msg = False
        
        if self.tkconsole.executing:
            self.interp.restart_subprocess(with_msg)

# ScriptBinding.Py
class ScriptBinding:
    def _run_module_event(self, event):
        filename = self.getfilename()
        if not filename:
            return 'break'
        code = self.checksyntax(filename)
        if not code:
            return 'break'
        if not self.tabnanny(filename):
            return 'break'
        interp = self.shell.interp
        if PyShell.use_subprocess:
            interp.restart_subprocess(with_cwd=False, with_msg=False)

This works fine and replaces RESTART with Execute <filename> when file is executed in Python Shell.

Also instead of this

halfbar = ((int(console.width) - 16) // 2) * '='
console.write(halfbar + ' RESTART ' + halfbar)

my recomemdation is:
console.write('[SHELL RESTART]')
msg216525 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-04-16 17:57
I took another look and tried the patch and discovered that my comments are partly wrong because restart_shell is called before runcode when runcode is use to run a file. (I am not sure how it is called otherwise with self.tkconsole.executing == True.) This happens in ScriptBinding.ScriptBinding._run_module_event and that is where filename could be added to the restart_shell call.

The rest of my comment was about not printing fake prompts that the user can never respond to. In particular, Run F5 is like python -i, and for that the console interpreter does not print a prompt until it is done running the script and ready for user input.

C:\Programs\Python34>python -i tem.py
start
stop
>>>
msg247795 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-01 02:36
New changeset 20a8e5dccf66 by Terry Jan Reedy in branch '2.7':
Issue #21192: Idle Editor. When a file is run, put its name in the restart bar.
https://hg.python.org/cpython/rev/20a8e5dccf66

New changeset 2ae12789dcb8 by Terry Jan Reedy in branch '3.4':
Issue #21192: Idle Editor. When a file is run, put its name in the restart bar.
https://hg.python.org/cpython/rev/2ae12789dcb8
msg247796 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-01 02:39
This is how restarts look now.  Thanks for the initial idea and patch.

>>>
====================== RUN C:\Programs\Python34\tem.py =================
xxxx
>>> 
=============================== RESTART Shell =========================
>>>
msg247825 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-01 20:32
New changeset edf9bfe36ad0 by Terry Jan Reedy in branch '2.7':
Issue #21192: acks for 2.7
https://hg.python.org/cpython/rev/edf9bfe36ad0
msg248864 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-08-19 23:20
I've found this to be a serious usability regression and think it should be reverted right-away.  It makes IDLE unsuitable for evening showing turtle demos to kids.  For adults in my classes, it was also confusing because unlike the old restart-bar it fails to make a clean distinction between sessions and making it clear that old variable definitions have be forgotten.  The issue is even more acute because cmd-p can cycle through statements in previous sessions.
msg248876 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-20 05:59
How about 'RESTART: Shell' and 'RESTART: <name of file>' to make it clear that old definitions are forgotten in both cases while new definitions are added in the second case.

I do not understand the comment about turtledemo as it runs separately from Idle.
msg249263 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-27 21:31
Now that Larry Hastings has posted directions for handling changes pulled into 3.5.0, I will soon commit the attached, or something close, and add a pull request.
msg249590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-03 02:09
New changeset 69ea73015132 by Terry Jan Reedy in branch '2.7':
Issue #21192: Change 'RUN' back to 'RESTART' when running editor file.
https://hg.python.org/cpython/rev/69ea73015132

New changeset 130a3edcac1d by Terry Jan Reedy in branch '3.4':
Issue #21192: Change 'RUN' back to 'RESTART' when running editor file.
https://hg.python.org/cpython/rev/130a3edcac1d
msg249592 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-03 02:21
Larry, please pull @restart.diff into 3.5.0.  I have already applied it to 2.7, 3.4, 3.5.1, and 3.6, so I will null merge from 3.5.0 into 3.5.1 and 3.6.

Reason.  Aside from Raymond's request above, I was reminded about a week ago that a) when Idle runs in one process, running a file from the editor does *not* cause a restart, and b) we might want to add the option to not restart even when running with two processes.  So I agree with Raymond that Idle should say RESTART (or the equivalent) when restarting the execution process and not say it when not, and that 3.5.0 should be consistent with other releases, and not make a change that is reverted in 3.5.1.
msg249619 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-03 08:31
Terry, if you want this pulled in to Python 3.5.0, you'll need to create a pull request on Bitbucket.  Instructions are here:

https://mail.python.org/pipermail/python-dev/2015-August/141167.html

and here:

https://mail.python.org/pipermail/python-dev/2015-August/141365.html
msg249686 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-03 20:25
On the other hand, I do not hold with marking a minor cosmetic change like this as "release blocker".  I'm willing to accept the change, given PEP 434, but I'm not going to delay any releases for it.
msg249692 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-03 21:50
Sorry, my memory was that I was supposed to that as a signal, but maybe that was with a different RM.
msg249704 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 01:35
https://bitbucket.org/larry/cpython350/pull-requests/12/issue-21192-change-run-back-to-restart/diff
msg249705 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 01:54
On 9/3/2015 4:31 AM, Larry Hastings wrote:

> Terry, if you want this pulled in to Python 3.5.0, you'll need to create a pull request on Bitbucket.  Instructions are here:
>
> https://mail.python.org/pipermail/python-dev/2015-August/141167.html

I don't remember seeing this, but done now.

> and here:
>
> https://mail.python.org/pipermail/python-dev/2015-August/141365.html

I did get this. This step

   4: Pull from the 3.5.0 repo into your "cpython351-merge" directory.
          % hg pull ssh://hg@bitbucket.org/larry/cpython350

gives me a

Putty Fatal Error: Disconnected: No supported authentication methods 
available (server sent publickey).

I presume it would require a key on deposit, as with python.org.  It 
seems however that
     hg pull https://terryjreedy@bitbucket.org/larry/cpython350
might work in that it searched for changes and found none (as expected).

There is something odd about the size of your clone.  My cpython clone 
is 928 MB on disk with 30300 files, while the clone of my fork of your 
repository is 1.59 GB for 14500 files.
msg249714 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-04 05:07
Pull request accepted, please forward-merge.  Thanks!

> There is something odd about the size of your clone.  My cpython
> clone is 928 MB on disk with 30300 files, while the clone of my fork
> of your repository is 1.59 GB for 14500 files.

I have no idea why.  All I can tell you is, I made my cpython350 directory by forking the official Bitbucket mirror of the cpython tree ( https://bitbucket.org/mirror/cpython ) and updating it.

If you're on a UNIX-y filesystem (something with hardlinks), the "relink" extension for Mercurial can help cut down on the disk space consumed.
msg249733 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 07:39
This was pull #12. Am I correct in thinking that all the merges Serhiy did after for pull #13 included the null merge for this?
msg249734 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-04 07:49
The pull requests are numbered by creation order, not by merge order.

Normally I'd expect that yes, Serhiy's merge would include yours.  But it didn't work out that way.  If you look at the changeset graph:

https://bitbucket.org/larry/cpython350/commits/all

Serhiy merged his revision (2b6ce7e), not my merge commit afterwards (07e04c3) which includes your change.  So your change still needs to be forward-merged.

Please pull and merge the current head (07e04c3), thanks!
msg249736 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 08:05
Since your merge contains the changes that Serhiy already merged, I expect that there will be some conflicts.  If so, the only thing I would know to do is revert and make mine and his null merges. If that is correct, will do. Making merge clone now.
msg249737 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-04 08:19
New changeset 09cd7d57b080 by Terry Jan Reedy in branch '3.5':
Issue #21192: Change 'RUN' back to 'RESTART' when running editor file.
https://hg.python.org/cpython/rev/09cd7d57b080
msg249739 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-09-04 08:21
There won't be conflicts with Serhiy's merge--just the opposite.  His pull request was merged first, so it's perfect that he did his forward merge first.  He's already resolved any conflicts with his merge, and so when you merge you'll only have to worry about your own changes.

Just merge the current head (07e04c3), it'll be fine, honest!
msg249740 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-04 08:22
I was wrong, no conflicts.
History
Date User Action Args
2022-04-11 14:58:01adminsetgithub: 65391
2015-09-04 08:22:53terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg249740
2015-09-04 08:21:52larrysetmessages: + msg249739
2015-09-04 08:19:12python-devsetmessages: + msg249737
2015-09-04 08:05:53terry.reedysetmessages: + msg249736
2015-09-04 07:49:17larrysetmessages: + msg249734
2015-09-04 07:39:16terry.reedysetmessages: + msg249733
2015-09-04 05:07:38larrysetmessages: + msg249714
2015-09-04 01:54:05terry.reedysetmessages: + msg249705
2015-09-04 01:35:01terry.reedysetmessages: + msg249704
2015-09-03 21:50:01terry.reedysetmessages: + msg249692
2015-09-03 20:25:46larrysetpriority: release blocker -> normal

messages: + msg249686
2015-09-03 08:31:06larrysetmessages: + msg249619
2015-09-03 02:21:30terry.reedysetpriority: normal -> release blocker
nosy: + larry, benjamin.peterson
messages: + msg249592

2015-09-03 02:09:26python-devsetmessages: + msg249590
2015-08-27 21:31:35terry.reedysetfiles: + @restart.diff
keywords: + patch
messages: + msg249263
2015-08-20 05:59:21terry.reedysetmessages: + msg248876
2015-08-19 23:20:06rhettingersetstatus: closed -> open

nosy: + rhettinger
messages: + msg248864

resolution: fixed -> (no value)
2015-08-01 20:32:57python-devsetmessages: + msg247825
2015-08-01 02:39:14terry.reedysetstatus: open -> closed
versions: + Python 2.7, Python 3.5, Python 3.6
messages: + msg247796

resolution: fixed
stage: needs patch -> resolved
2015-08-01 02:36:14python-devsetnosy: + python-dev
messages: + msg247795
2014-04-16 17:57:43terry.reedysetmessages: + msg216525
2014-04-16 16:50:05Adnan.Umersetmessages: + msg216497
2014-04-15 05:29:59terry.reedysetassignee: terry.reedy
messages: + msg216277
2014-04-10 15:13:48Adnan.Umersetfiles: + PyShell.py
versions: + Python 3.4
nosy: + Adnan.Umer

messages: + msg215888
2014-04-10 04:56:34Adnan.Umersetcomponents: + IDLE
2014-04-09 21:24:46terry.reedycreate