from __future__ import annotations

from pathlib import Path

_ROOT_MARKERS = ("pyproject.toml", ".git", "in")


def get_proj_dir() -> str:
    """Return project root directory with trailing slash.

    Walks up from this file's location until a directory containing
    one of the root markers is found.

    Root markers (checked in order): pyproject.toml, .git, in/.

    Returns:
        Absolute path to project root with trailing '/'.

    Raises:
        RuntimeError: If no marker is found within 10 parent levels.
    """
    current = Path(__file__).resolve().parent
    for _ in range(10):
        if any((current / marker).exists() for marker in _ROOT_MARKERS):
            return str(current) + "/"
        current = current.parent
    raise RuntimeError(
        f"Cannot find project root: none of {_ROOT_MARKERS} found "
        f"in ancestors of {Path(__file__).resolve()}"
    )
