Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions inference/stages/load_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ def _verify_arctic_fresh(universe_lib, date_str: str) -> None:


def _connect_arctic(bucket: str) -> "tuple[object, object]":
"""Open the ArcticDB universe + macro libraries. Hard-fail on unreachable."""
region = os.environ.get("AWS_REGION", "us-east-1")
uri = f"s3s://s3.{region}.amazonaws.com:{bucket}?path_prefix=arcticdb&aws_auth=true"
"""Open the ArcticDB universe + macro libraries. Hard-fail on unreachable.

Delegates to ``alpha_engine_lib.arcticdb.open_universe_lib`` /
``open_macro_lib`` (L2771 chokepoint). ``PipelineAbort`` is preserved
on the failure path so existing pipeline-level except handlers stay
correctly typed.
"""
from alpha_engine_lib.arcticdb import open_universe_lib, open_macro_lib
try:
arctic = adb.Arctic(uri)
return arctic.get_library("universe"), arctic.get_library("macro")
return open_universe_lib(bucket), open_macro_lib(bucket)
except Exception as exc:
raise PipelineAbort(
f"ArcticDB unreachable at {uri}: {exc}"
) from exc
raise PipelineAbort(str(exc)) from exc


def load_price_data_from_arctic(
Expand Down
10 changes: 2 additions & 8 deletions inference/stages/run_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,8 @@ def _load_precomputed_features_from_arcticdb(
inline compute_features. Those fallbacks masked a ``_run_gbm_inference``
miswiring where ArcticDB was never actually consulted in production.
"""
region = os.environ.get("AWS_REGION", "us-east-1")
uri = f"s3s://s3.{region}.amazonaws.com:{ctx.bucket}?path_prefix=arcticdb&aws_auth=true"
try:
universe = adb.Arctic(uri).get_library("universe")
except Exception as exc:
raise RuntimeError(
f"ArcticDB universe library unreachable at {uri}: {exc}"
) from exc
from alpha_engine_lib.arcticdb import open_universe_lib
universe = open_universe_lib(ctx.bucket)

precomputed: dict[str, pd.Series] = {}
n_err = 0
Expand Down
5 changes: 2 additions & 3 deletions scripts/dry_run_meta_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ def pull_from_arcticdb(local_dir: Path) -> int:
import pandas as pd
import boto3

region = os.environ.get("AWS_REGION", "us-east-1")
uri = f"s3s://s3.{region}.amazonaws.com:{BUCKET}?path_prefix={ARCTIC_PREFIX}&aws_auth=true"
arctic = _adb.Arctic(uri)
from alpha_engine_lib.arcticdb import open_arctic
arctic = open_arctic(BUCKET)
universe = arctic.get_library("universe")
macro_lib = arctic.get_library("macro")

Expand Down
7 changes: 3 additions & 4 deletions store/arctic_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@


def _get_arctic(bucket: str) -> adb.Arctic:
"""Create ArcticDB connection."""
region = os.environ.get("AWS_REGION", "us-east-1")
uri = f"s3s://s3.{region}.amazonaws.com:{bucket}?path_prefix={ARCTIC_PREFIX}&aws_auth=true"
return adb.Arctic(uri)
"""Create ArcticDB connection via the lib chokepoint (L2771)."""
from alpha_engine_lib.arcticdb import open_arctic
return open_arctic(bucket)


def download_from_arctic(
Expand Down
15 changes: 14 additions & 1 deletion tests/test_arctic_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@

@pytest.fixture
def fake_arcticdb(monkeypatch):
"""Replace store.arctic_reader.adb with a controllable mock."""
"""Replace the ``arcticdb`` module singleton's ``Arctic`` class with a
controllable mock. Patches at the singleton level so BOTH direct
``import arcticdb as adb; adb.Arctic(...)`` callers AND the
``alpha_engine_lib.arcticdb._import_arcticdb()`` lazy-import path
(used by ``open_arctic`` / ``open_universe_lib`` / ``open_macro_lib``)
pick up the mock. Without singleton-level patching, a lib-routed
call would bypass the mock and hit real S3 (post-L2771 chokepoint
migration)."""
import arcticdb as _real_arcticdb
import store.arctic_reader as mod
fake = MagicMock(name="arcticdb")
# Patch on the actual arcticdb module attribute — caught by both
# the consumer's `adb.Arctic(...)` and the lib's `open_arctic(...)`.
monkeypatch.setattr(_real_arcticdb, "Arctic", fake.Arctic)
# Also patch the consumer module's local ``adb`` reference for any
# legacy callers that still use it directly outside of `_get_arctic`.
monkeypatch.setattr(mod, "adb", fake)
return fake

Expand Down
Loading