erinys-memory 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ # erinys_memory package
2
+ __version__ = "0.5.1"
@@ -0,0 +1,50 @@
1
+ """Central sqlite3 implementation selector.
2
+
3
+ sqlite-vec (ERINYS's vector index) needs ``Connection.enable_load_extension``.
4
+ CPython ships that method disabled on some builds — macOS system Python and
5
+ pyenv built without ``--enable-loadable-sqlite-extensions`` are the common
6
+ offenders, while python.org / Homebrew / conda / GitHub Actions builds all
7
+ enable it.
8
+
9
+ **Import ``sqlite3`` from this module** (``from ._sqlite import sqlite3``) rather
10
+ than the standard library directly. Doing so guarantees every module shares one
11
+ implementation, so exception classes (``IntegrityError``, ``OperationalError``,
12
+ ...) are identical across the codebase. If db.py used ``pysqlite3`` while other
13
+ modules caught ``stdlib sqlite3`` errors, those ``except`` clauses would silently
14
+ miss real failures.
15
+
16
+ Selection order:
17
+ 1. stdlib ``sqlite3`` when it can load extensions (the common case);
18
+ 2. ``pysqlite3`` if installed (fallback for extension-disabled builds);
19
+ 3. stdlib ``sqlite3`` otherwise — a clear, actionable error is then raised at
20
+ connection time in ``db._load_sqlite_vec`` rather than a cryptic
21
+ ``AttributeError``.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import sqlite3 as _stdlib_sqlite3
27
+
28
+
29
+ def _select_sqlite3():
30
+ try:
31
+ probe = _stdlib_sqlite3.connect(":memory:")
32
+ try:
33
+ capable = hasattr(probe, "enable_load_extension")
34
+ finally:
35
+ probe.close()
36
+ except Exception:
37
+ capable = False
38
+ if capable:
39
+ return _stdlib_sqlite3
40
+ try:
41
+ import pysqlite3.dbapi2 as _pysqlite3 # type: ignore
42
+
43
+ return _pysqlite3
44
+ except ImportError:
45
+ return _stdlib_sqlite3
46
+
47
+
48
+ sqlite3 = _select_sqlite3()
49
+
50
+ __all__ = ["sqlite3"]