35
35
class suppress_stdout_stderr :
36
36
'''
37
37
Code source:
38
- https://stackoverflow.com/questions/11130156/suppress-stdout-stderr-print-from-python-functions
38
+ https://stackoverflow.com/questions/11130156/
39
39
40
40
A context manager for doing a "deep suppression" of stdout and stderr in
41
41
Python, i.e. will suppress all print, even if the print originates in a
@@ -50,7 +50,7 @@ class suppress_stdout_stderr:
50
50
51
51
'''
52
52
def __init__ (self ):
53
- self .null_fds = [os .open (os .devnull , os .O_RDWR ) for x in range (2 )]
53
+ self .null_fds = [os .open (os .devnull , os .O_WRONLY ) for x in range (2 )]
54
54
self .save_fds = [os .dup (1 ), os .dup (2 )]
55
55
56
56
def __enter__ (self ):
@@ -210,9 +210,8 @@ def parse_RST(rst_file: str) -> docutils.nodes.document:
210
210
# Initialize an empty document tree with the default settings from above
211
211
document = docutils .utils .new_document ('Document' , settings )
212
212
213
- # Parse input into an RST doctree, suppressing any stdout from parse method
214
- with suppress_stdout_stderr ():
215
- parser .parse (input , document )
213
+ # Parse input into an RST doctree, suppressing any stderr from parse method
214
+ parser .parse (input , document )
216
215
217
216
# Return the root node of the document tree
218
217
return document
@@ -423,8 +422,9 @@ def main(source_paths: List[str], output_format: str) -> bool:
423
422
directory_list = find_rst_files (source_paths )
424
423
425
424
# Fill the bad_title_dict, which contains all incorrectly capitalized headings
426
- for filename in directory_list :
427
- fill_bad_title_dict (filename )
425
+ with suppress_stdout_stderr ():
426
+ for filename in directory_list :
427
+ fill_bad_title_dict (filename )
428
428
429
429
# Return an exit status of 0 if there are no bad titles in the dictionary
430
430
if (len (bad_title_dict ) == 0 ):
0 commit comments