Skip to content

Migrate setup.py to a PEP 621 pyproject.toml #268

Description

@jaysonsantos

Part of the repository modernization effort.

Background

setup.py is the only source of package metadata. The version string 0.32.0 exists in four places:

  • setup.py:17
  • docs/conf.py — version = '0.32' and release = '0.32.0'
  • .cz.yaml:5
  • flake.nix:68

pyproject.toml holds only a [build-system] table. setup.cfg holds only the flake8 line length.

Warning: commitizen must keep working

.cz.yaml drives the release bump:

---
commitizen:
  name: cz_conventional_commits
  tag_format: v$version
  version: 0.32.0
  version_files:
  - setup.py
  - docs/conf.py

version_files does a literal replace of the version string. If setup.py is deleted, the entry must move to the new version source. Run cz bump --dry-run and confirm the result before you merge.

Note the pre-existing gap: the short version = '0.32' line in docs/conf.py does not match the full 0.32.0 string. commitizen does not bump it today.

Warning: keep README.rst

README.rst is a symlink to docs/intro.rst. docs/intro.rst is a Sphinx source file in reStructuredText.

Do not convert README.rst to Markdown. The conversion breaks the Sphinx build.

A PEP 621 readme = "README.rst" field reads whatever the path resolves to at build time. That is the symlink in a local build. That is the pandoc-built file in the publish workflow. The behavior matches setup.py today. .github/workflows/publish.yml needs no change for this issue.

Proposed pyproject.toml

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"

[project]
name = "python-binary-memcached"
dynamic = ["version"]
description = "A pure python module to access memcached via its binary protocol with SASL auth support"
readme = "README.rst"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
    { name = "Jayson Reis", email = "santosdosreis@gmail.com" },
]
classifiers = [
    "Development Status :: 4 - Beta",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
    "Programming Language :: Python :: 3 :: Only",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    "Programming Language :: Python :: 3.12",
    "Programming Language :: Python :: 3.13",
    "Programming Language :: Python :: 3.14",
]
dependencies = [
    "uhashring",
]

[project.urls]
Homepage = "https://github.com/jaysonsantos/python-binary-memcached"
Repository = "https://github.com/jaysonsantos/python-binary-memcached"
Documentation = "https://python-binary-memcached.readthedocs.org"
Changelog = "https://github.com/jaysonsantos/python-binary-memcached/blob/main/CHANGELOG.md"

[tool.setuptools]
packages = ["bmemcached", "bmemcached.client"]

[tool.setuptools.dynamic]
version = { attr = "bmemcached.__version__" }

Warning: where to put __version__

Add __version__ = "0.32.0" as the first line of bmemcached/__init__.py. Put it before the bmemcached.client import.

setuptools reads the attr: target from the module AST. It falls back to a real import when the AST read fails. A plain literal at the top avoids an import of bmemcached.client inside the isolated build environment. That import needs uhashring to be present already.

Acceptance criteria

  • pyproject.toml holds the [project] table above.
  • bmemcached/__init__.py declares __version__ = "0.32.0" on the first line.
  • setup.py and setup.cfg are deleted.
  • .cz.yaml version_files lists bmemcached/__init__.py and docs/conf.py. It no longer lists setup.py.
  • cz bump --dry-run finds and replaces the version string.
  • python -m build --sdist --wheel --outdir dist/ . succeeds.
  • twine check dist/* passes.
  • The built sdist holds README.rst and CHANGELOG.md. Check MANIFEST.in.
  • AGENTS.md:10,18 points at pyproject.toml. It no longer points at setup.py or setup.cfg.
  • The pull request text states that flake.nix:68 keeps a manual copy of the version.

Files to change

pyproject.toml, bmemcached/__init__.py, setup.py (delete), setup.cfg (delete), .cz.yaml, AGENTS.md, MANIFEST.in (check only).

Order

Do the minimum-version issue first. Do this issue before the ruff issue and the test-dependency issue. All three change pyproject.toml.

If setup.cfg is still needed for flake8, delete it in the ruff issue instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    modernizationRepo modernization effortpackagingPackaging and distribution

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions