Check that a package type-checks no worse at its declared minimums than at latest. Installs the package twice in isolated environments — once with dependencies at their latest compatible versions, once pinned to their declared minimums — and compares pyright errors. Errors present only
(package: Package, python_version: str)
| 431 | |
| 432 | |
| 433 | def check_package(package: Package, python_version: str) -> Result: |
| 434 | """Check that a package type-checks no worse at its declared minimums than at latest. |
| 435 | |
| 436 | Installs the package twice in isolated environments — once with dependencies at their |
| 437 | latest compatible versions, once pinned to their declared minimums — and compares |
| 438 | pyright errors. Errors present only at the minimum versions indicate the code depends |
| 439 | on a newer dependency than its declared lower bound allows. |
| 440 | |
| 441 | Args: |
| 442 | package: The package to validate. |
| 443 | python_version: The interpreter version for the isolated environments. |
| 444 | |
| 445 | Returns: |
| 446 | The result of the check. |
| 447 | """ |
| 448 | with tempfile.TemporaryDirectory(prefix=f"min-deps-{package.name}-") as tmp: |
| 449 | tmp_path = Path(tmp) |
| 450 | config = tmp_path / "pyrightconfig.json" |
| 451 | config.write_text(json.dumps({"reportIncompatibleMethodOverride": False})) |
| 452 | |
| 453 | baseline, detail = _resolve_and_check( |
| 454 | package, python_version, tmp_path / ".venv-latest", config, lowest=False |
| 455 | ) |
| 456 | if baseline is None: |
| 457 | return Result( |
| 458 | package.name, |
| 459 | False, |
| 460 | "resolution", |
| 461 | f"installing latest deps failed:\n{detail}", |
| 462 | ) |
| 463 | |
| 464 | minimum, detail = _resolve_and_check( |
| 465 | package, python_version, tmp_path / ".venv-lowest", config, lowest=True |
| 466 | ) |
| 467 | if minimum is None: |
| 468 | return Result( |
| 469 | package.name, |
| 470 | False, |
| 471 | "resolution", |
| 472 | f"installing minimum deps failed:\n{detail}", |
| 473 | ) |
| 474 | |
| 475 | new_errors = sorted(minimum.keys() - baseline.keys()) |
| 476 | if new_errors: |
| 477 | return Result( |
| 478 | package.name, |
| 479 | False, |
| 480 | "min-version", |
| 481 | "\n".join(minimum[key] for key in new_errors), |
| 482 | ) |
| 483 | |
| 484 | return Result(package.name, True, "ok", "") |
| 485 | |
| 486 | |
| 487 | def check_dev_pins(package_names: list[str]) -> int: |