Skip to main content

resolve_project_root

Function resolve_project_root 

Source
pub fn resolve_project_root(
    input: ProjectInput<'_>,
    home: Option<&Path>,
) -> Option<PathBuf>
Expand description

Resolve a project root from process-like path inputs without caching.

The fallback order is:

  1. Walk upward from the working directory set by ProjectInput::cwd.
  2. Walk upward from the parent directory of the executable set by ProjectInput::exe, unless the executable is a known runtime or tool such as node, python, or cargo. A known runtime inside a Python virtual environment (a directory with pyvenv.cfg one or two levels above the executable, as in app/.venv/bin/python or app\.venv\Scripts\python.exe) walks from the directory holding the environment instead.
  3. Walk upward from the parent directory of each absolute path in the arguments set by ProjectInput::cmd.

The first accepted marker hit wins. Relative command-line paths are ignored because they are ambiguous without a reliable process working directory. home is the same optional ceiling as in find_project_root. A root found from the executable path is rejected when it lies inside a dot directory directly under home (~/.nvm, ~/.cargo, ~/.local): those hold installed toolchains and packages, not the process’s project.

Use StackDetector::detect_project_root for repeated lookups; it applies the same order with caching and its own configured home ceiling.

§Examples

use what_stack::{ProjectInput, resolve_project_root};

assert_eq!(resolve_project_root(ProjectInput::new(), None), None);