ipython / ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
https://ipython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
16.29k stars 4.44k forks source link

Prompt display doesn't change with current working directory [ipython console] #2614

Open louking opened 11 years ago

louking commented 11 years ago

I am having trouble getting the prompt to show the current working directory in iPython 0.13.1 running in windows. As you can see below, after changing the current working directory to 'C:\Users\Lou\Documents\Lou's Software\projects\loutilities', the \Y3 only shows 'C:/Users/Lou'. The same behavior is seen with \w and {cwd} configurations.

This was discussed with Thomas K at stackoverflow, who investigated and indicated a bug report was needed.

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-9572.json

C:/Users/Lou> cd "C:\Users\Lou\Documents\Lou's Software\projects\loutilities"
C:\Users\Lou\Documents\Lou's Software\projects\loutilities

C:/Users/Lou> config PromptManager
PromptManager options
-------------------
PromptManager.color_scheme=<Unicode>
    Current: u'Linux'
PromptManager.in2_template=<Unicode>
    Current: u'   .\\D.: '
    Continuation prompt.
PromptManager.in_template=<Unicode>
    Current: u'\\Y3> '
    Input prompt.  '\#' will be transformed to the prompt number
PromptManager.justify=<Bool>
    Current: False
    If True (default), each prompt will be right-aligned with the preceding one.
PromptManager.out_template=<Unicode>
    Current: u'Out[\\#]: '
    Output prompt. '\#' will be transformed to the prompt number

Thomas K asked for output of os.getcwdu(). I used config command to change the prompt (I'd gone back to In [#n] prompt), and In [#n] prompt remained. A clue?

In [1]: config PromptManager.in_template='\\Y3'

In [3]: config PromptManager
PromptManager options
-------------------
PromptManager.color_scheme=<Unicode>
    Current: u'Linux'
PromptManager.in2_template=<Unicode>
    Current: u'   .\\D.: '
    Continuation prompt.
PromptManager.in_template=<Unicode>
    Current: u'\\Y3'
    Input prompt.  '\#' will be transformed to the prompt number
PromptManager.justify=<Bool>
    Current: True
    If True (default), each prompt will be right-aligned with the preceding one.
PromptManager.out_template=<Unicode>
    Current: u'Out[\\#]: '
    Output prompt. '\#' will be transformed to the prompt number

In [4]: import os

In [5]: os.getcwdu()
Out[5]: u'C:\\Users\\Lou'

In [6]: cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

In [7]: os.getcwdu()
Out[7]: u"C:\\Users\\Lou\\Documents\\Lou's Software\\projects\\weather"

And the original test duplicated...

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:/Users/Lou> import os

C:/Users/Lou> os.getcwdu()
      Out[3]: u"C:\\Users\\Lou\\Documents\\Lou's Software\\projects\\weather"

C:/Users/Lou> config PromptManager
PromptManager options
-------------------
PromptManager.color_scheme=<Unicode>
    Current: u'Linux'
PromptManager.in2_template=<Unicode>
    Current: u'   .\\D.: '
    Continuation prompt.
PromptManager.in_template=<Unicode>
    Current: u'\\Y3> '
    Input prompt.  '\#' will be transformed to the prompt number
PromptManager.justify=<Bool>
    Current: True
    If True (default), each prompt will be right-aligned with the preceding one.
PromptManager.out_template=<Unicode>
    Current: u'Out[\\#]: '
    Output prompt. '\#' will be transformed to the prompt number

11/21/12 - Thomas K asked to check get_ipython().prompt_manager.templates:

C:/Users/Lou> pwd
      Out[1]: u'C:\\Users\\Lou'

C:/Users/Lou> get_ipython().prompt_manager.templates
      Out[2]:
{'in': u'{cwd_y[3]}> ',
 'in2': u'   .{dots}.: ',
 'out': u'Out[{color.number}{count}{color.prompt}]: '}

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:/Users/Lou> pwd
      Out[4]: u"C:\\Users\\Lou\\Documents\\Lou's Software\\projects\\weather"

C:/Users/Lou> get_ipython().prompt_manager.templates
      Out[5]:
{'in': u'{cwd_y[3]}> ',
 'in2': u'   .{dots}.: ',
 'out': u'Out[{color.number}{count}{color.prompt}]: '}
Carreau commented 11 years ago
In [5]: os.getcwdu()
Out[5]: u'C:\\Users\\Lou'

This is already weird. Does it do the same in pure python ?

Investigating for why it does not update prompt.

Link to SO discussion : http://stackoverflow.com/questions/13387832/ipython-prompt-confusion

louking commented 11 years ago

Sorry, forgot to put the link to SO in.

I don't understand the question about pure python. The prompt rendering is from ipython, right?

Carreau commented 11 years ago

ah, I missed (bookmark:weather) I though it was jumping from C:\\Users\\Lou to C:\Users\Lou\Documents\Lou's Software\projects\weather and that there might have been a issue with the ' in Lou's Software

Never mind the question.

takluyver commented 11 years ago

More things to try:

from IPython.core import prompts
prompts.HOME
prompts.cwd_filt(3)
louking commented 11 years ago
C:/Users/Lou> from IPython.core import prompts

C:/Users/Lou> prompts.HOME
      Out[2]: u'\\\\\\:::::ZZZZZ,,,~~~'

C:/Users/Lou> prompts.cwd_filt(3)
      Out[3]: u'C:\\Users\\Lou'

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:/Users/Lou> prompts.HOME
      Out[6]: u'\\\\\\:::::ZZZZZ,,,~~~'

C:/Users/Lou> prompts.cwd_filt(3)
      Out[7]: u"Lou's Software\\projects\\weather"
takluyver commented 11 years ago

Sorry, \Y becomes cwd_filt2 - can you try the last bit with prompts.cwd_filt2(3)? Thanks.

louking commented 11 years ago
C:/Users/Lou> pwd
      Out[1]: u'C:\\Users\\Lou'

C:/Users/Lou> from IPython.core import prompts

C:/Users/Lou> prompts.HOME
      Out[3]: u'\\\\\\:::::ZZZZZ,,,~~~'

C:/Users/Lou> prompts.cwd_filt2(3)
      Out[4]: u'C:/Users/Lou'

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:/Users/Lou> prompts.HOME
      Out[6]: u'\\\\\\:::::ZZZZZ,,,~~~'

C:/Users/Lou> prompts.cwd_filt2(3)
      Out[7]: u"C:Lou's Software/projects/weather"
takluyver commented 11 years ago

OK, cwd_filt2 appears to be working as it should. The next thing to test is LazyEvaluate. Can you try this:

from IPython.core import prompts
y3le = prompts.LazyEvaluate(prompts.cwd_filt2, 3)
str(y3le), format(y3le)
cd weather
str(y3le), format(y3le)
louking commented 11 years ago
C:/Users/Lou> from IPython.core import prompts

C:/Users/Lou> y3le = prompts.LazyEvaluate(prompts.cwd_filt2, 3)

C:/Users/Lou> str(y3le), format(y3le)
      Out[3]: ('C:/Users/Lou', u'C:/Users/Lou')

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:/Users/Lou> str(y3le), format(y3le)
      Out[5]: ("C:Lou's Software/projects/weather", u"C:Lou's Software/projects/weather")
takluyver commented 11 years ago

Thanks, so that's working. What about get_ipython().prompt_manager.render('in')?

louking commented 11 years ago

Hmm

C:/Users/Lou> get_ipython().prompt_manager.render('in')
      Out[6]: u"\x01\x1b[0;32m\x02C:Lou's Software/projects/weather> \x01\x1b[0m\x02"
takluyver commented 11 years ago

That too is doing what I'd expect (the garbage characters are the control characters for the colour).

takluyver commented 11 years ago

Are you doing this in the terminal, or in the Qt console?

louking commented 11 years ago

I start ipython with

C:\Python27\Scripts\ipython.exe console

So is that the Qt console?

Carreau commented 11 years ago

No, this is the ZMQ console. Is is a 2 process terminal. (and I can reproduce the bug on OS X with zmqconsole)

Even if it look the same, you can try C:\Python27\Scripts\ipython.exe alone to have classical IPython.

or C:\Python27\Scripts\ipython.exe qtconsle to get the qtconsole (but you might have missing dependencies)

louking commented 11 years ago

Ah, using

C:\Python27\Scripts\ipython.exe

a) it comes up faster, and, b) I get

