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 doesn't recognize resetting sys.ps1.
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: out of date
Dependencies: 16123 Superseder:
Assigned To: terry.reedy Nosy List: Ramchandra Apte, alex.rodas, philwebster, roger.serwy, terry.reedy, zach.ware
Priority: normal Keywords: patch

Created on 2011-12-23 11:45 by Ramchandra Apte, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue13657.patch philwebster, 2013-05-18 03:40 review
Messages (17)
msg150154 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2011-12-23 11:45
IDLE doesn't support nor set sys.ps1 and sys.ps2.
>>> sys.ps1
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    sys.ps1
AttributeError: 'module' object has no attribute 'ps1'
>>> sys.ps1 = "Test " #The next prompt doesn't start with Test
>>>
msg150197 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2011-12-23 20:13
This would make the IDLE shell interface more consistent with the original interpreter. 

Presently, the ">>> " prompt is faked by "showprompt" in PyShell.py. It relies on "sys" from the IDLE gui process and not from the "sys" in the subprocess, so mimicking the changed prompt would require querying the subprocess for its sys.ps1 and sys.ps2. The "enter_callback" method will need modification to remove sys.ps2 from the text buffer before execution. Also, EditorWindow.py has code for handling sys.ps1 in "smart_backspace_event" and "newline_and_indent_event". 

If anything, this shell-specific, prompt-handling code needs some refactoring as it should only be in PyShell.py, not in EditorWindow.py.
Issue13039 is a result of prompt code side-effects in EditorWindow.py.
msg150207 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-12-24 04:03
> so mimicking the changed prompt would require querying the subprocess for its sys.ps1 and sys.ps2.

Is that sensibly possible? Any line of code can change those, so IDLE would have to do the equivalent of
idle.ps1,idle.ps2 = sys.ps1, sys.ps2 before every new ps1 statement prompt. A configuration option might work better.
  
I would rather remove the prompts from the entry window itself, and use 4 char indents instead of 8, so that cutting does not pick up the prompts.  IDLE does not have to exactly imitate the Command Window interface. It could also give the user a choice.
msg150210 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2011-12-24 04:36
> Is that sensibly possible? Any line of code can change those, so IDLE would have to do the equivalent of idle.ps1,idle.ps2 = sys.ps1, sys.ps2 before every new ps1 statement prompt.

It may be possible if the code gets refactored such that the subprocess handles the prompt and has stdin/stdout/stderr through RPCProxy treat the PyShell text widget as a dumb terminal.

> I would rather remove the prompts from the entry window itself, and use 4 char indents instead of 8, so that cutting does not pick up the prompts.  IDLE does not have to exactly imitate the Command Window interface. It could also give the user a choice.

This is #11838 and #1178.
msg156652 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012-03-23 12:27
What is the status of this bug?
msg156655 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-03-23 13:08
This is an issue, not a bug, and the status is as it was: unclear just what to do; would require some major work.
msg165165 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-07-10 05:26
For reference, IDLE-DEV is discussing the prompt: http://mail.python.org/pipermail/idle-dev/2012-June/003129.html
msg178557 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012-12-30 07:57
Buump...
msg189196 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2013-05-14 03:42
Adding 16123 as a dependency. Resolving sys.ps1 and sys.ps2 will likely be simpler when only considering one execution mode.
msg189493 - (view) Author: Phil Webster (philwebster) * Date: 2013-05-18 03:40
I've attached a patch that attempts to get sys.ps1 for the prompt. Unfortunately it prints out blue because it is treated as output from running print(sys.ps1) as if the user had typed it in. Now that I have a better understanding of the issue, I may be able to work on the subprocess handling that Roger suggested.
msg189626 - (view) Author: Alejandro Rodas (alex.rodas) * Date: 2013-05-19 22:05
I have reviewed the patch, and apart from setting the promt, I think it would be possible to set it at the beginning with the same approach:

    def getprompt(self):
        self.interp.runcommand(textwrap.dedent("""\
        try:
            print(sys.ps1, end="")
        except:
            import sys
            sys.ps1, sys.ps2 = ">>> ", "... "
            print(sys.ps1, end="")"""))

What I don't know is why ps1 and ps2 are the only attributes that are missing in the sys module within the ModifiedInterpreter. When I try InteractiveInterpreter in the original interpreter, it shows the 79 attributes that sys has originally.
msg209815 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-01-31 19:32
Robin Zimmermann on docs@ raised this issue again.  Is this likely to be fixed soon, or would it be good to document this limitation of IDLE in the tutorial (since the tutorial is the most likely place for someone to be confused by this)?
msg209845 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-01-31 23:40
If there is a discussion of sys.ps1 and sys.ps2 in the tutorial, then add a note that they are not supported in Idle. The only quick action on this issue would be to reject and close. I am still opposed to the proposal as presented, for reasons stated in my first message.

