MCPcopy Index your code
hub / github.com/mne-tools/mne-python / wrapped_stdout

Function wrapped_stdout

mne/utils/_logging.py:476–500  ·  view source on GitHub ↗

Wrap stdout writes to logger.info, with an optional indent prefix. Parameters ---------- indent : str The indentation to add. cull_newlines : bool If True, cull any new/blank lines at the end.

(indent="", cull_newlines=False)

Source from the content-addressed store, hash-verified

474
475@contextlib.contextmanager
476def wrapped_stdout(indent="", cull_newlines=False):
477 """Wrap stdout writes to logger.info, with an optional indent prefix.
478
479 Parameters
480 ----------
481 indent : str
482 The indentation to add.
483 cull_newlines : bool
484 If True, cull any new/blank lines at the end.
485 """
486 orig_stdout = sys.stdout
487 my_out = ClosingStringIO()
488 sys.stdout = my_out
489 try:
490 yield
491 finally:
492 sys.stdout = orig_stdout
493 pending_newlines = 0
494 for line in my_out.getvalue().split("\n"):
495 if not line.strip() and cull_newlines:
496 pending_newlines += 1
497 continue
498 for _ in range(pending_newlines):
499 logger.info("\n")
500 logger.info(indent + line)
501
502
503def _frame_info(n):

Callers 1

Calls 4

getvalueMethod · 0.95
ClosingStringIOClass · 0.85
splitMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected