Skip to content

Commit

Permalink
Fix: No extensions in some SQLite builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Mar 30, 2024
1 parent c0049ab commit 39264d0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
55 changes: 45 additions & 10 deletions python/scripts/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@
def test_sqlite_minimal_json_cosine_vector_search():
"""Minimal test for searching JSON vectors in an SQLite database."""
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True) # Not available on MacOS with default build
conn.load_extension(usearch.sqlite)

# Loading extensions isn't supported in some SQLite builds,
# including the default one on MacOS
try:
conn.enable_load_extension(True)
except AttributeError:
pytest.skip("SQLite extensions are not available on this platform")
return

conn.load_extension(usearch.sqlite)
cursor = conn.cursor()

# Create a table with a JSON column for vectors
Expand Down Expand Up @@ -56,9 +63,16 @@ def test_sqlite_minimal_json_cosine_vector_search():
def test_sqlite_minimal_text_search():
"""Minimal test for Unicode strings in an SQLite database."""
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True) # Not available on MacOS with default build
conn.load_extension(usearch.sqlite)

# Loading extensions isn't supported in some SQLite builds,
# including the default one on MacOS
try:
conn.enable_load_extension(True)
except AttributeError:
pytest.skip("SQLite extensions are not available on this platform")
return

conn.load_extension(usearch.sqlite)
cursor = conn.cursor()

# Create a table with a TEXT column for strings
Expand Down Expand Up @@ -105,9 +119,16 @@ def test_sqlite_blob_bits_vector_search():
"""Minimal test for searching binary vectors in an SQLite database."""

conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension(usearch.sqlite)

# Loading extensions isn't supported in some SQLite builds,
# including the default one on MacOS
try:
conn.enable_load_extension(True)
except AttributeError:
pytest.skip("SQLite extensions are not available on this platform")
return

conn.load_extension(usearch.sqlite)
cursor = conn.cursor()

# Create a table with a BLOB column for binary vectors
Expand Down Expand Up @@ -161,9 +182,16 @@ def test_sqlite_distances_in_high_dimensions(num_vectors: int, ndim: int):
"""

conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension(usearch.sqlite)

# Loading extensions isn't supported in some SQLite builds,
# including the default one on MacOS
try:
conn.enable_load_extension(True)
except AttributeError:
pytest.skip("SQLite extensions are not available on this platform")
return

conn.load_extension(usearch.sqlite)
cursor = conn.cursor()

# Create a table with additional columns for f32 and f16 BLOBs
Expand Down Expand Up @@ -230,9 +258,16 @@ def test_sqlite_distances_in_low_dimensions(num_vectors: int):

# Setup SQLite connection and enable extensions
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True)
conn.load_extension(usearch.sqlite)

# Loading extensions isn't supported in some SQLite builds,
# including the default one on MacOS
try:
conn.enable_load_extension(True)
except AttributeError:
pytest.skip("SQLite extensions are not available on this platform")
return

conn.load_extension(usearch.sqlite)
cursor = conn.cursor()

# Create a table for storing vectors and their descriptions
Expand Down
4 changes: 2 additions & 2 deletions python/usearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
__version__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}"


class UsearchBinaryManager:
class BinaryManager:
def __init__(self, version: Optional[str] = None):
if version is None:
version = __version__
Expand Down Expand Up @@ -105,5 +105,5 @@ def sqlite_found_or_downloaded(self) -> Optional[str]:


# Use the function to set the `sqlite` computed property
binary_manager = UsearchBinaryManager()
binary_manager = BinaryManager()
sqlite = binary_manager.sqlite_found_or_downloaded

0 comments on commit 39264d0

Please sign in to comment.