How do I read the project version number stored in the pyproject.toml file from within the tox.ini file?

40 views Asked by At

I want to include an upload environment in my tox.ini file. But, that requires resolving the project version dynamically; something like:

[testenv:upload]
basepython = python3.11
skip_install = true
deps =
    twine
commands =
    twine upload dist/foo-{[project]version}.tar.gz dist/foo-{[project]version}-py3-none-any.whl

But, that syntax doesn't work:

% tox -e upload
upload: commands[0]> twine upload 'dist/foo-{[project]version}.tar.gz' 'dist/foo-{[project]version}-py3-none-any.whl'
ERROR    InvalidDistribution: Cannot find file (or expand pattern): 'dist/foo-{[project]version}.tar.gz'

What is the correct syntax, in the tox.ini file, for reading the project version from the pyproject.toml file?

1

There are 1 answers

0
Seyi Daniels On

Tox itself does not have a global variable called project and if you want to get the project version from pyproject.toml, You could do this

  • Explicitly set the project version within your tox file, but that would involve having to change project version in two places. You can use tox setenv command to set the version.

[testenv]
setenv =
    VERSION=0.01

[testenv:upload]
basepython = python3.11
skip_install = true
deps =
    twine
commands =
    twine upload dist/foo-{env:VERSION}.tar.gz dist/foo-{env:VERSION}-py3-none-any.whl