mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-02-17 01:51:40 -05:00
13 lines
559 B
Python
13 lines
559 B
Python
import difflib, logging
|
|
from tinygrad.helpers import colored, getenv
|
|
|
|
def print_diff(s0, s1, unified=getenv("UNIFIED_DIFF",1)):
|
|
if not logging.getLogger().hasHandlers(): logging.basicConfig(level=logging.INFO, format="%(message)s")
|
|
if unified:
|
|
lines = list(difflib.unified_diff(str(s0).splitlines(), str(s1).splitlines()))
|
|
diff = "\n".join(colored(line, "red" if line.startswith("-") else "green" if line.startswith("+") else None) for line in lines)
|
|
else:
|
|
import ocdiff
|
|
diff = ocdiff.console_diff(str(s0), str(s1))
|
|
logging.info(diff)
|