Skip to content

Commit 0daddaf

Browse files
committed
Upgrade rich to 13.9.4
1 parent c530f32 commit 0daddaf

30 files changed

+391
-194
lines changed

news/rich.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade rich to 13.9.4

src/pip/_vendor/rich/_inspect.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import inspect
42
from inspect import cleandoc, getdoc, getfile, isclass, ismodule, signature
53
from typing import Any, Collection, Iterable, Optional, Tuple, Type, Union

src/pip/_vendor/rich/_null_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __iter__(self) -> Iterator[str]:
4646
return iter([""])
4747

4848
def __enter__(self) -> IO[str]:
49-
pass
49+
return self
5050

5151
def __exit__(
5252
self,

src/pip/_vendor/rich/_win32_console.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
The API that this module wraps is documented at https://docs.microsoft.com/en-us/windows/console/console-functions
44
"""
5+
56
import ctypes
67
import sys
78
from typing import Any
@@ -380,7 +381,7 @@ def cursor_position(self) -> WindowsCoordinates:
380381
WindowsCoordinates: The current cursor position.
381382
"""
382383
coord: COORD = GetConsoleScreenBufferInfo(self._handle).dwCursorPosition
383-
return WindowsCoordinates(row=cast(int, coord.Y), col=cast(int, coord.X))
384+
return WindowsCoordinates(row=coord.Y, col=coord.X)
384385

385386
@property
386387
def screen_size(self) -> WindowsCoordinates:
@@ -390,9 +391,7 @@ def screen_size(self) -> WindowsCoordinates:
390391
WindowsCoordinates: The width and height of the screen as WindowsCoordinates.
391392
"""
392393
screen_size: COORD = GetConsoleScreenBufferInfo(self._handle).dwSize
393-
return WindowsCoordinates(
394-
row=cast(int, screen_size.Y), col=cast(int, screen_size.X)
395-
)
394+
return WindowsCoordinates(row=screen_size.Y, col=screen_size.X)
396395

397396
def write_text(self, text: str) -> None:
398397
"""Write text directly to the terminal without any modification of styles

src/pip/_vendor/rich/align.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class VerticalCenter(JupyterMixin):
240240
241241
Args:
242242
renderable (RenderableType): A renderable object.
243+
style (StyleType, optional): An optional style to apply to the background. Defaults to None.
243244
"""
244245

245246
def __init__(

src/pip/_vendor/rich/ansi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
re_ansi = re.compile(
1111
r"""
12+
(?:\x1b[0-?])|
1213
(?:\x1b\](.*?)\x1b\\)|
1314
(?:\x1b([(@-Z\\-_]|\[[0-?]*[ -/]*[@-~]))
1415
""",

src/pip/_vendor/rich/cells.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
from __future__ import annotations
22

3-
import re
43
from functools import lru_cache
54
from typing import Callable
65

76
from ._cell_widths import CELL_WIDTHS
87

9-
# Regex to match sequence of the most common character ranges
10-
_is_single_cell_widths = re.compile("^[\u0020-\u006f\u00a0\u02ff\u0370-\u0482]*$").match
8+
# Ranges of unicode ordinals that produce a 1-cell wide character
9+
# This is non-exhaustive, but covers most common Western characters
10+
_SINGLE_CELL_UNICODE_RANGES: list[tuple[int, int]] = [
11+
(0x20, 0x7E), # Latin (excluding non-printable)
12+
(0xA0, 0xAC),
13+
(0xAE, 0x002FF),
14+
(0x00370, 0x00482), # Greek / Cyrillic
15+
(0x02500, 0x025FC), # Box drawing, box elements, geometric shapes
16+
(0x02800, 0x028FF), # Braille
17+
]
18+
19+
# A set of characters that are a single cell wide
20+
_SINGLE_CELLS = frozenset(
21+
[
22+
character
23+
for _start, _end in _SINGLE_CELL_UNICODE_RANGES
24+
for character in map(chr, range(_start, _end + 1))
25+
]
26+
)
27+
28+
# When called with a string this will return True if all
29+
# characters are single-cell, otherwise False
30+
_is_single_cell_widths: Callable[[str], bool] = _SINGLE_CELLS.issuperset
1131

1232

1333
@lru_cache(4096)
@@ -23,9 +43,9 @@ def cached_cell_len(text: str) -> int:
2343
Returns:
2444
int: Get the number of cells required to display text.
2545
"""
26-
_get_size = get_character_cell_size
27-
total_size = sum(_get_size(character) for character in text)
28-
return total_size
46+
if _is_single_cell_widths(text):
47+
return len(text)
48+
return sum(map(get_character_cell_size, text))
2949

3050

3151
def cell_len(text: str, _cell_len: Callable[[str], int] = cached_cell_len) -> int:
@@ -39,9 +59,9 @@ def cell_len(text: str, _cell_len: Callable[[str], int] = cached_cell_len) -> in
3959
"""
4060
if len(text) < 512:
4161
return _cell_len(text)
42-
_get_size = get_character_cell_size
43-
total_size = sum(_get_size(character) for character in text)
44-
return total_size
62+
if _is_single_cell_widths(text):
63+
return len(text)
64+
return sum(map(get_character_cell_size, text))
4565

4666

4767
@lru_cache(maxsize=4096)
@@ -54,20 +74,7 @@ def get_character_cell_size(character: str) -> int:
5474
Returns:
5575
int: Number of cells (0, 1 or 2) occupied by that character.
5676
"""
57-
return _get_codepoint_cell_size(ord(character))
58-
59-
60-
@lru_cache(maxsize=4096)
61-
def _get_codepoint_cell_size(codepoint: int) -> int:
62-
"""Get the cell size of a character.
63-
64-
Args:
65-
codepoint (int): Codepoint of a character.
66-
67-
Returns:
68-
int: Number of cells (0, 1 or 2) occupied by that character.
69-
"""
70-
77+
codepoint = ord(character)
7178
_table = CELL_WIDTHS
7279
lower_bound = 0
7380
upper_bound = len(_table) - 1

src/pip/_vendor/rich/color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import platform
21
import re
2+
import sys
33
from colorsys import rgb_to_hls
44
from enum import IntEnum
55
from functools import lru_cache
@@ -15,7 +15,7 @@
1515
from .text import Text
1616

1717

18-
WINDOWS = platform.system() == "Windows"
18+
WINDOWS = sys.platform == "win32"
1919

2020

2121
class ColorSystem(IntEnum):

src/pip/_vendor/rich/console.py

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inspect
22
import os
3-
import platform
43
import sys
54
import threading
65
import zlib
@@ -76,7 +75,7 @@
7675

7776
JUPYTER_DEFAULT_COLUMNS = 115
7877
JUPYTER_DEFAULT_LINES = 100
79-
WINDOWS = platform.system() == "Windows"
78+
WINDOWS = sys.platform == "win32"
8079

8180
HighlighterType = Callable[[Union[str, "Text"]], "Text"]
8281
JustifyMethod = Literal["default", "left", "center", "right", "full"]
@@ -90,15 +89,15 @@ class NoChange:
9089
NO_CHANGE = NoChange()
9190

9291
try:
93-
_STDIN_FILENO = sys.__stdin__.fileno()
92+
_STDIN_FILENO = sys.__stdin__.fileno() # type: ignore[union-attr]
9493
except Exception:
9594
_STDIN_FILENO = 0
9695
try:
97-
_STDOUT_FILENO = sys.__stdout__.fileno()
96+
_STDOUT_FILENO = sys.__stdout__.fileno() # type: ignore[union-attr]
9897
except Exception:
9998
_STDOUT_FILENO = 1
10099
try:
101-
_STDERR_FILENO = sys.__stderr__.fileno()
100+
_STDERR_FILENO = sys.__stderr__.fileno() # type: ignore[union-attr]
102101
except Exception:
103102
_STDERR_FILENO = 2
104103

@@ -1006,19 +1005,14 @@ def size(self) -> ConsoleDimensions:
10061005
width: Optional[int] = None
10071006
height: Optional[int] = None
10081007

1009-
if WINDOWS: # pragma: no cover
1008+
streams = _STD_STREAMS_OUTPUT if WINDOWS else _STD_STREAMS
1009+
for file_descriptor in streams:
10101010
try:
1011-
width, height = os.get_terminal_size()
1011+
width, height = os.get_terminal_size(file_descriptor)
10121012
except (AttributeError, ValueError, OSError): # Probably not a terminal
10131013
pass
1014-
else:
1015-
for file_descriptor in _STD_STREAMS:
1016-
try:
1017-
width, height = os.get_terminal_size(file_descriptor)
1018-
except (AttributeError, ValueError, OSError):
1019-
pass
1020-
else:
1021-
break
1014+
else:
1015+
break
10221016

10231017
columns = self._environ.get("COLUMNS")
10241018
if columns is not None and columns.isdigit():
@@ -1309,7 +1303,7 @@ def render(
13091303

13101304
renderable = rich_cast(renderable)
13111305
if hasattr(renderable, "__rich_console__") and not isclass(renderable):
1312-
render_iterable = renderable.__rich_console__(self, _options) # type: ignore[union-attr]
1306+
render_iterable = renderable.__rich_console__(self, _options)
13131307
elif isinstance(renderable, str):
13141308
text_renderable = self.render_str(
13151309
renderable, highlight=_options.highlight, markup=_options.markup
@@ -1386,9 +1380,14 @@ def render_lines(
13861380
extra_lines = render_options.height - len(lines)
13871381
if extra_lines > 0:
13881382
pad_line = [
1389-
[Segment(" " * render_options.max_width, style), Segment("\n")]
1390-
if new_lines
1391-
else [Segment(" " * render_options.max_width, style)]
1383+
(
1384+
[
1385+
Segment(" " * render_options.max_width, style),
1386+
Segment("\n"),
1387+
]
1388+
if new_lines
1389+
else [Segment(" " * render_options.max_width, style)]
1390+
)
13921391
]
13931392
lines.extend(pad_line * extra_lines)
13941393

@@ -1437,9 +1436,11 @@ def render_str(
14371436
rich_text.overflow = overflow
14381437
else:
14391438
rich_text = Text(
1440-
_emoji_replace(text, default_variant=self._emoji_variant)
1441-
if emoji_enabled
1442-
else text,
1439+
(
1440+
_emoji_replace(text, default_variant=self._emoji_variant)
1441+
if emoji_enabled
1442+
else text
1443+
),
14431444
justify=justify,
14441445
overflow=overflow,
14451446
style=style,
@@ -1536,7 +1537,11 @@ def check_text() -> None:
15361537
if isinstance(renderable, str):
15371538
append_text(
15381539
self.render_str(
1539-
renderable, emoji=emoji, markup=markup, highlighter=_highlighter
1540+
renderable,
1541+
emoji=emoji,
1542+
markup=markup,
1543+
highlight=highlight,
1544+
highlighter=_highlighter,
15401545
)
15411546
)
15421547
elif isinstance(renderable, Text):
@@ -1986,6 +1991,20 @@ def log(
19861991
):
19871992
buffer_extend(line)
19881993

1994+
def on_broken_pipe(self) -> None:
1995+
"""This function is called when a `BrokenPipeError` is raised.
1996+
1997+
This can occur when piping Textual output in Linux and macOS.
1998+
The default implementation is to exit the app, but you could implement
1999+
this method in a subclass to change the behavior.
2000+
2001+
See https://docs.python.org/3/library/signal.html#note-on-sigpipe for details.
2002+
"""
2003+
self.quiet = True
2004+
devnull = os.open(os.devnull, os.O_WRONLY)
2005+
os.dup2(devnull, sys.stdout.fileno())
2006+
raise SystemExit(1)
2007+
19892008
def _check_buffer(self) -> None:
19902009
"""Check if the buffer may be rendered. Render it if it can (e.g. Console.quiet is False)
19912010
Rendering is supported on Windows, Unix and Jupyter environments. For
@@ -1995,8 +2014,17 @@ def _check_buffer(self) -> None:
19952014
if self.quiet:
19962015
del self._buffer[:]
19972016
return
2017+
2018+
try:
2019+
self._write_buffer()
2020+
except BrokenPipeError:
2021+
self.on_broken_pipe()
2022+
2023+
def _write_buffer(self) -> None:
2024+
"""Write the buffer to the output file."""
2025+
19982026
with self._lock:
1999-
if self.record:
2027+
if self.record and not self._buffer_index:
20002028
with self._record_buffer_lock:
20012029
self._record_buffer.extend(self._buffer[:])
20022030

@@ -2166,7 +2194,7 @@ def save_text(self, path: str, *, clear: bool = True, styles: bool = False) -> N
21662194
21672195
"""
21682196
text = self.export_text(clear=clear, styles=styles)
2169-
with open(path, "wt", encoding="utf-8") as write_file:
2197+
with open(path, "w", encoding="utf-8") as write_file:
21702198
write_file.write(text)
21712199

21722200
def export_html(
@@ -2272,7 +2300,7 @@ def save_html(
22722300
code_format=code_format,
22732301
inline_styles=inline_styles,
22742302
)
2275-
with open(path, "wt", encoding="utf-8") as write_file:
2303+
with open(path, "w", encoding="utf-8") as write_file:
22762304
write_file.write(html)
22772305

22782306
def export_svg(
@@ -2561,7 +2589,7 @@ def save_svg(
25612589
font_aspect_ratio=font_aspect_ratio,
25622590
unique_id=unique_id,
25632591
)
2564-
with open(path, "wt", encoding="utf-8") as write_file:
2592+
with open(path, "w", encoding="utf-8") as write_file:
25652593
write_file.write(svg)
25662594

25672595

src/pip/_vendor/rich/default_styles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"logging.level.notset": Style(dim=True),
5555
"logging.level.debug": Style(color="green"),
5656
"logging.level.info": Style(color="blue"),
57-
"logging.level.warning": Style(color="red"),
57+
"logging.level.warning": Style(color="yellow"),
5858
"logging.level.error": Style(color="red", bold=True),
5959
"logging.level.critical": Style(color="red", bold=True, reverse=True),
6060
"log.level": Style.null(),
@@ -120,6 +120,7 @@
120120
"traceback.exc_type": Style(color="bright_red", bold=True),
121121
"traceback.exc_value": Style.null(),
122122
"traceback.offset": Style(color="bright_red", bold=True),
123+
"traceback.error_range": Style(underline=True, bold=True, dim=False),
123124
"bar.back": Style(color="grey23"),
124125
"bar.complete": Style(color="rgb(249,38,114)"),
125126
"bar.finished": Style(color="rgb(114,156,31)"),

0 commit comments

Comments
 (0)