Run the API surface check. Returns exit code.
(open_source_root: Path, strict: bool = False)
| 167 | |
| 168 | |
| 169 | def check(open_source_root: Path, strict: bool = False) -> int: |
| 170 | """Run the API surface check. Returns exit code.""" |
| 171 | if not BASELINE_PATH.exists(): |
| 172 | print(f"{RED}No baseline found at {BASELINE_PATH}{RESET}") |
| 173 | print("Run with --update to generate one.") |
| 174 | return 1 |
| 175 | |
| 176 | baseline = json.loads(BASELINE_PATH.read_text()) |
| 177 | current = extract_api(open_source_root) |
| 178 | |
| 179 | all_warnings = [] |
| 180 | all_errors = [] |
| 181 | |
| 182 | # Interfaces |
| 183 | print(f"\n{BOLD}Checking interfaces...{RESET}") |
| 184 | w, e = _diff_interfaces( |
| 185 | baseline.get("interfaces", {}), current.get("interfaces", {}) |
| 186 | ) |
| 187 | all_warnings.extend(w) |
| 188 | all_errors.extend(e) |
| 189 | |
| 190 | # Type aliases |
| 191 | print(f"{BOLD}Checking type aliases...{RESET}") |
| 192 | w, e = _diff_dict(baseline.get("types", {}), current.get("types", {}), "type") |
| 193 | all_warnings.extend(w) |
| 194 | all_errors.extend(e) |
| 195 | |
| 196 | # Enums |
| 197 | print(f"{BOLD}Checking enums...{RESET}") |
| 198 | b_enums_flat = {} |
| 199 | c_enums_flat = {} |
| 200 | for ename, members in baseline.get("enums", {}).items(): |
| 201 | for mname, mval in members.items(): |
| 202 | b_enums_flat[f"{ename}.{mname}"] = mval |
| 203 | for ename, members in current.get("enums", {}).items(): |
| 204 | for mname, mval in members.items(): |
| 205 | c_enums_flat[f"{ename}.{mname}"] = mval |
| 206 | w, e = _diff_dict(b_enums_flat, c_enums_flat, "enum member") |
| 207 | all_warnings.extend(w) |
| 208 | all_errors.extend(e) |
| 209 | |
| 210 | # Classes |
| 211 | print(f"{BOLD}Checking classes...{RESET}") |
| 212 | w, e = _diff_classes(baseline.get("classes", {}), current.get("classes", {})) |
| 213 | all_warnings.extend(w) |
| 214 | all_errors.extend(e) |
| 215 | |
| 216 | # Report |
| 217 | print() |
| 218 | if all_errors: |
| 219 | print(f"{RED}{BOLD}Breaking changes detected (removals):{RESET}") |
| 220 | for msg in all_errors: |
| 221 | error(msg) |
| 222 | print() |
| 223 | |
| 224 | if all_warnings: |
| 225 | print(f"{YELLOW}{BOLD}API additions/modifications detected:{RESET}") |
| 226 | for msg in all_warnings: |
no test coverage detected