python-3.xsetuptoolsgitversionpyproject.toml

Git versioning with setuptools in pyproject.toml


I'm trying to build a few packages with an automatic versioning set by setuptools-git-versioning. Unfortunately, even following the documentation and the very few resources online, I can't manage to make this versioning work.

pyproject.toml:

[build-system]
requires = ["setuptools>=42", "wheel", "setuptools-git-versioning"]
build-backend = "setuptools.build_meta"

[tool.setuptools-git-versioning]
enabled = true

...

[project]
version = "1.0"
...

According to documentation, the enabled flag should suffice for setuptools to get the tag-based version and set it as the version of the package, yet when building the package, the version prompted when running python3 -m pip list or conda list corresponds to the hard-coded value of version in the project section of pyproject.toml.

What am I missing/doing wrong?


Solution

  • According to the PyPa documentation when version is defined statically it can't be changed by a tool (i.e. setuptools-git-versioning in this case). The other option is to use dynamic which...

    Dynamic metadata is listed via the dynamic field (defined later in this specification) and represents metadata that a tool will later provide.

    So removing the static version = "1.0" and adding dynamic = ["version"] to the [project] should work.