MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _schema_scoped

Function _schema_scoped

scripts/theme_gate.py:403–424  ·  view source on GitHub ↗

(``settings[]`` ids, ``blocks[].settings[]`` ids) of the ``{% schema %}`` of a Liquid file.

(text: str)

Source from the content-addressed store, hash-verified

401
402
403def _schema_scoped(text: str) -> tuple[set[str], set[str]]:
404 """(``settings[]`` ids, ``blocks[].settings[]`` ids) of the ``{% schema %}`` of a Liquid file."""
405 m = re.search(r"\{%-?\s*schema\s*-?%\}(.*?)\{%-?\s*endschema\s*-?%\}", text, re.S)
406 if not m:
407 return set(), set()
408 try:
409 data = json.loads(m.group(1))
410 except (ValueError, RecursionError):
411 return set(), set()
412
413 def ids(entries: object) -> set[str]:
414 return {
415 e["id"] for e in entries if isinstance(e, dict) and isinstance(e.get("id"), str) and "type" in e
416 } if isinstance(entries, list) else set()
417
418 if not isinstance(data, dict):
419 return set(), set()
420 blocks: set[str] = set()
421 for b in data.get("blocks") if isinstance(data.get("blocks"), list) else []:
422 if isinstance(b, dict):
423 blocks |= ids(b.get("settings"))
424 return ids(data.get("settings")), blocks
425
426
427def _global_setting_ids(root: Path) -> set[str]:

Callers 1

schema_ofFunction · 0.85

Calls 2

idsFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected