Skip to content

Commit

Permalink
Additional references to sys.stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Sep 25, 2022
1 parent d5dcdef commit f6dc78b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Advanced

To maintain multiple progress bars simultaneously or write to the console, a manager is required.

Advanced output will only work when the output stream, ``sys.stdout`` by default,
Advanced output will only work when the output stream, ``sys.__stdout__`` by default,
is attached to a TTY. get_manager_ can be used to get a manager instance.
It will return a disabled Manager_ instance if the stream is not attached to a TTY
and an enabled instance if it is.
Expand Down
4 changes: 2 additions & 2 deletions doc/examples.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
..
Copyright 2017 - 2021 Avram Lubkin, All Rights Reserved
Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -31,7 +31,7 @@ Advanced

To maintain multiple progress bars simultaneously or write to the console, a manager is required.

Advanced output will only work when the output stream, :py:data:`sys.stdout` by default,
Advanced output will only work when the output stream, :py:data:`sys.__stdout__` by default,
is attached to a TTY. :py:func:`~enlighten.get_manager` can be used to get a manager instance.
It will return a disabled :py:class:`~enlighten.Manager` instance if the stream is not attached to a TTY
and an enabled instance if it is.
Expand Down
4 changes: 2 additions & 2 deletions doc/patterns.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
..
Copyright 2017 - 2021 Avram Lubkin, All Rights Reserved
Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -35,7 +35,7 @@ The :py:func:`~enlighten.get_manager` function slightly simplifies this
import enlighten
# Example configuration object
config = {'stream': None, # Defaults to sys.stdout
config = {'stream': None, # Defaults to sys.__stdout__
'useCounter': False}
manager = enlighten.get_manager(stream=config['stream'], enabled=config['useCounter'])
Expand Down
6 changes: 3 additions & 3 deletions enlighten/_basemanager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 - 2021 Avram Lubkin, All Rights Reserved
# Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -26,7 +26,7 @@ class BaseManager(object):
Args:
stream(:py:term:`file object`): Output stream. If :py:data:`None`,
defaults to :py:data:`sys.stdout`
defaults to :py:data:`sys.__stdout__`
status_bar_class(:py:term:`class`): Status bar class (Default: :py:class:`StatusBar`)
counter_class(:py:term:`class`): Progress bar class (Default: :py:class:`Counter`)
set_scroll(bool): Enable scroll area redefinition (Default: :py:data:`True`)
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self, **kwargs):
self.no_resize = kwargs.pop('no_resize', False)
self.set_scroll = kwargs.pop('set_scroll', True)
self.status_bar_class = kwargs.pop('status_bar_class', StatusBar)
self.stream = kwargs.pop('stream', sys.stdout)
self.stream = kwargs.pop('stream', sys.__stdout__)
self.threaded = kwargs.pop('threaded', None)
self._width = kwargs.pop('width', None)

Expand Down
4 changes: 2 additions & 2 deletions enlighten/_counter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 - 2021 Avram Lubkin, All Rights Reserved
# Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -183,7 +183,7 @@ class Counter(PrintableCounter):
A :py:class:`Counter` instance can be created with the :py:meth:`Manager.counter` method
or, when a standalone progress bar for simple applications is required, the :py:class:`Counter`
class can be called directly. The output stream will default to :py:data:`sys.stdout` unless
class can be called directly. The output stream will default to :py:data:`sys.__stdout__` unless
``stream`` is set.
.. note::
Expand Down
9 changes: 4 additions & 5 deletions enlighten/_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 - 2021 Avram Lubkin, All Rights Reserved
# Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -30,7 +30,7 @@ class Manager(BaseManager):
Args:
stream(:py:term:`file object`): Output stream. If :py:data:`None`,
defaults to :py:data:`sys.stdout`
defaults to :py:data:`sys.__stdout__`
status_bar_class(:py:term:`class`): Status bar class (Default: :py:class:`StatusBar`)
counter_class(:py:term:`class`): Progress bar class (Default: :py:class:`Counter`)
set_scroll(bool): Enable scroll area redefinition (Default: :py:data:`True`)
Expand All @@ -57,9 +57,8 @@ class Manager(BaseManager):
the primary output stream. The cursor position in the companion stream will be
moved in coordination with the primary stream.
If the value is :py:data:`None`, :py:data:`sys.stdout` and :py:data:`sys.stderr` will
be used as companion streams. Unless explicitly
specified, a stream which is not attached to a TTY (the case when
If the value is :py:data:`None`, the companion stream will be dynamically determined.
Unless explicitly specified, a stream which is not attached to a TTY (the case when
redirected to a file), will not be used as a companion stream.
"""
Expand Down
4 changes: 2 additions & 2 deletions enlighten/counter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 - 2020 Avram Lubkin, All Rights Reserved
# Copyright 2017 - 2022 Avram Lubkin, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -28,7 +28,7 @@ class Counter(_Counter): # pylint: disable=missing-docstring
def __init__(self, **kwargs):

manager = kwargs.get('manager')
stream = kwargs.pop('stream', sys.stdout)
stream = kwargs.pop('stream', sys.__stdout__)

if manager is None:
manager = get_manager(stream=stream, counter_class=self.__class__, set_scroll=False)
Expand Down
2 changes: 1 addition & 1 deletion enlighten/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_manager(stream=None, counter_class=Counter, **kwargs):
"""
Args:
stream(:py:term:`file object`): Output stream. If :py:data:`None`,
defaults to :py:data:`sys.stdout`
defaults to :py:data:`sys.__stdout__`
counter_class(:py:term:`class`): Progress bar class (Default: :py:class:`Counter`)
kwargs(Dict[str, Any]): Any additional :py:term:`keyword arguments<keyword argument>`
will passed to the manager class.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def tearDown(self):
def test_init_safe(self):
with redirect_output('stdout', self.tty.stdout):
# Companion stream is stderr if stream is stdout
manager = enlighten.Manager()
manager = enlighten.Manager(stream=sys.stdout)
self.assertIs(manager.stream, sys.stdout)
self.assertIs(manager.term.stream, sys.stdout)

Expand Down Expand Up @@ -86,7 +86,7 @@ def test_init_redirect(self):
# Need to mock isatty() for some build and test environments
with mock.patch.object(sys, 'stderr') as mock_stderr:
mock_stderr.isatty.return_value = True
manager = enlighten.Manager()
manager = enlighten.Manager(stream=sys.stdout)

self.assertIs(manager.stream, sys.stdout)
self.assertIs(manager.term.stream, sys.stdout)
Expand Down

0 comments on commit f6dc78b

Please sign in to comment.