Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The standard streams' method isatty() should return True. #486

Closed
real-yfprojects opened this issue May 28, 2021 · 7 comments
Closed

The standard streams' method isatty() should return True. #486

real-yfprojects opened this issue May 28, 2021 · 7 comments

Comments

@real-yfprojects
Copy link

real-yfprojects commented May 28, 2021

Current behaviour:

>>> import sys
>>> sys.stdout.isatty()
False

In my opinion this should return True.

A stream's method isatty should

Return whether this is an 'interactive' stream.

I think that means whether it is an interactive console.

This is especially important when working with colorama. This python module for terminal colouring checks this method's return value to decide whether to strip ANSI codes or not.
In the current state the qtconsole lacks colorama support.

It seems like the standard output and error streams are of type ipykernel.iostream.OutStream in the qtconsole. The issue might actually lie there.
I think this class directly inherits isatty() from io.TextIoBase which isn't an 'interactive' stream by default.

@real-yfprojects real-yfprojects changed the title Standard streams method isatty() should return True. The standard streams' method isatty() should return True. May 28, 2021
@wmvanvliet
Copy link
Contributor

QtConsole is not a full terminal (TTY emulator), and doesn't support all ANSI codes. Then again, it certainly is an interactive stream.

@ccordoba12
Copy link
Collaborator

@real-yfprojects, thanks for reporting. Please open this issue in the ipykernel repo because we can't solve it here and a change as the one you're suggesting will also affect the Jupyter notebook and JupyterLab.

https://github.com/ipython/ipykernel/

@real-yfprojects
Copy link
Author

real-yfprojects commented Jun 1, 2021

we can't solve it here

@ccordoba12
Why can't you subclass ipykernel.iostream.OutStream and override the isatty() method?

@ccordoba12
Copy link
Collaborator

Qtconsole is only a frontend for the kernel, so it doesn't directly handle anything related to it.

But if you think you can easily subclass OutStream here and override isatty(), please submit a PR for it.

@peendebak
Copy link

@ccordoba12 @wmvanvliet The isatty method is a bit all or nothing, which is not perfect for situations like this (e.g. qtconsole not being a full tty, but supporting much of the "common" functionality).

For ipykernel there is now an option to set the value of isatty ipython/ipykernel#683. How can we use that to provide color support in spyder? I looked in this repo where the ipykernel.iostream.OutStream is created, but could not find it.
And since this package is used by other packages besides spyder, should we make it optional here and set the option from spyder?

@ccordoba12
Copy link
Collaborator

@peendebak, you need to pass a different OutStream class to the kernel app, as shown here:

https://github.com/ipython/ipykernel/blob/079f072a8e90422dc74270992589c56ad9f7f9f2/ipykernel/kernelapp.py#L161-L162

That means that for this to work it's required to subclass IPKernelApp and the kernel itself.

Fortunately, that's what we do in Spyder already with our spyder-kernels package. Please open an issue there so I can give you detailed instructions on how you can achieve this.

@eendebakpt
Copy link

@ccordoba12 I created spyder-ide/spyder-kernels#302. Could you give instructions there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants