12345678910111213141516171819202122232425262728293031 |
- from __future__ import annotations
- import sys
- from typing import Any, Callable
- if sys.version_info >= (3, 9):
- from functools import cache
- else:
- from functools import lru_cache as _lru_cache
- def cache(func: Callable[..., Any]) -> Any:
- return _lru_cache(maxsize=None)(func)
- @cache
- def gitroot() -> str:
- from os.path import abspath
- from subprocess import CalledProcessError, run
- try:
- proc = run(("git", "rev-parse", "--show-cdup"), check=True, capture_output=True)
- root = abspath(proc.stdout.decode().strip())
- except CalledProcessError:
- raise SystemExit(
- "git failed. Is it installed, and are you in a Git repository " "directory?",
- )
- return root
|