()
| 80 | |
| 81 | |
| 82 | def ensure_pagefind() -> PurePath: |
| 83 | pagefind_exe_path = PEX_DEV_DIR / pagefind_executable() |
| 84 | if pagefind_exe_path.is_file() and os.access(pagefind_exe_path, os.R_OK | os.X_OK): |
| 85 | return pagefind_exe_path |
| 86 | |
| 87 | tmp_dir = PEX_DEV_DIR / ".tmp" |
| 88 | tmp_dir.mkdir(parents=True, exist_ok=True) |
| 89 | download_dir = Path(tempfile.mktemp(prefix="download-pagefind.", dir=tmp_dir)) |
| 90 | atexit.register(shutil.rmtree, str(download_dir), ignore_errors=True) |
| 91 | |
| 92 | tarball_url = ( |
| 93 | f"https://github.com/CloudCannon/pagefind/releases/download/v{PAGEFIND_VERSION}/" |
| 94 | f"{PAGEFIND_NAME}-v{PAGEFIND_VERSION}-{target_triple()}.tar.gz" |
| 95 | ) |
| 96 | out_path = download_dir / PurePath(unquote(urlparse(tarball_url).path)).name |
| 97 | out_path.parent.mkdir(parents=True, exist_ok=True) |
| 98 | with httpx.stream("GET", tarball_url, follow_redirects=True) as response, out_path.open( |
| 99 | "wb" |
| 100 | ) as out_fp: |
| 101 | for chunk in response.iter_bytes(): |
| 102 | out_fp.write(chunk) |
| 103 | pagefind_exe = CURRENT_PLATFORM.binary_name(PAGEFIND_NAME) |
| 104 | with tarfile.open(out_path) as tf: |
| 105 | tf.extract(pagefind_exe, path=str(download_dir)) |
| 106 | (download_dir / pagefind_exe).rename(pagefind_exe_path) |
| 107 | |
| 108 | return pagefind_exe_path |
| 109 | |
| 110 | |
| 111 | def execute_pagefind(args: Iterable[str]) -> None: |
no test coverage detected