from pathlib import Path
from shutil import copyfile

from setuptools import setup
from setuptools.command.build_py import build_py

ROOT = Path(__file__).resolve().parent


class BuildPyWithVersion(build_py):
    def run(self) -> None:
        super().run()
        target = Path(self.build_lib) / "ccma" / "VERSION"
        target.parent.mkdir(parents=True, exist_ok=True)
        copyfile(ROOT / "VERSION", target)


setup(
    version=(ROOT / "VERSION").read_text(encoding="utf-8").strip(),
    cmdclass={"build_py": BuildPyWithVersion},
)
