Migrating Python setup.cfg / setup.py to pyproject.toml#

This is how I migrate my old style of Python project setup using setup.cfg and setup.py to pyproject.toml using uv and setuptools.

Before, I used pyenv with .python-project containing the name of a project-specific Python version to switch automatically on cd’ing to the project directory.

Replace pyenv with uv#

Check uv version

uv --version
# uv 0.4.28

First, get rid of .python-project:

rm .python-version

Disable pyenv for the current shell

pyenv shell system

Create a venv

uv venv 3.11

Convert setup.cfg to pyproject.toml#

Activate the virtualenv:

source .venv/bin/activate

Install ini2toml

uv pip install 'ini2toml[full]'

Convert

uv run ini2toml setup.cfg -o pyproject.toml

Review pyproject.toml

vi pyproject.toml setup.cfg setup.py

Add some things that did not get converted:

[project]
requires-python = ">= 3.11"
readme = "README.md"
license = {file = "LICENSE"}

If you have package data, e.g. template files, check your MANIFEST.in file and be sure to set

[tool.setuptools]
include-package-data = true

Move from dev extras to dependency-groups [1], e.g.

[project.optional-dependencies]
dev = [
    "ruff",

–>

[dependency-groups]
dev = [
    "ruff>=0.7.1",

Run

uv sync

Cleanup

uv pip uninstall 'ini2toml[full]'