Skip to content
/ dvc Public
forked from iterative/dvc

Commit

Permalink
deps: bump rich to >=10.13.0
Browse files Browse the repository at this point in the history
It comes with the support for no. of parameters that matches with json.dumps.
See: Textualize/rich#1547 and
Textualize/rich#1644.

Also added support for printing json to stderr. Before we used to use json.dumps
and rich.json.JSON based on isatty. Now we use rich.print_json on both
tty and non-tty conditions, which may avoid different behaviours in the
future.
  • Loading branch information
skshetry committed Nov 7, 2021
1 parent be61284 commit 69b5122
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 28 additions & 14 deletions dvc/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,35 @@ def error_write(
)

def write_json(
self, data: Any, indent: int = 2, default: Callable = None
self,
data: Any,
indent: int = None,
highlight: bool = None,
stderr: bool = False,
skip_keys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
allow_nan: bool = True,
default: Optional[Callable[[Any], Any]] = None,
sort_keys: bool = False,
) -> None:
import json

if self.isatty():
from rich.highlighter import JSONHighlighter

j = json.dumps(data, indent=indent, default=default)
highlighter = JSONHighlighter()
text = highlighter(j)
text.no_wrap = True
text.overflow = None
return self.write(text, styled=True)

return self.write(json.dumps(data, default=default))
if highlight is None:
highlight = self.isatty()
if indent is None and self.isatty():
indent = 2

console = self.error_console if stderr else self.rich_console
return console.print_json(
data=data,
indent=indent,
highlight=bool(highlight),
skip_keys=skip_keys,
ensure_ascii=ensure_ascii,
check_circular=check_circular,
allow_nan=allow_nan,
default=default,
sort_keys=sort_keys,
)

def write(
self,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ install_requires =
pygtrie>=2.3.2
dpath>=2.0.2,<3
shtab>=1.3.4,<2
rich>=10.9.0
rich>=10.13.0
dictdiffer>=0.8.1
python-benedict>=0.24.2
pyparsing>=2.4.7
Expand Down

0 comments on commit 69b5122

Please sign in to comment.