Converting from setup.py and PBR to pyproject.toml

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"

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.

I hope this helps someone else figure this out.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.