To expand a bit on what I said before: the prompts 'work', at least for the Windows console because
a) it is limited to fixed-pitch fonts, so that '>>>' and '...' have the same width;
b) its selection box is always a rectangle, so if one starts with the first character of a line and move down and right, the prompts are excluded.

I do not know what is true for *nix consoles, but neither is true for Idle. I would only tolerate the added nuisance of a secondary prompt if it were made to take up the same space (pixels) as the primary prompt so that indents could be 4 spaces instead of 8 space tabs.

If we were to get the prompts from the remote process, they should be sent as part of every normal response output instead of being a separate enquiry.

Part of my opposition to custom prompts is that the standard prompts, even though a nuisance, are instantly recognizable in messages. The can also be recognized and removed by code, as when pasting. See #1178, which I hope to act on soon. Neither is true of custom prompts.
msg228295 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-10-03 02:34
I explained somewhere else that a secondary prompt would be wrong for Idle since the primary prompt  asks for a *statement*, not just the first line of the statement.  The advantage is being able to edit and recall entire statements, not just one line.  This is in addition to the absurdity of entering and then removing secondary prompts from the text buffer.

I still intend to at least add an option to move the prompt(s) to a sidebar and use 4 space indents.  At that point, it would not too much matter if '>>> ' were, as an option, followed by '... ' instead of '    ', although it would not look so good with a proportional font.
msg304862 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-24 06:23
#31858 fixes pyshell and editor so that a user setting of sys.ps1 in a startup file continues to be used after turning debugger on, instead of erased. I consider this to be an IDLE documentation issue, to add something in the introduction.  Discussing IDLE differences in the tutorial might need more discussion than just here.
msg305145 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-28 01:38
The part about startup files in my last message is probably wrong.  If one starts IDLE by 'import idlelib.idle' after setting 'sys.ps1 = 'me ', then the setting is recognized.  However, a startup file that runs in the user process will not affect sys.ps1 in the IDLE process.  We could add a command line option -p "prompt", but I don't see this as sufficiently important.

At least some shells and consoles recognize special characters in a prompt string to create the prompt.  For instance, the default setting on Windows is "$P$G", which I presume stands for 'working directory path' and 'greater than symbol', with a result such as "F:/dev/3x>".  (I have no idea where this is documented.)  Python and IDLE will print the literal string instead.  Custom prompts therefore seem like an advanced feature, not one aimed at beginners.
msg393442 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-05-11 05:05
Starting with 3.10.0b1, Shell is being reworked in ways that make this issue, as formulated, out of date.  Solving the indent problems means that prompt must be removed from the first line of interactive input.  #37892.  The initial solution is to put >>> and ... prompts in a sidebar.  #37903.  The rules out customization.  A planned alternate solution is to put the prompt on a line by itself above interactive input.  A followup issue could be customizing the isolated prompt by a setting in the options dialog.
History
Date User Action Args
2022-04-11 14:57:25adminsetgithub: 57866
2021-05-11 05:05:51terry.reedysetstatus: open -> closed
resolution: out of date
messages: + msg393442

stage: needs patch -> resolved
2017-10-28 01:38:37terry.reedysetmessages: + msg305145
title: IDLE doesn't support sys.ps1 and sys.ps2. -> IDLE doesn't recognize resetting sys.ps1.
2017-10-24 06:23:50terry.reedysetmessages: + msg304862
2017-06-30 00:53:25terry.reedysetassignee: terry.reedy
versions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.4, Python 3.5
2014-10-03 02:34:44terry.reedysetmessages: + msg228295
versions: + Python 3.5, - Python 3.3
2014-01-31 23:40:30terry.reedysetmessages: + msg209845
2014-01-31 19:32:31zach.waresetnosy: + zach.ware
messages: + msg209815
2013-05-19 22:05:19alex.rodassetnosy: + alex.rodas
messages: + msg189626
2013-05-18 03:40:06philwebstersetfiles: + issue13657.patch

nosy: + philwebster
messages: + msg189493

keywords: + patch
2013-05-14 03:42:55roger.serwysetversions: + Python 2.7, Python 3.4
nosy: + roger.serwy

messages: + msg189196

dependencies: + IDLE - deprecate running without a subprocess
2012-12-31 00:15:43roger.serwysetnosy: - roger.serwy
2012-12-30 07:57:12Ramchandra Aptesetmessages: + msg178557
2012-07-16 00:34:32roger.serwylinkissue7957 superseder
2012-07-10 05:26:58roger.serwysetmessages: + msg165165
2012-03-23 13:11:07terry.reedysetstage: needs patch
versions: + Python 3.3
2012-03-23 13:08:28terry.reedysetmessages: + msg156655
2012-03-23 12:27:00Ramchandra Aptesetmessages: + msg156652
2011-12-24 04:36:03roger.serwysetmessages: + msg150210
2011-12-24 04:03:38terry.reedysetnosy: + terry.reedy
messages: + msg150207
2011-12-23 20:13:30roger.serwysetnosy: + roger.serwy
messages: + msg150197
2011-12-23 11:45:42Ramchandra Aptecreate