Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

fix: update handling of engine version in tests and add blob management in Needle class

HenryNdubuakudd8179d13d2a
diff --git a/doc/apis.md b/doc/apis.md
index b2bec75..6be0929 100644
--- a/doc/apis.md
+++ b/doc/apis.md
@@ -160,4 +160,4 @@ The engine is fetched once and cached at `~/.cache/cactus-needle/<engine version
2. Copy the file to the same cache path on the device, or drop it inside the installed `needle/` package directory, which wins over the cache.
3. Set `NEEDLE_LIB_PATH=/path/to/libneedle.so` to load exactly that file and skip every lookup.
-The Python package itself installs offline the standard way: `pip download cactus-needle` on a connected machine, then `pip install --no-index --find-links <dir> cactus-needle` on the device.
+The Python package itself installs offline the standard way: `pip download cactus-needle` on a connected machine, then `pip install --no-index --find-links <dir> cactus-needle` on the device. On a device that must never attempt the network, also set `HF_HUB_OFFLINE=1` so a missing engine fails fast with a clear error instead of trying to download.
diff --git a/needle/__init__.py b/needle/__init__.py
index 16c93c2..0ba6fee 100644
--- a/needle/__init__.py
+++ b/needle/__init__.py
@@ -31,6 +31,7 @@ def _library_path():
_lib_handle = None
_active = None
_active_weights = None
+_active_blob = None
def _lib():
@@ -65,12 +66,13 @@ class Needle:
self._bind()
def _bind(self):
- global _active, _active_weights
+ global _active, _active_weights, _active_blob
if _active is self:
return
if self._weights and _active_weights != self._weights:
with open(self._weights, "rb") as handle:
blob = handle.read()
+ _active_blob = blob
if _lib().needle_load(blob, len(blob)) != 0:
raise RuntimeError(
f"failed to load weights from {self._weights} - the .cact "
diff --git a/tests/conftest.py b/tests/conftest.py
index 5fb0b67..ad2bb2e 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -11,7 +11,7 @@ def _engine_available():
here = os.path.dirname(needle.__file__)
name = fetch._lib_name()
cache = os.path.join(os.path.expanduser("~"), ".cache",
- "cactus-needle", needle.__version__, name)
+ "cactus-needle", fetch.ENGINE_VERSION, name)
return os.path.exists(os.path.join(here, name)) or os.path.exists(cache)
except Exception:
return False