importsysimportwarningsdefin_notebook():try:fromIPythonimportget_ipythonif"IPKernelApp"notinget_ipython().config:# pragma: no coverreturnFalseexceptImportError:returnFalseexceptAttributeError:returnFalsereturnTruedefin_pytest():return"pytest"insys.modules
[docs]defreport(*message,level=2,ongoing=False,nodes=None,all_nodes=False):""" Send a message to the appropriate output channel. :param message: Text message to send. :type message: str :param level: Verbosity level of the message. :type level: int :param ongoing: The message is part of an ongoing progress report. :type ongoing: bool """from.importoptionsfrom.servicesimportMPImessage=" ".join(map(str,message))rank=MPI.get_rank()if((notrankandnodesisNone)orall_nodesor(nodesisnotNoneandrankinnodes))andoptions.verbosity>=level:print(message,end="\n"ifnotongoingelse"\r",flush=True)
[docs]defwarn(message,category=None,stacklevel=2,log_exc=None):""" Send a warning. :param message: Warning message :type message: str :param category: The class of the warning. """from.importoptionsiflog_exc:importtracebackfrom.storage._utilimportcachelog=f"{message}\n\n{traceback.format_exception(type(log_exc),log_exc,log_exc.__traceback__)}"id=cache.files.store(log)path=cache.files.id_to_file_path(id)message+=f" See '{path}' for full error log."# Avoid infinite loop looking up verbosity when verbosity option is broken.if"Error retrieving option 'verbosity'"inmessageoroptions.verbosity>0:warnings.warn(message,category,stacklevel=stacklevel)