Source code for haive.core.utils.debugkit.debug.enhanced
"""Enhanced Debugging UtilitiesProvides icecream-style debugging with beautiful output and context detection."""importinspectfrompathlibimportPathfromtypingimportAnytry:importicecreamHAS_ICECREAM=TrueexceptImportError:HAS_ICECREAM=Falsetry:importrich# noqa: F401HAS_RICH=TrueexceptImportError:HAS_RICH=False
[docs]deffallback_ice(*args):"""Fallback icecream implementation when icecream is not available."""ifargs:for_arginargs:passelse:pass
[docs]classEnhancedDebugger:"""Enhanced debugging with icecream-style output."""def__init__(self):self.debug_enabled=Trueself.debug_history:list[dict[str,Any]]=[]
[docs]defice(self,*args,**kwargs)->Any:"""Enhanced print debugging with context (icecream replacement)."""ifnotself.debug_enabled:return# Get caller informationframe=inspect.currentframe().f_backfilename=frame.f_code.co_filenameline_number=frame.f_linenofunction_name=frame.f_code.co_name# Record in historyself.debug_history.append({"type":"ice","file":filename,"line":line_number,"function":function_name,"args":args,"kwargs":kwargs,})# Use icecream if available, otherwise fallbackifHAS_ICECREAM:ifargsorkwargs:combined_args=list(args)forkey,valueinkwargs.items():combined_args.append(f"{key}={value}")returnicecream.ic(*combined_args)else:returnicecream.ic()else:# Fallback implementationf"{Path(filename).name}:{line_number} in {function_name}()"ifargs:for_arginargs:passelse:passifkwargs:forkey,valueinkwargs.items():pass