Source root resolution module#
python/src/dotfiles/paths.py resolves the dotfiles repository root used by
CLI commands and Sphinx helper extensions.
High-level structure#
paths.py
|-- constants
| |-- PROJECT_MARKERS
| |-- CONFIG_SECTION_PATHS / CONFIG_KEY_GIT_ROOT
| `-- CHEZMOI_DOTFILES_PATH_OVERRIDE
|-- IO boundary
| |-- SourceRootResolutionIO
| `-- RealSourceRootResolutionIO
|-- tracing and context
| |-- DiscoveryTrace
| `-- ResolverContext
|-- strategy helpers
| |-- _resolve_direct_project_root
| |-- _resolve_from_runtime_package_path
| |-- _config_git_root
| `-- _resolve_from_chezmoi_source_path
`-- public API
|-- package_config_path
|-- set_source_root_override
|-- resolve_project_dir_with_io
|-- show_project_dir_discovery
`-- resolve_project_dir
Keeps source-root resolution in one module used by CLI and docs helpers.
Separates filesystem and process access behind
SourceRootResolutionIO.Uses
DiscoveryTraceto record and optionally stream strategy attempts.Raises
SourceRootResolutionErrorwith ordered strategy output on failure.
Resolution order#
--source-root(set throughset_source_root_override).Runtime package path ancestry (walk up from package/config location).
[paths].git_rootindotfiles-config.ini.chezmoi source-pathwalk-up to project markers.CHEZMOI_DOTFILES_PATH_OVERRIDE.
If --source-root is provided and invalid, resolution stops immediately and
does not continue to fallback strategies.
Runtime behavior#
uv run --project python dotfiles ...resolves to the active checkout when the package path is inside that checkout.Installed entrypoints can still resolve through configured
git_rootand other fallbacks when package ancestry is not a repository root.Sphinx extension hooks call
resolve_project_dirand reuse the same logic.
Cache and diagnostics#
resolve_project_diris memoized with@lru_cache(maxsize=1).set_source_root_overrideclears the cache so subsequent commands use the latest override.show_project_dir_discoveryemits each trace line for--show-source-discovery.