All jobs

Migrate a Python Project from setup.py to pyproject.toml

Yes. An agent moves your setuptools metadata from setup.py and setup.cfg into pyproject.toml, rebuilds the wheel, diffs its metadata and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts by finding out where the packaging actually lives, because in a project shaped like httpie/cli it is not in setup.py. That file is three lines, from setuptools import setup and a bare setup(), and everything else sits in setup.cfg: a [metadata] table whose version is attr: httpie.__version__ read from httpie/init.py, long_description = file: README.md, the classifiers and project_urls, then [options] with install_requires (including environment markers such as importlib-metadata>=1.4.0; python_version<"3.8" and colorama>=0.2.4; sys_platform=="win32"), python_requires = >=3.7, packages = find: narrowed by [options.packages.find] to httpie and httpie.*, three console_scripts entry points (http, https and httpie), dev and test extras, and an [options.data_files] block that installs three man pages from extras/man into share/man/man1. The agent lists every one of those keys before it writes anything, because each needs a home in the new file and some have none.

It then writes pyproject.toml with a [build-system] table that names setuptools and a [project] table carrying the same metadata: name, dynamic = ["version"] with [tool.setuptools.dynamic] version = {attr = "httpie.__version__"}, readme, requires-python, dependencies with the markers kept verbatim, [project.optional-dependencies] for dev and test, [project.scripts] for the three commands, [project.urls], and [tool.setuptools.packages.find] with the same include list. The man pages are the awkward part: data_files has a [tool.setuptools] equivalent that setuptools discourages, so the agent keeps it there and says so in the pull request rather than silently dropping three files the Makefile's man target regenerates. MANIFEST.in stays, since setuptools still reads it for the sdist.

Two sections of setup.cfg do not move, and the agent explains why. [flake8] cannot go into pyproject.toml because flake8 does not read it, so that section stays, or moves to a .flake8 file, so that make codestyle keeps ignoring E501 and W503. The [tool:pytest] section is more interesting: the repository also has a pytest.ini, and pytest reads pytest.ini first and ignores every other config file when one exists, so the testpaths, --doctest-modules and xfail_strict settings in setup.cfg have not been in effect. The agent points that out, moves the markers from pytest.ini and the intended settings into [tool.pytest.ini_options] in one place, runs make test with and without them, and reports whether the previously dormant options change which tests run.

Then it proves the package is the same package. In the sandbox it runs make install into the project's venv, python -m build --sdist --wheel --outdir dist/ as the build target does, installs the wheel with pip install --force-reinstall dist/*.whl, runs http --version, https --version and httpie --version, and twine check dist/*. It builds the wheel once from the original branch too, unpacks both and diffs their METADATA and entry_points.txt, so the review question becomes a diff of two short files. Finally it edits the three workflows whose paths filters list setup.* or setup.py (tests.yml, coverage.yml and code-style.yml) to add pyproject.toml, otherwise a future change to the packaging would not trigger the test matrix across Python 3.7 to 3.12 and three operating systems.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Migrate this Python project from setup.py and setup.cfg to a PEP 621 pyproject.toml. Read setup.py, setup.cfg, pytest.ini, MANIFEST.in, Makefile, httpie/__init__.py and every file under .github/workflows first, and list each setup.cfg key with where it will go. Keep the version dynamic from httpie.__version__, keep every dependency marker, the console_scripts entry points, the dev and test extras, the package discovery include list and the man page data_files, and say in the pull request which of those have no first-class equivalent. Leave the flake8 section in a place flake8 reads. Note that pytest.ini overrides the [tool:pytest] section in setup.cfg and merge the two into one [tool.pytest.ini_options] table, reporting any change in which tests run. Build the sdist and wheel with python -m build from the original branch and from yours, unpack both, diff METADATA and entry_points.txt, install the new wheel, run http --version and twine check, and run make test. Add pyproject.toml to the paths filters of every workflow that lists setup.py or setup.*. Open a pull request with the key-by-key table and the metadata diff.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds pyproject.toml, deletes setup.py, shrinks setup.cfg to the flake8 section or replaces it with .flake8, folds pytest.ini into pyproject.toml, and edits tests.yml, coverage.yml and code-style.yml so their paths filters name the new file. The description carries a table with one row per setup.cfg key, the table it moved to, and a note for the ones that needed a decision: the dynamic version, the man page data files, and the dormant pytest settings.

