-
Notifications
You must be signed in to change notification settings - Fork 382
feat: Lazily resolve config file & load dotenv earlier #1422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,8 @@ | |||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| import os | ||||||||||||
|
|
||||||||||||
| from utils.logging_config import get_logger | ||||||||||||
| logger = get_logger(__name__) | ||||||||||||
|
|
||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||
| # Documents directory | ||||||||||||
|
|
@@ -17,6 +18,7 @@ def get_documents_path() -> str: | |||||||||||
| Environment variable: OPENRAG_DOCUMENTS_PATH | ||||||||||||
| Default: ``openrag-documents`` (relative to the working directory) | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"OPENRAG_DOCUMENTS_PATH: {os.getenv('OPENRAG_DOCUMENTS_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_DOCUMENTS_PATH") or "openrag-documents" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -29,6 +31,7 @@ def get_keys_path() -> str: | |||||||||||
| Environment variable: OPENRAG_KEYS_PATH | ||||||||||||
| Default: ``keys`` (relative to the working directory) | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"OPENRAG_KEYS_PATH: {os.getenv('OPENRAG_KEYS_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_KEYS_PATH") or "keys" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -41,6 +44,7 @@ def get_flows_path() -> str: | |||||||||||
| Environment variable: OPENRAG_FLOWS_PATH | ||||||||||||
| Default: ``flows`` (relative to the working directory) | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"OPENRAG_FLOWS_PATH: {os.getenv('OPENRAG_FLOWS_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_FLOWS_PATH") or "flows" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -50,6 +54,7 @@ def get_flows_backup_path() -> str: | |||||||||||
| Environment variable: OPENRAG_FLOWS_BACKUP_PATH | ||||||||||||
| Default: ``<flows_path>/backup`` | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"OPENRAG_FLOWS_BACKUP_PATH: {os.getenv('OPENRAG_FLOWS_BACKUP_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_FLOWS_BACKUP_PATH") or os.path.join(get_flows_path(), "backup") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -62,11 +67,14 @@ def get_config_path() -> str: | |||||||||||
| Environment variable: OPENRAG_CONFIG_PATH | ||||||||||||
| Default: ``config`` (relative to the working directory) | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| logger.debug(f"OPENRAG_CONFIG_PATH: {os.getenv('OPENRAG_CONFIG_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_CONFIG_PATH") or "config" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def get_config_file_path() -> str: | ||||||||||||
| """Return the full path to the config.yaml file.""" | ||||||||||||
| logger.debug(f"get_config_file_path: {os.path.join(get_config_path(), 'config.yaml')}") | ||||||||||||
| return os.path.join(get_config_path(), "config.yaml") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -79,6 +87,7 @@ def get_data_path() -> str: | |||||||||||
| Environment variable: OPENRAG_DATA_PATH | ||||||||||||
| Default: ``data`` (relative to the working directory) | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"OPENRAG_DATA_PATH: {os.getenv('OPENRAG_DATA_PATH')}") | ||||||||||||
| return os.getenv("OPENRAG_DATA_PATH") or "data" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
|
|
@@ -90,4 +99,5 @@ def get_data_file(filename: str) -> str: | |||||||||||
| get_data_file("conversations.json") | ||||||||||||
| # → "data/conversations.json" (or $OPENRAG_DATA_PATH/conversations.json) | ||||||||||||
| """ | ||||||||||||
| logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}") | ||||||||||||
| return os.path.join(get_data_path(), filename) | ||||||||||||
|
Comment on lines
+102
to
103
|
||||||||||||
| logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}") | |
| return os.path.join(get_data_path(), filename) | |
| data_path = get_data_path() | |
| logger.debug(f"get_data_file: {os.path.join(data_path, filename)}") | |
| return os.path.join(data_path, filename) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,3 @@ | ||||||||||||||||||||||||||
| from config.paths import get_flows_path | ||||||||||||||||||||||||||
| import asyncio | ||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||
| import threading | ||||||||||||||||||||||||||
|
|
@@ -8,6 +7,15 @@ | |||||||||||||||||||||||||
| import httpx | ||||||||||||||||||||||||||
| from agentd.patch import patch_openai_with_mcp | ||||||||||||||||||||||||||
| from dotenv import load_dotenv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| from dotenv import load_dotenv | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| from dotenv import load_dotenv |
Copilot
AI
Apr 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple duplicated imports introduced here (e.g., get_env_int/get_env_float and httpx are imported twice). This will trip linters and makes the import ordering harder to reason about; please deduplicate and keep a single import for each symbol/module.
| from dotenv import load_dotenv | |
| load_dotenv(override=False) | |
| load_dotenv("../", override=False) | |
| from config.paths import get_flows_path | |
| from utils.env_utils import get_env_int, get_env_float | |
| import httpx | |
| load_dotenv(override=False) | |
| load_dotenv("../", override=False) | |
| from config.paths import get_flows_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_config_file_path()currently callsget_config_path()twice (once inside the debug f-string and again for the return). That duplicates env lookups and will also emit duplicate debug logs. Please compute the config dir/path once in a local variable and reuse it for both logging and the return value.