sync_bdd_issues.py
1 #!/usr/bin/env python3 2 """ 3 Thin wrapper around the `radicle-priorities` issue mirror. 4 5 Why this exists: 6 - `radicle-priorities` contains the canonical implementation of syncing pending 7 BDD scenarios -> Radicle issues. 8 - This repo is meant to be easy to operate, so we provide a local entrypoint: 9 10 python3 scripts/sync_bdd_issues.py --dry-run 11 python3 scripts/sync_bdd_issues.py --apply 12 13 The wrapper defaults `--repo` to the current repo root. 14 """ 15 16 from __future__ import annotations 17 18 import os 19 import subprocess 20 import sys 21 from pathlib import Path 22 from typing import List, Optional, Sequence 23 24 25 def _find_radicle_priorities_script(repo_root: Path) -> Optional[Path]: 26 # Expected dev layout: sibling checkout next to this repo. 27 sibling = repo_root.parent / "radicle-priorities" / "scripts" / "sync_bdd_issues.py" 28 if sibling.exists() and sibling.is_file(): 29 return sibling 30 return None 31 32 33 def _run(argv: Sequence[str]) -> int: 34 proc = subprocess.run(list(argv)) 35 return int(proc.returncode) 36 37 38 def main(argv: Optional[List[str]] = None) -> int: 39 repo_root = Path(__file__).resolve().parents[1] 40 target = _find_radicle_priorities_script(repo_root) 41 if target is None: 42 sys.stderr.write( 43 "Could not find `radicle-priorities/scripts/sync_bdd_issues.py` next to this repo.\n" 44 "Expected layout:\n" 45 " <parent>/radicle-native-test-suite/\n" 46 " <parent>/radicle-priorities/\n" 47 "\n" 48 "Either clone `radicle-priorities` next to this repo, or run the script from that repo:\n" 49 " python3 ../radicle-priorities/scripts/sync_bdd_issues.py --repo \"$PWD\" --dry-run\n" 50 ) 51 return 2 52 53 # Pass through args, but pin --repo so the mirror reads/writes bdd/* here. 54 args = list(argv) if argv is not None else sys.argv[1:] 55 cmd = [sys.executable, str(target), "--repo", str(repo_root)] 56 cmd.extend(args) 57 58 # Ensure the underlying script sees the repo root even if it relies on env. 59 os.environ["RADICLE_PRIORITIES_REPO_ROOT"] = str(repo_root) 60 return _run(cmd) 61 62 63 if __name__ == "__main__": 64 raise SystemExit(main()) 65