MCPcopy
hub / github.com/treeverse/dvc / write_json

Method write_json

dvc/ui/__init__.py:96–135  ·  view source on GitHub ↗
(
        self,
        data: Any,
        indent: Optional[int] = None,
        highlight: Optional[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,
    )

Source from the content-addressed store, hash-verified

94 )
95
96 def write_json(
97 self,
98 data: Any,
99 indent: Optional[int] = None,
100 highlight: Optional[bool] = None,
101 stderr: bool = False,
102 skip_keys: bool = False,
103 ensure_ascii: bool = True,
104 check_circular: bool = True,
105 allow_nan: bool = True,
106 default: Optional[Callable[[Any], Any]] = None,
107 sort_keys: bool = False,
108 ) -> None:
109 if highlight is None:
110 highlight = self.isatty()
111 if indent is None and self.isatty():
112 indent = 2
113
114 from rich.json import JSON
115
116 json = JSON.from_data(
117 data=data,
118 indent=indent,
119 highlight=bool(highlight),
120 skip_keys=skip_keys,
121 ensure_ascii=ensure_ascii,
122 check_circular=check_circular,
123 allow_nan=allow_nan,
124 default=default,
125 sort_keys=sort_keys,
126 )
127 if not highlight:
128 import os
129
130 # we don't need colorama to try to strip ansi codes
131 # when highlighting is disabled
132 ctx = nullcontext() if "DVC_TEST" in os.environ else disable_colorama()
133 with ctx:
134 return self.write(json.text, stderr=stderr)
135 return self.rich_print(json, stderr=stderr, soft_wrap=True)
136
137 def rich_print( # noqa: PLR0913
138 self,

Callers 14

test_write_jsonFunction · 0.95
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
_show_jsonFunction · 0.80
runMethod · 0.80
runMethod · 0.80
runMethod · 0.80
_show_listMethod · 0.80
runMethod · 0.80

Calls 4

isattyMethod · 0.95
writeMethod · 0.95
rich_printMethod · 0.95
disable_coloramaFunction · 0.85

Tested by 1

test_write_jsonFunction · 0.76