| |
| import argparse |
| import re |
| from pathlib import Path |
|
|
| try: |
| import yaml |
| except Exception as exc: |
| raise SystemExit(f"PyYAML is required to parse YAML files: {exc}") |
|
|
|
|
| DATASET_ID = "OneScience/proteinmpnn" |
| MODEL_ID = "OneScience/ProteinMPNN" |
| REQUIRED_README_SECTIONS = [ |
| "## OneScience 官方信息", |
| "## 项目说明", |
| "## Resource Card", |
| "## 文件说明", |
| "## Manifest", |
| "## 模型 vs 数据集关系", |
| "## 文件与下载", |
| "## 运行流程", |
| "## 预检与诊断", |
| ] |
| REQUIRED_MANIFEST_KEYS = [ |
| "resource", |
| "platform_resource", |
| "website_integration", |
| "runtime", |
| "onescience", |
| "runtime_package", |
| "files", |
| "relations", |
| "run_matrix", |
| "capabilities", |
| "commands", |
| "expected_outputs", |
| "diagnostics", |
| "domain_extension", |
| ] |
|
|
|
|
| def read_text_checked(path: Path) -> str: |
| raw = path.read_bytes() |
| try: |
| text = raw.decode("utf-8") |
| except UnicodeDecodeError as exc: |
| raise SystemExit(f"{path} is not valid UTF-8: {exc}") from exc |
| bad = [] |
| if "????" in text: |
| bad.append("contains four consecutive question marks") |
| if "\ufffd" in text: |
| bad.append("contains U+FFFD replacement character") |
| if re.search(r"(Ã|Â|Ð|Ñ|锟|鏂|璇|涓)", text): |
| bad.append("contains possible mojibake markers") |
| if bad: |
| raise SystemExit(f"{path} encoding check failed: {', '.join(bad)}") |
| return text |
|
|
|
|
| def cjk_count(text: str) -> int: |
| return sum(1 for ch in text if "\u4e00" <= ch <= "\u9fff") |
|
|
|
|
| def walk_values(obj): |
| if isinstance(obj, dict): |
| for value in obj.values(): |
| yield from walk_values(value) |
| elif isinstance(obj, list): |
| for value in obj: |
| yield from walk_values(value) |
| else: |
| yield obj |
|
|
|
|
| def collect_command_names(commands): |
| names = set() |
| if isinstance(commands, dict): |
| for value in commands.values(): |
| if isinstance(value, list): |
| for item in value: |
| if isinstance(item, dict) and "name" in item: |
| names.add(item["name"]) |
| elif isinstance(value, dict) and "name" in value: |
| names.add(value["name"]) |
| return names |
|
|
|
|
| parser = argparse.ArgumentParser() |
| parser.add_argument("--root", default=".") |
| args = parser.parse_args() |
| root = Path(args.root).resolve() |
|
|
| readme = read_text_checked(root / "README.md") |
| manifest_text = read_text_checked(root / "manifest.yaml") |
| relations_text = read_text_checked(root / "onescience_relations.yaml") |
|
|
| if cjk_count(readme) < 200: |
| raise SystemExit(f"README.md CJK count too low: {cjk_count(readme)}") |
| if cjk_count(manifest_text) < 20: |
| raise SystemExit(f"manifest.yaml CJK count too low: {cjk_count(manifest_text)}") |
| for section in REQUIRED_README_SECTIONS: |
| if section not in readme: |
| raise SystemExit(f"README.md missing section: {section}") |
|
|
| manifest = yaml.safe_load(manifest_text) |
| relations = yaml.safe_load(relations_text) |
| missing = [k for k in REQUIRED_MANIFEST_KEYS if k not in manifest] |
| if missing: |
| raise SystemExit(f"manifest missing keys: {missing}") |
|
|
| if manifest["resource"]["id"] != DATASET_ID: |
| raise SystemExit("manifest resource.id mismatch") |
| primary = manifest["platform_resource"]["primary"] |
| if primary["repo_id"] != DATASET_ID or primary["repo_type"] != "dataset": |
| raise SystemExit("manifest platform_resource.primary mismatch") |
|
|
| all_text = "\n".join([readme, manifest_text, relations_text]) |
| if "Onescience/" in all_text or "onescience/" in all_text: |
| raise SystemExit("found invalid OneScience namespace casing") |
| if " proteinmpnn" in all_text or "`proteinmpnn`" in all_text: |
| pass |
| if "modelscope download --dataset proteinmpnn" in all_text: |
| raise SystemExit("found bare dataset download id") |
| if "modelscope download --dataset OneScience/proteinmpnn" not in all_text: |
| raise SystemExit("missing exact dataset download command") |
| if "OneScience/ProteinMPNN" not in all_text: |
| raise SystemExit("missing compatible model id") |
|
|
| compatible = manifest["relations"].get("compatible_models", []) |
| if not compatible: |
| raise SystemExit("missing relations.compatible_models") |
| for item in compatible: |
| ref = item.get("resource_ref", {}) |
| if ref.get("repo_id") != MODEL_ID or ref.get("repo_type") != "model": |
| raise SystemExit("compatible model resource_ref mismatch") |
|
|
| rel_dataset = relations.get("relations", {}).get("dataset", {}).get("resource_ref", {}) |
| if rel_dataset.get("repo_id") != DATASET_ID: |
| raise SystemExit("onescience_relations dataset repo_id mismatch") |
|
|
| command_names = collect_command_names(manifest.get("commands", {})) |
| if not command_names: |
| raise SystemExit("no named commands found") |
| scenario_refs = [s.get("command_ref") for s in manifest.get("run_matrix", {}).get("scenarios", [])] |
| missing_refs = [ref for ref in scenario_refs if ref and ref not in command_names] |
| if missing_refs: |
| raise SystemExit(f"run_matrix command_refs missing from commands: {missing_refs}") |
|
|
| for value in walk_values(manifest): |
| if isinstance(value, str) and "repo_id" not in value: |
| if "OneScience/proteinmpnn" in value or "OneScience/ProteinMPNN" in value: |
| continue |
|
|
| print("STANDARD_CHECK_OK") |
| print(f"readme_cjk={cjk_count(readme)}") |
| print(f"manifest_cjk={cjk_count(manifest_text)}") |
| print(f"dataset_repo_id={DATASET_ID}") |
| print(f"compatible_model_repo_id={MODEL_ID}") |
| print("command_refs=PASS") |
|
|