REQUIRED_KEYS = { "desc", } FORGE_KEYS = { "github", "gitlab", "srht", # source hut, not "~" on the name "bitbucket", } PKG_KEYS = { "pip", "pipx", "cargo", "npm", "hex", } COMMON_KEYS = { "status", # tells it cliget process has been tested on this tool "website", "tags", # may have a typo with "tag" no s "name", # tool name when not exe name "releases", # relases page if not on the forge/pkg } KEYS = REQUIRED_KEYS | FORGE_KEYS | PKG_KEYS | COMMON_KEYS def failed(*m): print(" ERROR: ", *m) def entries_sorted(catalog: dict) -> bool: # or my raise an error ? keys = list(catalog.keys()) for x, y in zip(keys, keys[1:]): if y < x: # TODO should yield failed(x, "before", y) return False return True def required(catalog: dict) -> bool: # or my raise an error ? for k, v in catalog.items(): keys = set(v.keys()) for rkey in REQUIRED_KEYS: if not rkey in keys: failed(k, "has no", rkey) return False return True def only_commons(catalog: dict) -> bool: for k, v in catalog.items(): for vk in v.keys(): if not vk in KEYS: failed(k, "should not have", vk) return False return True RULES = [ # (name, function) pairs ("entries are sorted", entries_sorted), ("required keys are present", required), ("only common keys", only_commons), ] import sys from yaml import safe_load catalog = safe_load(open(sys.argv[1], "rt")) for name, rule in RULES: if rule(catalog): print(name, "OK") else: print(name, "FAIL") break