From 891b5f6a3d23d9ea4b02be3618de8ad6c2bc02f6 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 4 Jun 2021 21:41:43 +0200 Subject: [PATCH 1/7] overload isatty to return True --- ipykernel/iostream.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index ce69334d8..9036d5dc8 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -381,6 +381,13 @@ def __init__( else: raise ValueError("echo argument must be a file like object") + def isatty(self): + """Return a bool indicating whether this is an 'interactive' stream. + + The standard ipykernel streams are assumed to be interactive. + """ + return True + def _setup_stream_redirects(self, name): pr, pw = os.pipe() fno = getattr(sys, name).fileno() From 54af64e90ac0df49628a1ee7cc240c47e539146c Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 4 Jun 2021 21:42:17 +0200 Subject: [PATCH 2/7] fix whitespace --- ipykernel/iostream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 9036d5dc8..cd74fca6f 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -383,11 +383,11 @@ def __init__( def isatty(self): """Return a bool indicating whether this is an 'interactive' stream. - + The standard ipykernel streams are assumed to be interactive. """ return True - + def _setup_stream_redirects(self, name): pr, pw = os.pipe() fno = getattr(sys, name).fileno() From 185767d2bec1d29b7ba12a65f0f9983b81342af9 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Fri, 4 Jun 2021 21:58:44 +0200 Subject: [PATCH 3/7] fix tests --- ipykernel/tests/test_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipykernel/tests/test_io.py b/ipykernel/tests/test_io.py index c0e7021af..7d425e2bd 100644 --- a/ipykernel/tests/test_io.py +++ b/ipykernel/tests/test_io.py @@ -25,7 +25,7 @@ def test_io_api(): ctx.term() assert stream.errors is None - assert not stream.isatty() + assert stream.isatty() with nt.assert_raises(io.UnsupportedOperation): stream.detach() with nt.assert_raises(io.UnsupportedOperation): From d7567b04230060c5b5cecd84fcffdb03baed57f3 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 8 Jun 2021 13:09:28 +0200 Subject: [PATCH 4/7] make isatty an option --- ipykernel/iostream.py | 10 +++++++--- ipykernel/tests/test_io.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index cd74fca6f..892ea21f0 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -320,7 +320,7 @@ def _watch_pipe_fd(self): self._exc = sys.exc_info() def __init__( - self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True + self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True, isatty=True, ): """ Parameters @@ -333,6 +333,8 @@ def __init__( the file descriptor by its number. It will spawn a watching thread, that will swap the give file descriptor for a pipe, read from the pipe, and insert this into the current Stream. + isatty: bool (default, True) + Indication of whether this stream has termimal capabilities (e.g. can handle colors) """ if pipe is not None: @@ -364,6 +366,7 @@ def __init__( self._io_loop = pub_thread.io_loop self._new_buffer() self.echo = None + self._isatty = bool(isatty) if ( watchfd @@ -384,9 +387,10 @@ def __init__( def isatty(self): """Return a bool indicating whether this is an 'interactive' stream. - The standard ipykernel streams are assumed to be interactive. + Returns: + Boolean """ - return True + return self._isatty def _setup_stream_redirects(self, name): pr, pw = os.pipe() diff --git a/ipykernel/tests/test_io.py b/ipykernel/tests/test_io.py index 7d425e2bd..014aaf9ce 100644 --- a/ipykernel/tests/test_io.py +++ b/ipykernel/tests/test_io.py @@ -17,7 +17,7 @@ def test_io_api(): thread = IOPubThread(pub) thread.start() - stream = OutStream(session, thread, 'stdout') + stream = OutStream(session, thread, 'stdout', isatty=True) # cleanup unused zmq objects before we start testing thread.stop() @@ -38,3 +38,13 @@ def test_io_api(): stream.seek(0) with nt.assert_raises(io.UnsupportedOperation): stream.tell() + +def test_io_isatty(): + session = Session() + ctx = zmq.Context() + pub = ctx.socket(zmq.PUB) + thread = IOPubThread(pub) + thread.start() + + stream = OutStream(session, thread, 'stdout', isatty=False) + assert not stream.isatty() From 05ecce6669667716020b7623e4593551947cf744 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 8 Jun 2021 20:19:44 +0200 Subject: [PATCH 5/7] change default value of isatty to False --- ipykernel/iostream.py | 4 ++-- ipykernel/tests/test_io.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index 892ea21f0..eef51aade 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -320,7 +320,7 @@ def _watch_pipe_fd(self): self._exc = sys.exc_info() def __init__( - self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True, isatty=True, + self, session, pub_thread, name, pipe=None, echo=None, *, watchfd=True, isatty=False, ): """ Parameters @@ -333,7 +333,7 @@ def __init__( the file descriptor by its number. It will spawn a watching thread, that will swap the give file descriptor for a pipe, read from the pipe, and insert this into the current Stream. - isatty: bool (default, True) + isatty: bool (default, False) Indication of whether this stream has termimal capabilities (e.g. can handle colors) """ diff --git a/ipykernel/tests/test_io.py b/ipykernel/tests/test_io.py index 014aaf9ce..7e06e343c 100644 --- a/ipykernel/tests/test_io.py +++ b/ipykernel/tests/test_io.py @@ -25,7 +25,7 @@ def test_io_api(): ctx.term() assert stream.errors is None - assert stream.isatty() + assert not stream.isatty() with nt.assert_raises(io.UnsupportedOperation): stream.detach() with nt.assert_raises(io.UnsupportedOperation): @@ -46,5 +46,5 @@ def test_io_isatty(): thread = IOPubThread(pub) thread.start() - stream = OutStream(session, thread, 'stdout', isatty=False) - assert not stream.isatty() + stream = OutStream(session, thread, 'stdout', isatty=True) + assert stream.isatty() From 5a5c7d429245f547b196e14342946ae6a6337396 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 8 Jun 2021 21:39:08 +0200 Subject: [PATCH 6/7] fix tests --- ipykernel/tests/test_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipykernel/tests/test_io.py b/ipykernel/tests/test_io.py index 7e06e343c..cf68b88ea 100644 --- a/ipykernel/tests/test_io.py +++ b/ipykernel/tests/test_io.py @@ -17,7 +17,7 @@ def test_io_api(): thread = IOPubThread(pub) thread.start() - stream = OutStream(session, thread, 'stdout', isatty=True) + stream = OutStream(session, thread, 'stdout') # cleanup unused zmq objects before we start testing thread.stop() From abbcc0ef43a402cd675c1d7801108a27e3dc63b1 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 8 Jun 2021 23:12:45 +0200 Subject: [PATCH 7/7] fix linting --- ipykernel/iostream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipykernel/iostream.py b/ipykernel/iostream.py index eef51aade..e37840be2 100644 --- a/ipykernel/iostream.py +++ b/ipykernel/iostream.py @@ -333,7 +333,7 @@ def __init__( the file descriptor by its number. It will spawn a watching thread, that will swap the give file descriptor for a pipe, read from the pipe, and insert this into the current Stream. - isatty: bool (default, False) + isatty : bool (default, False) Indication of whether this stream has termimal capabilities (e.g. can handle colors) """