The PEP621 allows you to specify certain project metadata as dynamic. See the official example here.
[project]
dynamic = ["version"]
The build back-end should have some logic to generate the dynamic version. In setuptools this can be achieved by:
[tool.setuptools.dynamic]
version = { file = "VERSION" }
It parse the file VERSION.
How can py-build-cmake generate dynamic version and other metadata?