Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setuptools not getting dynamic version when using pyproject.toml

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'
like image 635
Greg Wilson Avatar asked Mar 11 '26 17:03

Greg Wilson


1 Answers

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...

like image 103
Greg Wilson Avatar answered Mar 14 '26 07:03

Greg Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!