from copy import deepcopy from pathlib import Path import hashlib import importlib.util import json import sys def canonical(value): return json.dumps(value,sort_keys=True,ensure_ascii=False,separators=(',',':'),allow_nan=False).encode() def read(path):return json.loads(Path(path).read_text()) def write(path,value): path=Path(path);path.parent.mkdir(parents=True,exist_ok=True) path.write_bytes(canonical(value)+b'\n') def module(name,path): spec=importlib.util.spec_from_file_location(name,path);obj=importlib.util.module_from_spec(spec) sys.modules[name]=obj;spec.loader.exec_module(obj);return obj def equal(a,b): if type(a) is bool or type(b) is bool:return type(a) is type(b) and a==b if isinstance(a,(float,int)) and isinstance(b,(float,int)):return a==b if type(a)!=type(b):return False if isinstance(a,dict):return set(a)==set(b) and all(equal(a[k],b[k]) for k in a) if isinstance(a,list):return len(a)==len(b) and all(equal(x,y) for x,y in zip(a,b)) return a==b