16
16
import rich_click as click
17
17
18
18
import rich .console
19
- import rich .json
20
19
import rich .markdown
21
20
import rich .syntax
22
21
import rich .terminal_theme
@@ -187,37 +186,17 @@ def display_output(
187
186
"checks" : as_simple_dict (processed ),
188
187
}
189
188
if header :
190
- d = {header : d }
191
-
192
- if color and output .isatty ():
193
- j = rich .json .JSON .from_data (d )
194
- console = rich .console .Console (stderr = stderr , color_system = "auto" )
195
- if header :
196
- # We strip off beginning and ending brackets
197
- console .print (j .__rich__ ()[2 :- 2 ], end = "" )
198
- else :
199
- console .print (j )
189
+ print (json .dumps ({header : d }, indent = 2 )[2 :- 2 ], end = "" , file = output )
200
190
else :
201
- # Rich wraps json, which breaks it
202
- if header :
203
- print (json .dumps (d , indent = 2 )[2 :- 2 ])
204
- else :
205
- print (json .dumps (d , indent = 2 ))
191
+ print (json .dumps (d , indent = 2 ), file = output )
192
+
206
193
case "html" :
207
194
html = to_html (families , processed , status )
208
195
if header :
209
196
failures = sum (r .result is False for r in processed )
210
197
status_msg = f"({ failures } failed)" if failures else "(all passed)"
211
198
html = f"<details><summary><h2>{ header } </h2>: { status_msg } </summary>\n { html } </details>\n "
212
- if color and output .isatty ():
213
- # We check isatty even though Rich does too because Rich
214
- # injects a ton of ending whitespace even going to a file
215
- rich .print (
216
- rich .syntax .Syntax (html , lexer = "html" ),
217
- file = output ,
218
- )
219
- else :
220
- print (html , file = output )
199
+ print (html , file = output )
221
200
case _:
222
201
assert_never (format_opt )
223
202
@@ -284,14 +263,10 @@ def main(
284
263
"""
285
264
286
265
if len (packages ) > 1 :
287
- stdout = rich .console .Console (
288
- color_system = "auto" if stderr_fmt is None else None
289
- )
290
- stderr = rich .console .Console (color_system = "auto" , stderr = True )
291
266
if format_opt == "json" :
292
- stdout . print ("{" )
267
+ print ("{" )
293
268
if stderr_fmt == "json" :
294
- stderr . print ("{" )
269
+ print ("{" , file = sys . stderr )
295
270
296
271
result = 0
297
272
for n , package in enumerate (packages ):
@@ -308,15 +283,15 @@ def main(
308
283
if len (packages ) > 1 :
309
284
is_before_end = n < len (packages ) - 1
310
285
if format_opt == "json" :
311
- stdout . print ("," if is_before_end else "" )
286
+ print ("," if is_before_end else "" )
312
287
if stderr_fmt == "json" :
313
- stderr . print ("," if is_before_end else "" )
288
+ print ("," if is_before_end else "" , file = sys . stderr )
314
289
315
290
if len (packages ) > 1 :
316
291
if format_opt == "json" :
317
- stdout . print ("}" )
292
+ print ("}" )
318
293
if stderr_fmt == "json" :
319
- stderr . print ("}" )
294
+ print ("}" , file = sys . stderr )
320
295
321
296
if result :
322
297
raise SystemExit (result )
0 commit comments