From aaa70a6601e4b4e52a1f797bc24f1931e4553fac Mon Sep 17 00:00:00 2001 From: kert Date: Sat, 14 Nov 2026 11:47:42 -0500 Subject: [PATCH] fix(rex): import comment text without the lake store --- src/rex/__init__.py | 16 ++++++++++++++- tests/rex/test_package.py | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/rex/test_package.py diff --git a/src/rex/__init__.py b/src/rex/__init__.py index 607d27b..15831dc 100644 --- a/src/rex/__init__.py +++ b/src/rex/__init__.py @@ -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}") diff --git a/tests/rex/test_package.py b/tests/rex/test_package.py new file mode 100644 index 0000000..f51234b --- /dev/null +++ b/tests/rex/test_package.py @@ -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