Load and query the centralized dependencies manifest.
| 12 | |
| 13 | |
| 14 | class DependencyManifest: |
| 15 | """Load and query the centralized dependencies manifest.""" |
| 16 | |
| 17 | def __init__(self, manifest_path: Optional[Path] = None): |
| 18 | """ |
| 19 | Initialize the dependency manifest. |
| 20 | |
| 21 | Args: |
| 22 | manifest_path: Path to dependencies.json (defaults to ci/dependencies.json) |
| 23 | """ |
| 24 | if manifest_path is None: |
| 25 | # Try multiple locations in order of preference |
| 26 | candidates = [ |
| 27 | Path("ci") / "dependencies.json", # Primary location |
| 28 | Path(".") / "dependencies.json", # Fallback for backward compatibility |
| 29 | ] |
| 30 | |
| 31 | manifest_path = None |
| 32 | for candidate in candidates: |
| 33 | if candidate.exists(): |
| 34 | manifest_path = candidate |
| 35 | break |
| 36 | |
| 37 | if manifest_path is None: |
| 38 | raise FileNotFoundError( |
| 39 | f"dependencies.json not found in any of: {', '.join(str(c) for c in candidates)}" |
| 40 | ) |
| 41 | |
| 42 | if not manifest_path.exists(): |
| 43 | raise FileNotFoundError(f"dependencies.json not found at {manifest_path}") |
| 44 | |
| 45 | self.manifest_path = manifest_path |
| 46 | with open(manifest_path, "r") as f: |
| 47 | self.data = json.load(f) |
| 48 | |
| 49 | def get_globs(self, operation: str) -> list[str]: |
| 50 | """ |
| 51 | Get file patterns (globs) for a given operation. |
| 52 | |
| 53 | Args: |
| 54 | operation: Operation name (e.g., "python_lint", "cpp_lint") |
| 55 | |
| 56 | Returns: |
| 57 | List of glob patterns |
| 58 | |
| 59 | Raises: |
| 60 | KeyError: If operation not found in manifest |
| 61 | """ |
| 62 | if operation not in self.data["operations"]: |
| 63 | raise KeyError( |
| 64 | f"Operation '{operation}' not found in manifest. Available: " |
| 65 | f"{', '.join(self.data['operations'].keys())}" |
| 66 | ) |
| 67 | |
| 68 | return self.data["operations"][operation].get("globs", []) |
| 69 | |
| 70 | def get_excludes(self, operation: str) -> list[str]: |
| 71 | """ |
no outgoing calls