from pathlib import Path
import tomllib
from typing import TypedDict


class Project(TypedDict):
    name: str
    version: str


def get_project(project: Path) -> Project:
    toml = project / "pyproject.toml"
    if not toml.exists():
        raise FileNotFoundError(f"Could not find {toml}")
    data = tomllib.loads(toml.read_text(encoding="utf-8"))
    return Project(data["project"])


def main():
    project = get_project(Path.cwd())
    version_path = Path("src") / project["name"] / "version.py"
    version_path.write_text(f"""\
# Do not edit this file, it is automatically generated by scripts/generate_version.py
VERSION = "{project['version']}"
""")


if __name__ == "__main__":
    main()