Below the table is the evidence: the unified diff of METADATA and entry_points.txt between the wheel built from the base branch and the wheel built from the pull request, the output of twine check dist/*, the three --version commands run from the installed wheel, and the tail of make test. Nothing is asserted about the build that a quoted command does not show, and the branch is pushed only as a pull request, never to the default branch.

Before merging, a reviewer reads the METADATA diff first; it should be empty apart from ordering, or show only changes the table explains. They then check the extras still resolve with pip install '.[dev]', and that the release workflow, which runs make install && make build on a chosen ref, needs no change because the build target already calls python -m build and never invoked setup.py directly.

Run it on every repository still on setup.py

A team with several Python packages starts one run per repository, each a POST /o/{org}/sessions with this prompt and that repository in resources. Send a request_id per repository so a retried call returns the run it already started instead of opening a second pull request. Each run reads its own setup.cfg, so a package whose version is static or whose extras differ gets a pull request written for that file, not a template.

Each run works in its own sandbox and the key's max_concurrent limit, 4 by default, caps how many build at once. Give the key a webhook URL and Rush posts run.completed or run.failed when each turn ends, so a small handler can collect the pull request links in one place.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The risk in this migration is not the TOML syntax, it is the key that quietly disappears: a marker dropped from a dependency, an entry point renamed, man pages that stop shipping. The only check that catches those is building the wheel twice and diffing what is inside, which means a clean venv, python -m build, unpacking two archives and reading METADATA. On a laptop that gets skipped once the import works; in its own sandbox the agent does it as a matter of course and quotes the diff.

The full record stays with the pull request. Every command, from make install to twine check, is in the run's transcript with its output, so a reviewer who did not watch can see that the test matrix was considered, that the pytest.ini precedence was noticed rather than assumed, and that the man pages were kept on purpose. If the diff shows something the reviewer wants changed, a follow-up message on the same session wakes the parked sandbox with the built wheels still on disk.

Frequently asked questions

Will the version still come from httpie/__init__.py?

Yes. PEP 621 lets a field be declared dynamic, and setuptools reads it from an attribute with [tool.setuptools.dynamic]. The agent keeps attr: httpie.__version__ as version = {attr = "httpie.__version__"} so the release process, which bumps the string in that file, does not change.

What happens to the man pages in data_files?

They are kept. setuptools still accepts data-files under [tool.setuptools], with a warning in its documentation that the mechanism is discouraged. The agent carries the three files over, says so in the pull request, and leaves the choice of a packaging-specific alternative to the maintainers rather than dropping files that make man regenerates.

Does flake8 configuration move too?

No. flake8 does not read pyproject.toml, so its ignore = E501,W503 stays in setup.cfg or moves to a .flake8 file. The pull request keeps make codestyle passing with the same ignores, and the agent runs it to show that.

Why does the pull request touch the workflow files?

Because tests.yml, coverage.yml and code-style.yml only run when a path in their filters changes, and those filters list setup.* or setup.py. Without pyproject.toml in the list, a later packaging change would merge without the test matrix running. The agent adds the path and nothing else to those workflows.

Can it keep a setup.py for tools that still call it?

Ask for it in the prompt. Nothing in this repository runs python setup.py any more; the Makefile builds with python -m build and the release workflow calls make build. If a downstream packager still needs a shim, the agent leaves a minimal setup.py that calls setup() and reads everything from pyproject.toml.

More Python jobs

More jobs like this: Hand off a long task

Keep reading