fix: use cwd instead of __file__ for config path resolution
Fixes config file not found error when installed via pip
This commit is contained in:
@@ -34,14 +34,22 @@ class IndexingConfig:
|
||||
chunk_overlap: int = 100
|
||||
file_patterns: list[str] = field(default_factory=lambda: ["*.md"])
|
||||
deny_dirs: list[str] = field(
|
||||
default_factory=lambda: [".obsidian", ".trash", "zzz-Archive", ".git", ".logseq"]
|
||||
default_factory=lambda: [
|
||||
".obsidian",
|
||||
".trash",
|
||||
"zzz-Archive",
|
||||
".git",
|
||||
".logseq",
|
||||
]
|
||||
)
|
||||
allow_dirs: list[str] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SecurityConfig:
|
||||
require_confirmation_for: list[str] = field(default_factory=lambda: ["health", "financial_debt"])
|
||||
require_confirmation_for: list[str] = field(
|
||||
default_factory=lambda: ["health", "financial_debt"]
|
||||
)
|
||||
sensitive_sections: list[str] = field(
|
||||
default_factory=lambda: ["#mentalhealth", "#physicalhealth", "#Relations"]
|
||||
)
|
||||
@@ -73,11 +81,15 @@ class ObsidianRagConfig:
|
||||
|
||||
def _resolve_data_dir() -> Path:
|
||||
"""Resolve the data directory: dev (project root/obsidian-rag/) or production (~/.obsidian-rag/)."""
|
||||
dev_data_dir = DEFAULT_CONFIG_DIR / "obsidian-rag"
|
||||
if dev_data_dir.exists() or (DEFAULT_CONFIG_DIR / "KnowledgeVault").exists():
|
||||
import os as osmod
|
||||
|
||||
# Use cwd for dev detection to handle pip install scenarios
|
||||
cwd = Path(osmod.getcwd())
|
||||
dev_data_dir = cwd / "obsidian-rag"
|
||||
if dev_data_dir.exists() or (cwd / "KnowledgeVault").exists():
|
||||
return dev_data_dir
|
||||
# Production: ~/.obsidian-rag/
|
||||
return Path(os.path.expanduser("~/.obsidian-rag"))
|
||||
return Path(osmod.path.expanduser("~/.obsidian-rag"))
|
||||
|
||||
|
||||
def load_config(config_path: str | Path | None = None) -> ObsidianRagConfig:
|
||||
@@ -105,7 +117,9 @@ def load_config(config_path: str | Path | None = None) -> ObsidianRagConfig:
|
||||
|
||||
def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
||||
"""Shallow-merge a dict into a dataclass instance."""
|
||||
if not isinstance(default, type) and not isinstance(default, (list, dict, str, int, float, bool)):
|
||||
if not isinstance(default, type) and not isinstance(
|
||||
default, (list, dict, str, int, float, bool)
|
||||
):
|
||||
# It's a dataclass instance — merge fields
|
||||
if hasattr(default, "__dataclass_fields__"):
|
||||
fields = {}
|
||||
@@ -113,7 +127,9 @@ def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
||||
if key in default.__dataclass_fields__:
|
||||
field_def = default.__dataclass_fields__[key]
|
||||
actual_default = field_def.default
|
||||
if isinstance(actual_default, type) and issubclass(actual_default, Enum):
|
||||
if isinstance(actual_default, type) and issubclass(
|
||||
actual_default, Enum
|
||||
):
|
||||
# Enum fields need special handling
|
||||
fields[key] = val
|
||||
elif isinstance(val, dict):
|
||||
@@ -130,16 +146,22 @@ def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
||||
|
||||
def resolve_vault_path(config: ObsidianRagConfig) -> Path:
|
||||
"""Resolve vault_path relative to project root or as absolute."""
|
||||
import os as osmod
|
||||
|
||||
cwd = Path(osmod.getcwd())
|
||||
vp = Path(config.vault_path)
|
||||
if vp.is_absolute():
|
||||
return vp
|
||||
# Resolve relative to project root
|
||||
return (DEFAULT_CONFIG_DIR / vp).resolve()
|
||||
return (cwd / vp).resolve()
|
||||
|
||||
|
||||
def resolve_vector_db_path(config: ObsidianRagConfig) -> Path:
|
||||
"""Resolve vector store path relative to data directory."""
|
||||
data_dir = _resolve_data_dir()
|
||||
import os as osmod
|
||||
|
||||
cwd = Path(osmod.getcwd())
|
||||
data_dir = cwd / "obsidian-rag"
|
||||
vsp = Path(config.vector_store.path)
|
||||
if vsp.is_absolute():
|
||||
return vsp
|
||||
|
||||
Reference in New Issue
Block a user