From 955e57e9666c354f970273ff6aac7bc89884323f Mon Sep 17 00:00:00 2001 From: Etan Joseph Heyman Date: Sat, 1 Aug 2026 23:51:17 +0300 Subject: [PATCH] fix: remove dotenv import from KG rebuild --- scripts/kg_rebuild.py | 4 ---- tests/test_kg_rebuild.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/kg_rebuild.py b/scripts/kg_rebuild.py index d2b289c0..b09643f0 100644 --- a/scripts/kg_rebuild.py +++ b/scripts/kg_rebuild.py @@ -27,10 +27,6 @@ # Add src to path sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src")) -from dotenv import load_dotenv - -load_dotenv(Path(__file__).resolve().parent.parent / ".env") - from brainlayer.paths import get_db_path from brainlayer.pipeline.batch_extraction import DEFAULT_SEED_ENTITIES from brainlayer.pipeline.entity_extraction import ( diff --git a/tests/test_kg_rebuild.py b/tests/test_kg_rebuild.py index c8a89a77..bda54c5c 100644 --- a/tests/test_kg_rebuild.py +++ b/tests/test_kg_rebuild.py @@ -309,3 +309,23 @@ def test_groq_rebuild_entity_payload_preserves_source_subtype(): assert entity.entity_type == "source" assert entity.entity_subtype == "channel" assert entity.start == 6 + + +def test_kg_rebuild_module_import_does_not_require_python_dotenv(monkeypatch): + import builtins + import importlib + import sys + + real_import = builtins.__import__ + + def import_without_dotenv(name, *args, **kwargs): + if name == "dotenv" or name.startswith("dotenv."): + raise ModuleNotFoundError("No module named 'dotenv'") + return real_import(name, *args, **kwargs) + + monkeypatch.setattr(builtins, "__import__", import_without_dotenv) + sys.modules.pop("scripts.kg_rebuild", None) + + module = importlib.import_module("scripts.kg_rebuild") + + assert callable(module.extracted_entity_from_groq_payload)