INNER CODE UNIT · Python
asset_path
WenyuChiou/awesome-agentic-ai-zh · scripts/build-role-map.py:71
def asset_path(locale, extension):
return ROOT / f"resources/diagrams/branch-decision-tree{LOCALES[locale][0]}.{extension}"
def import_original(locale):
from PIL import Image
relative = asset_path(locale, "png").relative_to(ROOT).as_posix()
data = subprocess.check_output(["git", "show", f"{SOURCE_COMMIT}:{relative}"], cwd=ROOT)
if hashlib.sha256(data).hexdigest() != SOURCE_HASHES[locale]:
raise ValueError(f"Unexpected source artwork: {locale}")
with Image.open(io.BytesIO(data)) as source:
if source.size != LOCALES[locale][1]:
raise ValueError("Unexpected source canvas")
output = io.BytesIO()
source.save(output, format="WEBP", quality=95, method=6)
return output.getvalue()