globals().update({color: lambda text, ansi=91+i: f'\x1b[{ansi}m{text}\x1b[0m' for i, color in enumerate('red green yellow blue magenta cyan'.split())}) print(red('hello'), green('world')) 'sync' def Sync(): import os, sys, asyncio, functools 'nest_asyncio' in sys.modules or os.system('pip install -q nest_asyncio') __import__('nest_asyncio').apply(); return lambda func: functools.wraps(func)( lambda *args, **kwargs: asyncio.run(func(*args, **kwargs))) sync = Sync() '' import os, asyncio, contextlib, multiprocessing, threading from inspect import iscoroutinefunction def go(func, *args, **kwargs): if iscoroutinefunction(func): target = lambda: asyncio.runners.run(func(*args, **kwargs)) else: target = lambda: func(*args, **kwargs) multiprocessing.Process(target=target).start() unsafe = contextlib.suppress(Exception) with unsafe: asyncio.get_running_loop() asyncio.run = lambda main: threading.Thread( target=lambda: asyncio.runners.run(main)).start() os.environ['DISPLAY'] = ':0' import rich, rich.theme, rich.traceback console = rich.console.Console(width=75, theme=rich.theme.Theme({ 'inspect.callable': 'bold color(114)', # inspect 'inspect.attr': 'white', 'inspect.help': 'white', 'inspect.def': 'color(69)', 'inspect.class': 'color(69)', 'repr.tag_name': 'color(43)', # repr 'repr.tag_contents': 'white', 'repr.bool_true': 'color(77)', # True, False, None 'repr.bool_false': 'color(161)', 'repr.none': 'white', 'repr.attrib_name': 'color(216)', # Name 'repr.call': 'color(111)', 'repr.tag_name': 'color(38)', 'repr.number': 'bold color(113)', 'repr.str': 'color(183)', 'traceback.title': 'color(160)', # Traceback 'traceback.exc_type': 'color(160)', 'traceback.border': 'color(203)', 'traceback.error': 'white', 'traceback.border.syntax_error': 'white', 'traceback.text': 'white', 'traceback.exc_value': 'white', 'traceback.offset': 'white', 'scope.border': 'color(111)'})) rich.traceback.install(console=console) def inspect(obj): rich.inspect(obj, methods=True, console=console)