From 8e3a0be6fbb9186fa45cc42ec833d0895d2313ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 1 Feb 2022 12:24:18 +0100 Subject: [PATCH 01/14] Fix test_syntax not to use identity comparison on string Fix test_syntax to compare strings via "==" rather than "is", in order to fix test failure on PyPy3. --- CHANGELOG.md | 4 ++++ CONTRIBUTORS.md | 1 + tests/test_syntax.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4997ae325..17f3028b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890 +### Fixed + +- Fixed `test_syntax.py::test_from_path_lexer_override` test failure on PyPy3 https://github.com/Textualize/rich/pull/1904 + ## [11.1.0] - 2022-01-28 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c29cd7904..06e0618fd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -27,3 +27,4 @@ The following people have contributed to the development of Rich: - [Nicolas Simonds](https://github.com/0xDEC0DE) - [Gabriele N. Tornetta](https://github.com/p403n1x87) - [Patrick Arminio](https://github.com/patrick91) +- [Michał Górny](https://github.com/mgorny) diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 46d0126e1..e5d904f36 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -277,7 +277,7 @@ def test_from_path_lexer_override(): try: os.write(fh, b"import this\n") syntax = Syntax.from_path(path, lexer="rust") - assert syntax.lexer.name is "Rust" + assert syntax.lexer.name == "Rust" assert syntax.code == "import this\n" finally: os.remove(path) From f15dc3ea0b59d5fc04341d3f634f0e61c05a84db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Tue, 1 Feb 2022 15:10:32 +0100 Subject: [PATCH 02/14] Fix test_inspect failures on PyPy3 Mark the test_inspect tests failing on PyPy3 due to different output to be skipped appropriately. --- CHANGELOG.md | 2 +- tests/test_inspect.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f3028b4..1a75bf376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fixed `test_syntax.py::test_from_path_lexer_override` test failure on PyPy3 https://github.com/Textualize/rich/pull/1904 +- Fixed test failures on PyPy3 https://github.com/Textualize/rich/pull/1904 ## [11.1.0] - 2022-01-28 diff --git a/tests/test_inspect.py b/tests/test_inspect.py index 63c5f0624..b4c1d2a70 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -32,6 +32,11 @@ reason="rendered differently on py3.10", ) +skip_pypy3 = pytest.mark.skipif( + hasattr(sys, "pypy_version_info"), + reason="rendered differently on pypy3", +) + def render(obj, methods=False, value=False, width=50) -> str: console = Console(file=io.StringIO(), width=width, legacy_windows=False) @@ -81,6 +86,7 @@ def test_render(): assert expected == result +@skip_pypy3 def test_inspect_text(): expected = ( "╭──────────────── ─────────────────╮\n" @@ -98,6 +104,7 @@ def test_inspect_text(): @skip_py36 @skip_py37 +@skip_pypy3 def test_inspect_empty_dict(): expected = ( "╭──────────────── ────────────────╮\n" @@ -119,6 +126,7 @@ def test_inspect_empty_dict(): assert render({}).startswith(expected) +@skip_pypy3 def test_inspect_builtin_function(): expected = ( "╭────────── ───────────╮\n" @@ -237,6 +245,7 @@ def test_inspect_integer_with_methods(): @skip_py36 @skip_py37 +@skip_pypy3 def test_broken_call_attr(): class NotCallable: __call__ = 5 # Passes callable() but isn't really callable From 731f9848228e4cffede54ed2056b606b27a35ecb Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 13:51:58 +0000 Subject: [PATCH 03/14] Expose diagnose.report as a function add a little more info to hint at environment --- .coveragerc | 3 ++- rich/diagnose.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index ff1a046c0..2afac8dc6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,8 @@ omit = rich/jupyter.py rich/_windows.py rich/_timer.py - + rich/diagnose.py + [report] exclude_lines = pragma: no cover diff --git a/rich/diagnose.py b/rich/diagnose.py index 455e11dc0..7ecdff97f 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -1,6 +1,35 @@ -if __name__ == "__main__": # pragma: no cover - from rich.console import Console - from rich import inspect +import os +import platform + +from rich import inspect +from rich.console import Console, get_windows_console_features +from rich.panel import Panel +from rich.text import Text + + +def report(): # pragma: no cover + """Print a report to the terminal with debugging information""" + console = Console() + inspect(console) + features = get_windows_console_features() + inspect(features) + + if console.is_jupyter: + jpy_parent_pid = os.getenv("JPY_PARENT_PID") + vs_code_verbose = os.getenv("VSCODE_VERBOSE_LOGGING") + console.print( + Panel( + title="Jupyter Environment Hints", + renderable=Text( + f"JPY_PARENT_PID = {jpy_parent_pid}\n" + f"VSCODE_VERBOSE_LOGGING = {vs_code_verbose}" + ), + ), + ) + + console.print(f'platform="{platform.system()}"') + +if __name__ == "__main__": # pragma: no cover console = Console() inspect(console) From bdad740de91368814c331ea807f362e5bec73336 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:10:12 +0000 Subject: [PATCH 04/14] Update issue template --- .github/ISSUE_TEMPLATE/bug_report.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 05cd2cd11..723781db8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -20,12 +20,21 @@ Provide a minimal code example that demonstrates the issue if you can. If the is What platform (Win/Linux/Mac) are you running on? What terminal software are you using? -I may ask you to cut and paste the output of the following commands. It may save some time if you do it now. +I may ask you to copy and paste the output of the following commands. It may save some time if you do it now. + +If you're using Rich in a terminal: ``` -python -m rich.diagnose -python -m rich._windows +python -c "from rich.diagnose import report; report()" pip freeze | grep rich ``` - + +If you're using Rich in a Jupyter Notebook, run the following snippet in a cell +and paste the output in your bug report. + +```python +from rich.diagnose import report +report() +``` + From 29bc5dd4905c6bf8ec8d4fd8d789abbdfe5d6b92 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:19:15 +0000 Subject: [PATCH 05/14] Add missing return type annotation to diagnose.report --- rich/diagnose.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/diagnose.py b/rich/diagnose.py index 7ecdff97f..7e8ad989b 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -7,7 +7,7 @@ from rich.text import Text -def report(): # pragma: no cover +def report() -> None: # pragma: no cover """Print a report to the terminal with debugging information""" console = Console() inspect(console) From bcbaed2b95b3f0ce4d5a72a5fc40274158d96bc9 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 4 Feb 2022 14:23:32 +0000 Subject: [PATCH 06/14] Added `rich.diagnose.report` note to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4997ae325..0887ed394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890 +- Added `rich.diagnose.report` to expose environment debugging logic as function https://github.com/Textualize/rich/pull/1917 ## [11.1.0] - 2022-01-28 From e1c595c7e5bd00fc7900471ea13f6de2fa8d165d Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 6 Feb 2022 13:53:06 -0600 Subject: [PATCH 07/14] task._progress change default_factory to create deque(maxlen=1000), to avoid run-time while loop to trim to length 1000 --- rich/progress.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index fe35b6c17..115ae8160 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -475,7 +475,7 @@ class Task: """Optional[float]: The last speed for a finished task.""" _progress: Deque[ProgressSample] = field( - default_factory=deque, init=False, repr=False + default_factory=lambda: deque(maxlen=1000), init=False, repr=False ) _lock: RLock = field(repr=False, default_factory=RLock) @@ -813,8 +813,6 @@ def update( popleft = _progress.popleft while _progress and _progress[0].timestamp < old_sample_time: popleft() - while len(_progress) > 1000: - popleft() if update_completed > 0: _progress.append(ProgressSample(current_time, update_completed)) if task.completed >= task.total and task.finished_time is None: From e4f48cc612e35d2fb6bfe9c8c946a80aa2dad564 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 6 Feb 2022 14:03:39 -0600 Subject: [PATCH 08/14] Update CONTRIBUTORS.md and CHANGELOG.md with changes related to adding Progress.get_default_columns --- CHANGELOG.md | 1 + CONTRIBUTORS.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ece575ab..154decdc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890 +- Added classmethod `Progress.get_default_columns()` to get the default list of progress bar columns https://github.com/Textualize/rich/pull/1894 ## [11.1.0] - 2022-01-28 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c29cd7904..0c0f891fd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -16,6 +16,7 @@ The following people have contributed to the development of Rich: - [Hedy Li](https://github.com/hedythedev) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) +- [Paul McGuire](https://github.com/ptmcg) - [Nathan Page](https://github.com/nathanrpage97) - [Avi Perl](https://github.com/avi-perl) - [Laurent Peuch](https://github.com/psycojoker) From c8c2cf117f3510b1105c3fa5a93a811855f7f0b5 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 7 Feb 2022 10:06:36 +0000 Subject: [PATCH 09/14] Add more diagnose.report env variables, invoke from __main__ --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- rich/diagnose.py | 30 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 723781db8..6d6f45677 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,7 +25,7 @@ I may ask you to copy and paste the output of the following commands. It may sav If you're using Rich in a terminal: ``` -python -c "from rich.diagnose import report; report()" +python -m rich.diagnose pip freeze | grep rich ``` diff --git a/rich/diagnose.py b/rich/diagnose.py index 7e8ad989b..09c4e0622 100644 --- a/rich/diagnose.py +++ b/rich/diagnose.py @@ -4,7 +4,7 @@ from rich import inspect from rich.console import Console, get_windows_console_features from rich.panel import Panel -from rich.text import Text +from rich.pretty import Pretty def report() -> None: # pragma: no cover @@ -14,22 +14,22 @@ def report() -> None: # pragma: no cover features = get_windows_console_features() inspect(features) - if console.is_jupyter: - jpy_parent_pid = os.getenv("JPY_PARENT_PID") - vs_code_verbose = os.getenv("VSCODE_VERBOSE_LOGGING") - console.print( - Panel( - title="Jupyter Environment Hints", - renderable=Text( - f"JPY_PARENT_PID = {jpy_parent_pid}\n" - f"VSCODE_VERBOSE_LOGGING = {vs_code_verbose}" - ), - ), - ) + env_names = ( + "TERM", + "COLORTERM", + "CLICOLOR", + "NO_COLOR", + "TERM_PROGRAM", + "COLUMNS", + "LINES", + "JPY_PARENT_PID", + "VSCODE_VERBOSE_LOGGING", + ) + env = {name: os.getenv(name) for name in env_names} + console.print(Panel.fit((Pretty(env)), title="[b]Environment Variables")) console.print(f'platform="{platform.system()}"') if __name__ == "__main__": # pragma: no cover - console = Console() - inspect(console) + report() From 232fade573401688ccc40e42756c7a4022c5e8ac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 13:31:20 +0000 Subject: [PATCH 10/14] Bump sphinx-copybutton from 0.4.0 to 0.5.0 Bumps [sphinx-copybutton](https://github.com/executablebooks/sphinx-copybutton) from 0.4.0 to 0.5.0. - [Release notes](https://github.com/executablebooks/sphinx-copybutton/releases) - [Changelog](https://github.com/executablebooks/sphinx-copybutton/blob/master/CHANGELOG.md) - [Commits](https://github.com/executablebooks/sphinx-copybutton/compare/v0.4.0...v0.5.0) --- updated-dependencies: - dependency-name: sphinx-copybutton dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 849854779..193114721 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ alabaster==0.7.12 Sphinx==4.4.0 sphinx-rtd-theme==1.0.0 -sphinx-copybutton==0.4.0 +sphinx-copybutton==0.5.0 From 429c6d38614072d574e22d7aabbe08ff566ab60c Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 8 Feb 2022 20:05:39 +0000 Subject: [PATCH 11/14] optimization for measure --- CHANGELOG.md | 8 ++++++-- pyproject.toml | 2 +- rich/measure.py | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a53bb62..9c1416a5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +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). -## Unreleased +## [11.2.0] - 2022-02-08 ### Added @@ -13,11 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `rich.diagnose.report` to expose environment debugging logic as function https://github.com/Textualize/rich/pull/1917 - Added classmethod `Progress.get_default_columns()` to get the default list of progress bar columns https://github.com/Textualize/rich/pull/1894 +### Fixed + +- Fixed performance issue in measuring text + ## [11.1.0] - 2022-01-28 ### Added - - Workaround for edge case of object from Faiss with no `__class__` https://github.com/Textualize/rich/issues/1838 - Add Traditional Chinese readme - Add `Syntax.guess_lexer`, add support for more lexers (e.g. Django templates etc.) https://github.com/Textualize/rich/pull/1869 @@ -1627,6 +1630,7 @@ Major version bump for a breaking change to `Text.stylize signature`, which corr - First official release, API still to be stabilized +[11.2.0]: https://github.com/willmcgugan/rich/compare/v11.1.0...v11.2.0 [11.1.0]: https://github.com/willmcgugan/rich/compare/v11.0.0...v11.1.0 [11.0.0]: https://github.com/willmcgugan/rich/compare/v10.16.1...v11.0.0 [10.16.1]: https://github.com/willmcgugan/rich/compare/v10.16.0...v10.16.1 diff --git a/pyproject.toml b/pyproject.toml index e8ea9bf99..4b221c35b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "rich" homepage = "https://github.com/willmcgugan/rich" documentation = "https://rich.readthedocs.io/en/latest/" -version = "11.1.0" +version = "11.2.0" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" authors = ["Will McGugan "] license = "MIT" diff --git a/rich/measure.py b/rich/measure.py index aea238df9..e12787c8b 100644 --- a/rich/measure.py +++ b/rich/measure.py @@ -1,5 +1,5 @@ from operator import itemgetter -from typing import Callable, Iterable, NamedTuple, Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Callable, Iterable, NamedTuple, Optional from . import errors from .protocol import is_renderable, rich_cast @@ -96,7 +96,9 @@ def get( if _max_width < 1: return Measurement(0, 0) if isinstance(renderable, str): - renderable = console.render_str(renderable, markup=options.markup) + renderable = console.render_str( + renderable, markup=options.markup, highlight=False + ) renderable = rich_cast(renderable) if is_renderable(renderable): get_console_width: Optional[ From c787271970768bdeee0dc134931a9ada3e676a7b Mon Sep 17 00:00:00 2001 From: losuler Date: Thu, 10 Feb 2022 00:09:25 +1100 Subject: [PATCH 12/14] Fix keyword argument names --- docs/source/tables.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/tables.rst b/docs/source/tables.rst index 7429ac66a..22236358f 100644 --- a/docs/source/tables.rst +++ b/docs/source/tables.rst @@ -62,14 +62,14 @@ There are a number of keyword arguments on the Table constructor you can use to - ``expand`` Set to True to expand the table to the full available size. - ``show_header`` Set to True to show a header, False to disable it. - ``show_footer`` Set to True to show a footer, False to disable it. -- ``show edge`` Set to False to disable the edge line around the table. +- ``show_edge`` Set to False to disable the edge line around the table. - ``show_lines`` Set to True to show lines between rows as well as header / footer. - ``leading`` Additional space between rows. - ``style`` A Style to apply to the entire table, e.g. "on blue" - ``row_styles`` Set to a list of styles to style alternating rows. e.g. ``["dim", ""]`` to create *zebra stripes* - ``header_style`` Set the default style for the header. - ``footer_style`` Set the default style for the footer. -- ``border style`` Set a style for border characters. +- ``border_style`` Set a style for border characters. - ``title_style`` Set a style for the title. - ``caption_style`` Set a style for the caption. - ``title_justify`` Set the title justify method ("left", "right", "center", or "full") From 6216ee0fccb6c40fc363ae69ea353c2e77c487fb Mon Sep 17 00:00:00 2001 From: Wasi Master <63045920+wasi-master@users.noreply.github.com> Date: Wed, 9 Feb 2022 22:32:54 +0600 Subject: [PATCH 13/14] In Jupyter mode have the link target set to "_blank" --- rich/jupyter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/jupyter.py b/rich/jupyter.py index bedf5cb19..97340d004 100644 --- a/rich/jupyter.py +++ b/rich/jupyter.py @@ -63,7 +63,7 @@ def escape(text: str) -> str: rule = style.get_html_style(theme) text = f'{text}' if rule else text if style.link: - text = f'{text}' + text = f'{text}' append_fragment(text) code = "".join(fragments) From 821c0ce2ebc947d34328a375d7714a07b7ef3c24 Mon Sep 17 00:00:00 2001 From: Wasi Master <63045920+wasi-master@users.noreply.github.com> Date: Thu, 10 Feb 2022 17:17:16 +0600 Subject: [PATCH 14/14] Modify CHANGELOG.md and CONTRIBUTORS.md --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d04a55d..fcf58cd7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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). +## Unreleased + +### Fixed + +- In Jupyter mode make the link target be set to "_blank" + ## [11.2.0] - 2022-02-08 ### Added diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 61c67de9d..23109df83 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -29,3 +29,4 @@ The following people have contributed to the development of Rich: - [Gabriele N. Tornetta](https://github.com/p403n1x87) - [Patrick Arminio](https://github.com/patrick91) - [Michał Górny](https://github.com/mgorny) +- [Arian Mollik Wasi](https://github.com/wasi-master)