setuptools not getting dynamic version when using pyproject.toml

658 views Asked by At

I am using setuptools with a pyproject.toml file, and want setuptools to get the package version dynamically from the package contents. Instead, it is always setting the package version in the name of the generated file to 0.0.0, even though the package version inside the package seems correct. What am I doing wrong?

  • Python 3.11.6 on MacOS 14.1.2 (Sonoma)
  • setuptools version 68.2.2
  • pip version 23.3.1

Package structure:

.
├── LICENSE.md
├── README.md
├── invperc
│   └── __init__.py
└── pyproject.toml
  • invperc/__init__.py contains only this:
__version__ = "0.2.0"
  • pyproject.toml contains only this:
[project]
name = "invperc"
description = "Invasion Percolation"
readme = "README.md"
authors = [
    { name = "Greg Wilson", email = "[email protected]" }
]
license = { text = "MIT License" }
dependencies = ["pandas", "numpy"]
dynamic = ["version"]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tools.setuptools.dynamic]
version = {attr = "invperc.__version__"}
  • Command:
python -m build
  • Screen output:
...many lines...
Successfully built invperc-0.0.0.tar.gz and invperc-0.0.0-py3-none-any.whl
  • dist/invperc-0.0.0.tar.gz and dist/invperc-0.0.0-py3-none-any-whl now exist with 0.0.0 as version numbers (which is incorrect).

  • But if I import and check:

$ cd /tmp
$ pip install $HOME/invperc/dist/invperc-0.0.0-py3-none-any.whl
$ python
>>> import invperc
>>> invperc.__version__
'0.2.0'
1

There are 1 answers

3
Greg Wilson On

Thanks to @[email protected] for the answer: [tools.setuptools.dynamic] should be [tool.setuptools.dynamic] with a singular "tool" instead of a plural "tools". Now excuse me while I go scream into a pillow about the lack of any kind of warning message...