mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
style: auto-fix ruff lint and format for Python 3.12
Run ruff check --fix and ruff format across the repo to fix ~495 auto-fixable lint errors (mostly I001 import sorting) and reformat 225 files to match the py312 target. Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
@@ -6,9 +6,9 @@ Downloads and installs sqlite-vec for vector search capabilities.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
import platform
|
||||
import sqlite3
|
||||
import platform
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def get_sqlite_vec_url():
|
||||
"""Get the appropriate sqlite-vec download URL for this platform."""
|
||||
system = platform.system().lower()
|
||||
machine = platform.machine().lower()
|
||||
|
||||
|
||||
# Map platform to sqlite-vec release names
|
||||
if system == "darwin":
|
||||
if machine in ("x86_64", "amd64"):
|
||||
@@ -29,8 +29,10 @@ def get_sqlite_vec_url():
|
||||
elif machine in ("arm64", "aarch64"):
|
||||
return "https://github.com/asg017/sqlite-vec/releases/latest/download/sqlite-vec-v0.1.0-alpha.7-linux-aarch64.tar.gz"
|
||||
elif system == "windows":
|
||||
return "https://github.com/asg017/sqlite-vec/releases/latest/download/sqlite-vec-v0.1.0-alpha.7-windows-x86_64.zip"
|
||||
|
||||
return (
|
||||
"https://github.com/asg017/sqlite-vec/releases/latest/download/sqlite-vec-v0.1.0-alpha.7-windows-x86_64.zip"
|
||||
)
|
||||
|
||||
raise RuntimeError(f"Unsupported platform: {system} {machine}")
|
||||
|
||||
|
||||
@@ -39,36 +41,38 @@ def download_sqlite_vec():
|
||||
try:
|
||||
url = get_sqlite_vec_url()
|
||||
print(f"Downloading sqlite-vec from: {url}")
|
||||
|
||||
|
||||
# Create extension directory
|
||||
ext_dir = Path(__file__).parent / "extensions"
|
||||
ext_dir.mkdir(exist_ok=True)
|
||||
|
||||
|
||||
# Download
|
||||
filename = url.split("/")[-1]
|
||||
local_path = ext_dir / filename
|
||||
|
||||
|
||||
urllib.request.urlretrieve(url, local_path)
|
||||
print(f"Downloaded: {local_path}")
|
||||
|
||||
|
||||
# Extract
|
||||
if filename.endswith(".tar.gz"):
|
||||
import tarfile
|
||||
with tarfile.open(local_path, 'r:gz') as tar:
|
||||
|
||||
with tarfile.open(local_path, "r:gz") as tar:
|
||||
tar.extractall(ext_dir)
|
||||
elif filename.endswith(".zip"):
|
||||
import zipfile
|
||||
with zipfile.ZipFile(local_path, 'r') as zip_ref:
|
||||
|
||||
with zipfile.ZipFile(local_path, "r") as zip_ref:
|
||||
zip_ref.extractall(ext_dir)
|
||||
|
||||
|
||||
# Find the extension file
|
||||
for ext_file in ext_dir.rglob("vec0.*"):
|
||||
if ext_file.suffix in (".so", ".dll", ".dylib"):
|
||||
print(f"Found extension: {ext_file}")
|
||||
return ext_file
|
||||
|
||||
|
||||
raise RuntimeError("Could not find vec0 extension after extraction")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"Failed to download sqlite-vec: {e}")
|
||||
return None
|
||||
@@ -80,21 +84,21 @@ def test_sqlite_vec(extension_path):
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.enable_load_extension(True)
|
||||
conn.load_extension(str(extension_path))
|
||||
|
||||
|
||||
# Test basic functionality
|
||||
conn.execute("CREATE VIRTUAL TABLE test_vec USING vec0(embedding float[3])")
|
||||
conn.execute("INSERT INTO test_vec (embedding) VALUES ('[1,2,3]')")
|
||||
result = conn.execute("SELECT * FROM test_vec").fetchone()
|
||||
|
||||
|
||||
conn.close()
|
||||
|
||||
|
||||
if result:
|
||||
print("✓ sqlite-vec extension is working correctly")
|
||||
return True
|
||||
else:
|
||||
print("✗ sqlite-vec extension test failed")
|
||||
return False
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ sqlite-vec extension test failed: {e}")
|
||||
return False
|
||||
@@ -103,7 +107,7 @@ def test_sqlite_vec(extension_path):
|
||||
def install_sqlite_vec():
|
||||
"""Install sqlite-vec extension."""
|
||||
print("Setting up sqlite-vec extension for vector search...")
|
||||
|
||||
|
||||
# Check if already available
|
||||
try:
|
||||
conn = sqlite3.connect(":memory:")
|
||||
@@ -114,24 +118,25 @@ def install_sqlite_vec():
|
||||
return True
|
||||
except Exception:
|
||||
pass # Extension not available, will download
|
||||
|
||||
|
||||
# Download and install
|
||||
extension_path = download_sqlite_vec()
|
||||
if extension_path and test_sqlite_vec(extension_path):
|
||||
# Create symlink or copy to standard location
|
||||
try:
|
||||
import shutil
|
||||
|
||||
target_dir = Path.home() / ".hanzo" / "extensions"
|
||||
target_dir.mkdir(parents=True, exist_ok=True)
|
||||
target_path = target_dir / extension_path.name
|
||||
|
||||
|
||||
shutil.copy2(extension_path, target_path)
|
||||
print(f"✓ Installed sqlite-vec to: {target_path}")
|
||||
|
||||
|
||||
# Add to environment
|
||||
print("\nTo use sqlite-vec, add this to your environment:")
|
||||
print(f"export SQLITE_VEC_PATH={target_path}")
|
||||
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Warning: Failed to install extension: {e}")
|
||||
@@ -145,4 +150,4 @@ def install_sqlite_vec():
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = install_sqlite_vec()
|
||||
sys.exit(0 if success else 1)
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
Reference in New Issue
Block a user