I make no claim to be an expert at this, but I did just need to convert a project from a slightly complicated setup.py / PBR configuration to pyproject.toml and thought I should write up where I landed. I say “slightly complicated” because there are a few very OpenStacky things I like to do in these things. Specifically:
- version numbers are driven by git tags not hard coded in the configuration file.
- console scripts are a thing.
- I often include data files in the built package.
So here’s an example of all of those things that is working ok for me:
[build-system]
requires = [
"setuptools>=61.0",
"setuptools_scm[simple]>=6.2",
"wheel",
"build",
"twine"
]
build-backend = "setuptools.build_meta"
[project]
name = "clingwrap"
dynamic = ["version"]
description = "Build bundles of debugging information for system crashes"
readme = "README.md"
requires-python = ">=3.7"
dependencies = [
"oslo.concurrency", # apache2
"click>=7.1.1", # bsd
"pyyaml", # mit
"shakenfist-utilities", # apache2
]
[project.urls]
"Homepage" = "https://shakenfist.com"
"Bug Tracker" = "https://github.com/shakenfist/clingwrap/issues"
[project.scripts]
clingwrap = "clingwrap.main:cli"
[tool.setuptools.package-data]
clingwrap = [
"examples/*.cwd"
]
[tool.setuptools_scm]
git_describe_command = "git describe --dirty --tags --match v* --first-parent"
write_to = "clingwrap/_version.py"
[project.optional-dependencies]
test = [
"coverage", # apache2
"testtools", # mit
"mock", # bsd
"stestr", # apache2
"tox", # mit
"flake8", # mit
]
Note that setuptools_scm[simple] is needed for version tags to work, as is the dynamic = ["version"]. The data files are included by [tool.setuptools.package-data] with the only wart there being that I needed to move the examples directory into theĀ clingwrap directory for them to be included correctly.
The next hurdle was getting requirements installed without installing the package itself. It seems that uv is the easiest way to do this. To install the dependencies for the package, but not the package itself, you can do this: uv pip install -r pyproject.toml, this replaces the previous requirements.txt file. To replaceĀ test-requirements.txt I also include a [project.optional-dependencies] section, which can be installed with uv pip install -r pyproject.toml --extra test.
I hope this helps someone else figure this out.