Download laravel/laravel at the pinned tag and install Composer deps. Uses a GitHub tarball (no git required). A pinned ``composer.lock`` (checked into the repo under ``benches/fixtures/laravel/``) is copied into the extracted source *before* ``composer install`` so the exact same d
(work_dir: str)
| 474 | |
| 475 | |
| 476 | def setup_laravel(work_dir: str) -> str: |
| 477 | """Download laravel/laravel at the pinned tag and install Composer deps. |
| 478 | |
| 479 | Uses a GitHub tarball (no git required). A pinned ``composer.lock`` |
| 480 | (checked into the repo under ``benches/fixtures/laravel/``) is |
| 481 | copied into the extracted source *before* ``composer install`` so |
| 482 | the exact same dependency tree is resolved every time. |
| 483 | |
| 484 | Returns the path to the Laravel project root. |
| 485 | """ |
| 486 | import tarfile |
| 487 | import urllib.request |
| 488 | |
| 489 | tarball_path = os.path.join(work_dir, "laravel.tar.gz") |
| 490 | |
| 491 | # Download the tarball. |
| 492 | print(f" Downloading laravel/laravel {LARAVEL_TAG}...", file=sys.stderr) |
| 493 | urllib.request.urlretrieve(LARAVEL_TARBALL, tarball_path) |
| 494 | |
| 495 | # Extract. GitHub tarballs contain a single top-level directory |
| 496 | # named ``laravel-<tag-without-v>/``. |
| 497 | print(" Extracting...", file=sys.stderr) |
| 498 | with tarfile.open(tarball_path, "r:gz") as tar: |
| 499 | tar.extractall(path=work_dir, filter="data") |
| 500 | os.remove(tarball_path) |
| 501 | |
| 502 | # Find the extracted directory (e.g. ``laravel-12.12.2``). |
| 503 | extracted = [ |
| 504 | d for d in os.listdir(work_dir) |
| 505 | if os.path.isdir(os.path.join(work_dir, d)) and d.startswith("laravel-") |
| 506 | ] |
| 507 | if len(extracted) != 1: |
| 508 | raise RuntimeError( |
| 509 | f"Expected exactly one laravel-* directory, found: {extracted}" |
| 510 | ) |
| 511 | laravel_dir = os.path.join(work_dir, extracted[0]) |
| 512 | |
| 513 | # Copy our pinned composer.lock so ``composer install`` resolves |
| 514 | # the exact same versions every run. |
| 515 | lock_src = LARAVEL_LOCK_FIXTURE |
| 516 | if not os.path.isfile(lock_src): |
| 517 | raise FileNotFoundError( |
| 518 | f"Pinned composer.lock not found at {lock_src}. " |
| 519 | "Did you forget to check in benches/fixtures/laravel/composer.lock?" |
| 520 | ) |
| 521 | shutil.copy2(lock_src, os.path.join(laravel_dir, "composer.lock")) |
| 522 | |
| 523 | # Install Composer dependencies from the lock file. |
| 524 | print(" Running composer install...", file=sys.stderr) |
| 525 | subprocess.run( |
| 526 | [ |
| 527 | "composer", "install", |
| 528 | "--no-interaction", |
| 529 | "--no-progress", |
| 530 | "--prefer-dist", |
| 531 | "--quiet", |
| 532 | ], |
| 533 | check=True, |
no test coverage detected