|
| 1 | +import sys |
| 2 | +import zipfile |
| 3 | +import requests |
| 4 | +from pathlib import Path |
| 5 | +import shutil |
| 6 | + |
| 7 | + |
| 8 | +# == USAGE == |
| 9 | +# python3 download_artifacts.py PLATFORM VERSION |
| 10 | +# eg: python3 download_artifacts.py linux_x86_64 "0.5.9" |
| 11 | + |
| 12 | +REPO = "sqliteai/sqlite-vector" |
| 13 | +RELEASE_URL = f"https://github.com/{REPO}/releases/download" |
| 14 | + |
| 15 | +# Map Python plat_name to artifact names |
| 16 | +ARTIFACTS = { |
| 17 | + "manylinux2014_x86_64": ["vector-linux-x86_64"], |
| 18 | + "manylinux2014_aarch64": [ |
| 19 | + "vector-linux-arm64", |
| 20 | + ], |
| 21 | + "win_amd64": ["vector-windows-x86_64"], |
| 22 | + "macosx_10_9_x86_64": ["vector-macos"], |
| 23 | + "macosx_11_0_arm64": ["vector-macos"], |
| 24 | +} |
| 25 | + |
| 26 | +BINARY_NAME = { |
| 27 | + "manylinux2014_x86_64": "vector.so", |
| 28 | + "manylinux2014_aarch64": "vector.so", |
| 29 | + "win_amd64": "vector.dll", |
| 30 | + "macosx_10_9_x86_64": "vector.dylib", |
| 31 | + "macosx_11_0_arm64": "vector.dylib", |
| 32 | +} |
| 33 | + |
| 34 | +BINARIES_DIR = Path(__file__).parent / "src/sqlite-vector/binaries" |
| 35 | + |
| 36 | + |
| 37 | +def download_and_extract(artifact_name, bin_name, version): |
| 38 | + artifact = f"{artifact_name}-{version}.zip" |
| 39 | + url = f"{RELEASE_URL}/{version}/{artifact}" |
| 40 | + print(f"Downloading {url}") |
| 41 | + |
| 42 | + r = requests.get(url) |
| 43 | + if r.status_code != 200: |
| 44 | + print(f"Failed to download {artifact}: {r.status_code}") |
| 45 | + sys.exit(1) |
| 46 | + |
| 47 | + zip_path = BINARIES_DIR / artifact |
| 48 | + with open(zip_path, "wb") as f: |
| 49 | + f.write(r.content) |
| 50 | + |
| 51 | + out_dir = BINARIES_DIR |
| 52 | + out_dir.mkdir(parents=True, exist_ok=True) |
| 53 | + |
| 54 | + with zipfile.ZipFile(zip_path, "r") as zip_ref: |
| 55 | + for member in zip_ref.namelist(): |
| 56 | + if member.endswith(bin_name): |
| 57 | + zip_ref.extract(member, out_dir) |
| 58 | + |
| 59 | + # Move to expected name/location |
| 60 | + src = out_dir / member |
| 61 | + dst = out_dir / bin_name |
| 62 | + src.rename(dst) |
| 63 | + |
| 64 | + print(f"Extracted {dst}") |
| 65 | + |
| 66 | + zip_path.unlink() |
| 67 | + |
| 68 | + |
| 69 | +def main(): |
| 70 | + version = None |
| 71 | + platform = None |
| 72 | + if len(sys.argv) == 3: |
| 73 | + platform = sys.argv[1].lower() |
| 74 | + version = sys.argv[2] |
| 75 | + |
| 76 | + if not version or not platform: |
| 77 | + print( |
| 78 | + 'Error: Version is not specified.\nUsage: \n python3 download_artifacts.py linux_x86_64 "0.5.9"' |
| 79 | + ) |
| 80 | + sys.exit(1) |
| 81 | + |
| 82 | + print(BINARIES_DIR) |
| 83 | + if BINARIES_DIR.exists(): |
| 84 | + shutil.rmtree(BINARIES_DIR) |
| 85 | + BINARIES_DIR.mkdir(parents=True, exist_ok=True) |
| 86 | + |
| 87 | + platform_artifacts = ARTIFACTS.get(platform, []) |
| 88 | + if not platform_artifacts: |
| 89 | + print(f"Error: Unknown platform '{platform}'") |
| 90 | + sys.exit(1) |
| 91 | + |
| 92 | + for artifact_name in platform_artifacts: |
| 93 | + download_and_extract(artifact_name, BINARY_NAME[platform], version) |
| 94 | + |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + main() |
0 commit comments