fix(rex): import comment text without the lake store

This commit is contained in:
kert
2026-11-14 11:47:42 -05:00
parent 7c878b3fc8
commit aaa70a6601
2 changed files with 57 additions and 1 deletions

View File

@@ -39,4 +39,18 @@ from .pipe import ingest as ingest
from .sieve import FieldMap as FieldMap
from .sieve import Sieve as Sieve
from .sieve import Zone as Zone
from .store import Store as Store
def __getattr__(name: str):
"""``Store`` imports fsspec and pyarrow.
The llm image reads comment attachments through ``rex.comments`` and
does not install the rex extra. Loading ``Store`` from the package
root would make that import fail before any text is extracted.
"""
if name == "Store":
from .store import Store
globals()["Store"] = Store
return Store
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

42
tests/rex/test_package.py Normal file
View File

@@ -0,0 +1,42 @@
"""Package import must not pull the lake store.
The llm image extracts comment text and does not install fsspec or
pyarrow. ``rex.comments`` is reached through ``import rex``.
"""
from __future__ import annotations
import os
import subprocess
import sys
from pathlib import Path
def test_comment_extract_does_not_import_the_lake_store():
root = Path(__file__).resolve().parents[2]
env = os.environ.copy()
env["PYTHONPATH"] = str(root / "src")
script = """
import rex
import rex.comments.extract
assert "rex.store" not in sys.modules
assert "fsspec" not in sys.modules
assert "pyarrow" not in sys.modules
try:
rex.definitely_missing
except AttributeError:
pass
else:
raise SystemExit("missing attribute resolved")
from rex import Store
assert Store.__name__ == "Store"
assert "rex.store" in sys.modules
"""
proc = subprocess.run(
[sys.executable, "-c", "import sys\n" + script],
env=env,
capture_output=True,
text=True,
check=False,
)
assert proc.returncode == 0, proc.stdout + proc.stderr