MCPcopy
hub / github.com/Textualize/rich / install

Function install

rich/pretty.py:171–250  ·  view source on GitHub ↗

Install automatic pretty printing in the Python REPL. Args: console (Console, optional): Console instance or ``None`` to use global console. Defaults to None. overflow (Optional[OverflowMethod], optional): Overflow method. Defaults to "ignore". crop (Optional[bool], opti

(
    console: Optional["Console"] = None,
    overflow: "OverflowMethod" = "ignore",
    crop: bool = False,
    indent_guides: bool = False,
    max_length: Optional[int] = None,
    max_string: Optional[int] = None,
    max_depth: Optional[int] = None,
    expand_all: bool = False,
)

Source from the content-addressed store, hash-verified

169
170
171def install(
172 console: Optional["Console"] = None,
173 overflow: "OverflowMethod" = "ignore",
174 crop: bool = False,
175 indent_guides: bool = False,
176 max_length: Optional[int] = None,
177 max_string: Optional[int] = None,
178 max_depth: Optional[int] = None,
179 expand_all: bool = False,
180) -> None:
181 """Install automatic pretty printing in the Python REPL.
182
183 Args:
184 console (Console, optional): Console instance or ``None`` to use global console. Defaults to None.
185 overflow (Optional[OverflowMethod], optional): Overflow method. Defaults to "ignore".
186 crop (Optional[bool], optional): Enable cropping of long lines. Defaults to False.
187 indent_guides (bool, optional): Enable indentation guides. Defaults to False.
188 max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
189 Defaults to None.
190 max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
191 max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None.
192 expand_all (bool, optional): Expand all containers. Defaults to False.
193 max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
194 """
195 from rich import get_console
196
197 console = console or get_console()
198 assert console is not None
199
200 def display_hook(value: Any) -> None:
201 """Replacement sys.displayhook which prettifies objects with Rich."""
202 if value is not None:
203 assert console is not None
204 builtins._ = None # type: ignore[attr-defined]
205 console.print(
206 (
207 value
208 if _safe_isinstance(value, RichRenderable)
209 else Pretty(
210 value,
211 overflow=overflow,
212 indent_guides=indent_guides,
213 max_length=max_length,
214 max_string=max_string,
215 max_depth=max_depth,
216 expand_all=expand_all,
217 )
218 ),
219 crop=crop,
220 )
221 builtins._ = value # type: ignore[attr-defined]
222
223 try:
224 ip = get_ipython() # type: ignore[name-defined]
225 except NameError:
226 sys.displayhook = display_hook
227 else:
228 from IPython.core.formatters import BaseFormatter

Callers 3

test_installFunction · 0.90
test_install_max_depthFunction · 0.90
load_ipython_extensionFunction · 0.90

Calls 2

get_consoleFunction · 0.90
RichFormatterClass · 0.85

Tested by 2

test_installFunction · 0.72
test_install_max_depthFunction · 0.72