diff --git a/src/tools.py b/src/tools.py index 8d6b5faa0c8b5fc70a32489fd234b52ecf2e0e69..5d4e954b8939d5f83ffe617f083407ddac10c16c 100644 --- a/src/tools.py +++ b/src/tools.py @@ -1,6 +1,11 @@ # -*- coding: utf-8 -*- import time + +from colorama import Fore +from colorama import Back +from colorama import Style + from functools import ( reduce, partial, wraps ) @@ -23,7 +28,7 @@ def display_timers(): global _timers global _calls - print(" +---------------------------------------------------------Timers--+") + print(f" +--{Fore.BLUE}Timers{Style.RESET_ALL}---------------------------------------------------------+") lst = sorted( map( @@ -35,7 +40,7 @@ def display_timers(): ) for func, time, calls in lst: - print(f" | {func:<32} | {time:>10.6f} sec | {calls:>5} calls |") + print(f" | {Fore.GREEN}{func:<32}{Style.RESET_ALL} | {time:>10.6f} sec | {calls:>5} calls |") print(" +-----------------------------------------------------------------+") @@ -65,6 +70,28 @@ def timer(func): return wrapper +######### +# DEBUG # +######### + +def trace(func): + @wraps(func) + def wrapper(*args, **kwargs): + t = time.ctime() + head = f"[{Fore.BLUE}TRACE{Style.RESET_ALL}]" + c = f"{head}[{t}] Call {func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}({args}, {kwargs})" + print(c) + + value = func(*args, **kwargs) + + t = time.ctime() + r = f"{head}[{t}] Return {func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}" + print(r) + + return value + + return wrapper + ################ # OTHERS TOOLS # ################