Return the directory for database files given a project root. Applies ``COCOINDEX_CODE_DB_PATH_MAPPING`` if set, otherwise falls back to ``project_root / ".cocoindex_code"``.
(project_root: Path)
| 223 | |
| 224 | |
| 225 | def resolve_db_dir(project_root: Path) -> Path: |
| 226 | """Return the directory for database files given a project root. |
| 227 | |
| 228 | Applies ``COCOINDEX_CODE_DB_PATH_MAPPING`` if set, otherwise falls back |
| 229 | to ``project_root / ".cocoindex_code"``. |
| 230 | """ |
| 231 | global _db_path_mapping # noqa: PLW0603 |
| 232 | if _db_path_mapping is None: |
| 233 | _db_path_mapping = _parse_path_mapping(_ENV_DB_PATH_MAPPING) |
| 234 | |
| 235 | resolved = project_root.resolve() |
| 236 | for mapping in _db_path_mapping: |
| 237 | if resolved == mapping.source or resolved.is_relative_to(mapping.source): |
| 238 | rel = resolved.relative_to(mapping.source) |
| 239 | return mapping.target / rel |
| 240 | return project_root / _SETTINGS_DIR_NAME |
| 241 | |
| 242 | |
| 243 | def get_db_path_mappings() -> list[PathMapping]: |