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
|
chunk_overlap: int = 100
|
||||||
file_patterns: list[str] = field(default_factory=lambda: ["*.md"])
|
file_patterns: list[str] = field(default_factory=lambda: ["*.md"])
|
||||||
deny_dirs: list[str] = field(
|
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)
|
allow_dirs: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SecurityConfig:
|
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(
|
sensitive_sections: list[str] = field(
|
||||||
default_factory=lambda: ["#mentalhealth", "#physicalhealth", "#Relations"]
|
default_factory=lambda: ["#mentalhealth", "#physicalhealth", "#Relations"]
|
||||||
)
|
)
|
||||||
@@ -73,11 +81,15 @@ class ObsidianRagConfig:
|
|||||||
|
|
||||||
def _resolve_data_dir() -> Path:
|
def _resolve_data_dir() -> Path:
|
||||||
"""Resolve the data directory: dev (project root/obsidian-rag/) or production (~/.obsidian-rag/)."""
|
"""Resolve the data directory: dev (project root/obsidian-rag/) or production (~/.obsidian-rag/)."""
|
||||||
dev_data_dir = DEFAULT_CONFIG_DIR / "obsidian-rag"
|
import os as osmod
|
||||||
if dev_data_dir.exists() or (DEFAULT_CONFIG_DIR / "KnowledgeVault").exists():
|
|
||||||
|
# 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
|
return dev_data_dir
|
||||||
# Production: ~/.obsidian-rag/
|
# 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:
|
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:
|
def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
||||||
"""Shallow-merge a dict into a dataclass instance."""
|
"""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
|
# It's a dataclass instance — merge fields
|
||||||
if hasattr(default, "__dataclass_fields__"):
|
if hasattr(default, "__dataclass_fields__"):
|
||||||
fields = {}
|
fields = {}
|
||||||
@@ -113,7 +127,9 @@ def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
|||||||
if key in default.__dataclass_fields__:
|
if key in default.__dataclass_fields__:
|
||||||
field_def = default.__dataclass_fields__[key]
|
field_def = default.__dataclass_fields__[key]
|
||||||
actual_default = field_def.default
|
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
|
# Enum fields need special handling
|
||||||
fields[key] = val
|
fields[key] = val
|
||||||
elif isinstance(val, dict):
|
elif isinstance(val, dict):
|
||||||
@@ -130,17 +146,23 @@ def _merge(default: Any, overrides: dict[str, Any]) -> Any:
|
|||||||
|
|
||||||
def resolve_vault_path(config: ObsidianRagConfig) -> Path:
|
def resolve_vault_path(config: ObsidianRagConfig) -> Path:
|
||||||
"""Resolve vault_path relative to project root or as absolute."""
|
"""Resolve vault_path relative to project root or as absolute."""
|
||||||
|
import os as osmod
|
||||||
|
|
||||||
|
cwd = Path(osmod.getcwd())
|
||||||
vp = Path(config.vault_path)
|
vp = Path(config.vault_path)
|
||||||
if vp.is_absolute():
|
if vp.is_absolute():
|
||||||
return vp
|
return vp
|
||||||
# Resolve relative to project root
|
# Resolve relative to project root
|
||||||
return (DEFAULT_CONFIG_DIR / vp).resolve()
|
return (cwd / vp).resolve()
|
||||||
|
|
||||||
|
|
||||||
def resolve_vector_db_path(config: ObsidianRagConfig) -> Path:
|
def resolve_vector_db_path(config: ObsidianRagConfig) -> Path:
|
||||||
"""Resolve vector store path relative to data directory."""
|
"""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)
|
vsp = Path(config.vector_store.path)
|
||||||
if vsp.is_absolute():
|
if vsp.is_absolute():
|
||||||
return vsp
|
return vsp
|
||||||
return (data_dir / vsp).resolve()
|
return (data_dir / vsp).resolve()
|
||||||
|
|||||||
Reference in New Issue
Block a user