1import tomllib
2from pathlib import Path
3
4
5def get_app_info_from_pyproject() -> tuple[str, str]:
6 """Get the project name and version from the nearest pyproject.toml file."""
7 current_path = Path.cwd()
8
9 # Walk up the directory tree looking for pyproject.toml
10 for path in [current_path] + list(current_path.parents):
11 pyproject_path = path / "pyproject.toml"
12 if pyproject_path.exists():
13 try:
14 with pyproject_path.open("rb") as f:
15 pyproject = tomllib.load(f)
16 project = pyproject.get("project", {})
17 name = project.get("name", "App")
18 version = project.get("version", "dev")
19 return name, version
20 except (tomllib.TOMLDecodeError, OSError):
21 continue
22
23 return "App", "dev"