From fe3ffe586015a6e629000c82eeee85f82e94f6e8 Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 26 Mar 2026 09:10:09 -0400 Subject: [PATCH] refactor: extract should_include_path to utils module to resolve circular import between indexer and attachment_indexer --- backend/attachment_indexer.py | 4 ++-- backend/indexer.py | 37 +++-------------------------------- backend/utils.py | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 backend/utils.py diff --git a/backend/attachment_indexer.py b/backend/attachment_indexer.py index 2d36d20..011e912 100644 --- a/backend/attachment_indexer.py +++ b/backend/attachment_indexer.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import Dict, List, Optional, Set import threading -from backend.indexer import _should_include_path +from backend.utils import should_include_path logger = logging.getLogger("obsigate.attachment_indexer") @@ -67,7 +67,7 @@ def _scan_vault_attachments(vault_name: str, vault_path: str, vault_cfg: dict = for fpath in vault_root.rglob("*"): # Check if path should be included based on hidden files configuration rel_parts = fpath.relative_to(vault_root).parts - if not _should_include_path(rel_parts, vault_cfg): + if not should_include_path(rel_parts, vault_cfg): continue # Only process files diff --git a/backend/indexer.py b/backend/indexer.py index 4c7ff11..f41c074 100644 --- a/backend/indexer.py +++ b/backend/indexer.py @@ -9,7 +9,7 @@ from typing import Dict, List, Optional, Any import frontmatter -from backend.attachment_indexer import build_attachment_index +from backend.utils import should_include_path logger = logging.getLogger("obsigate.indexer") @@ -122,38 +122,6 @@ def load_vault_config() -> Dict[str, Dict[str, Any]]: return vaults -def _should_include_path(rel_parts: tuple, vault_config: Dict[str, Any]) -> bool: - """Check if a path should be included based on hidden files configuration. - - Args: - rel_parts: Tuple of path parts relative to vault root - vault_config: Vault configuration dict with includeHidden and hiddenWhitelist - - Returns: - True if the path should be included, False otherwise - """ - include_hidden = vault_config.get("includeHidden", False) - hidden_whitelist = vault_config.get("hiddenWhitelist", []) - - # Check if any part of the path starts with a dot (hidden) - hidden_parts = [part for part in rel_parts if part.startswith(".")] - - if not hidden_parts: - # No hidden parts, always include - return True - - if include_hidden: - # Include all hidden files/folders - return True - - # Check if any hidden part is in the whitelist - for hidden_part in hidden_parts: - if hidden_part in hidden_whitelist: - return True - - # Not in whitelist and includeHidden is False - return False - # Regex for extracting inline #tags from markdown body (excludes code blocks) _INLINE_TAG_RE = re.compile(r'(?:^|\s)#([a-zA-Z][a-zA-Z0-9_/-]{1,50})', re.MULTILINE) @@ -276,7 +244,7 @@ def _scan_vault(vault_name: str, vault_path: str, vault_cfg: Optional[Dict[str, for fpath in vault_root.rglob("*"): # Check if path should be included based on hidden files configuration rel_parts = fpath.relative_to(vault_root).parts - if not _should_include_path(rel_parts, vault_cfg): + if not should_include_path(rel_parts, vault_cfg): continue rel_path_str = str(fpath.relative_to(vault_root)).replace("\\", "/") @@ -423,6 +391,7 @@ async def build_index(progress_callback=None) -> None: await asyncio.gather(*tasks) # Build attachment index + from backend.attachment_indexer import build_attachment_index await build_attachment_index(vault_config) total_files = sum(len(v["files"]) for v in index.values()) diff --git a/backend/utils.py b/backend/utils.py new file mode 100644 index 0000000..d13b9da --- /dev/null +++ b/backend/utils.py @@ -0,0 +1,35 @@ +"""Utility functions shared across backend modules.""" +from typing import Dict, Any, Tuple + + +def should_include_path(rel_parts: Tuple[str, ...], vault_config: Dict[str, Any]) -> bool: + """Check if a path should be included based on hidden files configuration. + + Args: + rel_parts: Tuple of path parts relative to vault root + vault_config: Vault configuration dict with includeHidden and hiddenWhitelist + + Returns: + True if the path should be included, False otherwise + """ + include_hidden = vault_config.get("includeHidden", False) + hidden_whitelist = vault_config.get("hiddenWhitelist", []) + + # Check if any part of the path starts with a dot (hidden) + hidden_parts = [part for part in rel_parts if part.startswith(".")] + + if not hidden_parts: + # No hidden parts, always include + return True + + if include_hidden: + # Include all hidden files/folders + return True + + # Check if any hidden part is in the whitelist + for hidden_part in hidden_parts: + if hidden_part in hidden_whitelist: + return True + + # Not in whitelist and includeHidden is False + return False