C:/Users/Lou> cd weather
(bookmark:weather) -> C:\Users\Lou\Documents\Lou's Software\projects\weather
C:\Users\Lou\Documents\Lou's Software\projects\weather

C:Lou's Software/projects/weather>

So I'm good.

I had recently upgraded from ipython 0.10.x, and thought I needed some parameter to replace the -p sh (or whatever that option was).

Thanks for the investigation!

takluyver commented 11 years ago

Ah, that makes sense, then. Yes, there's not much reason to use 'console' for normal use. I've retitled the issue accordingly.

There isn't really a replacement yet for the sh profile in earlier versions, but some of the features are now integrated into IPython by default.

takluyver commented 11 years ago

Hi Lou,

I mostly work on Linux, where I use Geany. I don't think it's exceptional, but it does what I need it to. When I've used Windows, I've quite liked PyScripter, so you could give that a try. I don't normally use an integrated debugger, though - I just have IPython in another window.

For future reference, the best place to ask questions like that is on the ipython-user mailing list.

louking commented 11 years ago

thanks again

On Sat, Nov 24, 2012 at 1:04 PM, Thomas Kluyver notifications@github.comwrote:

Hi Lou,

I mostly work on Linux, where I use Geany. I don't think it's exceptional, but it does what I need it to. When I've used Windows, I've quite liked PyScripter, so you could give that a try. I don't normally use an integrated debugger, though - I just have IPython in another window.

For future reference, the best place to ask questions like that is on the ipython-user mailing list http://mail.scipy.org/mailman/listinfo/ipython-user.

— Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/2614#issuecomment-10681474.