Skip to content

Commit

Permalink
Merge branch 'master' into fix-repr-highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 10, 2022
2 parents ba0262b + 3be88c0 commit 099893e
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Expand Up @@ -2,7 +2,8 @@
omit = rich/jupyter.py
rich/_windows.py
rich/_timer.py

rich/diagnose.py

[report]
exclude_lines =
pragma: no cover
Expand Down
15 changes: 12 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -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
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()
```

</details>
24 changes: 22 additions & 2 deletions CHANGELOG.md
Expand Up @@ -7,14 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- In Jupyter mode make the link target be set to "_blank"

### Added

- Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890
- Add support for enum.Flag in ReprHighlighter https://github.com/Textualize/rich/pull/1920
## [11.1.0] - 2022-01-28

## [11.2.0] - 2022-02-08

### 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
- 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

### Fixed

- Fixed test failures on PyPy3 https://github.com/Textualize/rich/pull/1904

## [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
Expand Down Expand Up @@ -1625,6 +1644,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
Expand Down
6 changes: 5 additions & 1 deletion CONTRIBUTORS.md
Expand Up @@ -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)
Expand All @@ -26,5 +27,8 @@ The following people have contributed to the development of Rich:
- [Tim Savage](https://github.com/timsavage)
- [Nicolas Simonds](https://github.com/0xDEC0DE)
- [Gabriele N. Tornetta](https://github.com/p403n1x87)
- [Patrick Arminio](https://github.com/patrick91)
- [Patrick Arminio](https://github.com/patrick9)
- [Dennis Brakhane](https://github.com/brakhane)
- [Michał Górny](https://github.com/mgorny)
- [Arian Mollik Wasi](https://github.com/wasi-master)

2 changes: 1 addition & 1 deletion 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
4 changes: 2 additions & 2 deletions docs/source/tables.rst
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -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 <willmcgugan@gmail.com>"]
license = "MIT"
Expand Down
35 changes: 32 additions & 3 deletions 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.pretty import Pretty


def report() -> None: # pragma: no cover
"""Print a report to the terminal with debugging information"""
console = Console()
inspect(console)
features = get_windows_console_features()
inspect(features)

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
report()
2 changes: 1 addition & 1 deletion rich/jupyter.py
Expand Up @@ -63,7 +63,7 @@ def escape(text: str) -> str:
rule = style.get_html_style(theme)
text = f'<span style="{rule}">{text}</span>' if rule else text
if style.link:
text = f'<a href="{style.link}">{text}</a>'
text = f'<a href="{style.link}" target="_blank">{text}</a>'
append_fragment(text)

code = "".join(fragments)
Expand Down
6 changes: 4 additions & 2 deletions 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
Expand Down Expand Up @@ -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[
Expand Down
4 changes: 1 addition & 3 deletions rich/progress.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_inspect.py
Expand Up @@ -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)
Expand Down Expand Up @@ -81,6 +86,7 @@ def test_render():
assert expected == result


@skip_pypy3
def test_inspect_text():
expected = (
"╭──────────────── <class 'str'> ─────────────────╮\n"
Expand All @@ -98,6 +104,7 @@ def test_inspect_text():

@skip_py36
@skip_py37
@skip_pypy3
def test_inspect_empty_dict():
expected = (
"╭──────────────── <class 'dict'> ────────────────╮\n"
Expand All @@ -119,6 +126,7 @@ def test_inspect_empty_dict():
assert render({}).startswith(expected)


@skip_pypy3
def test_inspect_builtin_function():
expected = (
"╭────────── <built-in function print> ───────────╮\n"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_syntax.py
Expand Up @@ -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)
Expand Down

0 comments on commit 099893e

Please sign in to comment.