Files
paddlepaddle--paddleocr/tools/resolve_doc_github_refs.py
wehub-resource-sync e904b667c6
PaddleOCR PR Tests GPU / test-pr-gpu (push) Blocked by required conditions
PaddleOCR PR Tests / test-pr (push) Blocked by required conditions
PaddleOCR PR Tests / test-pr-python (3.8) (push) Waiting to run
Build/Publish Develop Docs / deploy (push) Failing after 1s
PaddleOCR Code Style Check / check-code-style (push) Failing after 1s
PaddleOCR PR Tests GPU / detect-changes (push) Failing after 1s
PaddleOCR PR Tests GPU / test-pr-gpu-impl (push) Waiting to run
PaddleOCR PR Tests / detect-changes (push) Failing after 1s
PaddleOCR PR Tests / test-pr-python (3.13) (push) Waiting to run
PaddleOCR PR Tests / test-pr-python (3.9) (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 11:59:26 +08:00

50 lines
1.4 KiB
Python

#!/usr/bin/env python3
import argparse
from pathlib import Path
TEXT_SUFFIXES = {".md", ".yml", ".yaml"}
def resolve_placeholders(root, placeholder, source_ref):
if (
not source_ref
or source_ref.strip() != source_ref
or any(c.isspace() for c in source_ref)
):
raise ValueError("source_ref must be a non-empty ref without whitespace")
root = Path(root)
changed = []
for path in sorted(root.rglob("*")):
if not path.is_file() or path.suffix not in TEXT_SUFFIXES:
continue
content = path.read_text(encoding="utf-8")
if placeholder not in content:
continue
path.write_text(content.replace(placeholder, source_ref), encoding="utf-8")
changed.append(path)
return changed
def main(argv=None):
parser = argparse.ArgumentParser(
description="Resolve docs GitHub source-ref placeholders before building docs."
)
parser.add_argument("--root", default="docs", help="Directory to rewrite.")
parser.add_argument("--placeholder", required=True)
parser.add_argument("--source-ref", required=True)
args = parser.parse_args(argv)
changed = resolve_placeholders(
args.root,
placeholder=args.placeholder,
source_ref=args.source_ref,
)
print(f"Resolved {len(changed)} file(s) under {args.root}.")
return 0
if __name__ == "__main__":
raise SystemExit(main())