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

Fix duplicate progress output in Jupyter #2804

Merged
merged 4 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [13.3.2] - Unreleased

### Fixed
Expand All @@ -13,10 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix syntax error when building with nuitka https://github.com/Textualize/rich/pull/2635
- Fixed pretty printing of empty dataclass https://github.com/Textualize/rich/issues/2819
- Fixes superfluous spaces in html output https://github.com/Textualize/rich/issues/2832
- Fixed duplicate output in Jupyter https://github.com/Textualize/rich/pulls/2804

### Added

- Added Polish README

## [13.3.1] - 2023-01-28

### Fixed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The following people have contributed to the development of Rich:
- [Kyle Pollina](https://github.com/kylepollina)
- [Sebastián Ramírez](https://github.com/tiangolo)
- [Felipe Guedes](https://github.com/guedesfelipe)
- [Min RK](https://github.com/minrk)
- [Clément Robert](https://github.com/neutrinoceros)
- [Brian Rutledge](https://github.com/bhrutledge)
- [Tushar Sadhwani](https://github.com/tusharsadhwani)
Expand Down
14 changes: 9 additions & 5 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,6 @@ def __init__(
self._force_terminal = None
if force_terminal is not None:
self._force_terminal = force_terminal
else:
# If FORCE_COLOR env var has any value at all, we force terminal.
force_color = self._environ.get("FORCE_COLOR")
if force_color is not None:
self._force_terminal = True

self._file = file
self.quiet = quiet
Expand Down Expand Up @@ -949,6 +944,15 @@ def is_terminal(self) -> bool:
# Return False for Idle which claims to be a tty but can't handle ansi codes
return False

if self.is_jupyter:
# return False for Jupyter, which may have FORCE_COLOR set
return False

# If FORCE_COLOR env var has any value at all, we assume a terminal.
force_color = self._environ.get("FORCE_COLOR")
if force_color is not None:
self._force_terminal = True

isatty: Optional[Callable[[], bool]] = getattr(self.file, "isatty", None)
try:
return False if isatty is None else isatty()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,3 +971,11 @@ def test_force_color(env_value):
# means is_terminal returns True.
console = Console(file=io.StringIO(), _environ={"FORCE_COLOR": env_value})
assert console.is_terminal


def test_force_color_jupyter():
# FORCE_COLOR above doesn't happen in a Jupyter kernel
console = Console(
file=io.StringIO(), _environ={"FORCE_COLOR": "1"}, force_jupyter=True
)
assert not console.is_terminal