# Convert setup.py metadata to pyproject.toml

`pyproject.toml`'s `[project]` metadata is the standard place to find a project metadata.

Historically this was on `setup.py`, but it had plenty of problems.

Now, you can write all of a project's metadata in `pyproject.toml`,
[see the specification](https://packaging.python.org/en/latest/specifications/pyproject-toml/).

All plone and collective python distributions are using `setup.py` to keep each project's metadata.

[`zope.meta`](https://pypi.org/project/zope.meta) created a script to move the metadata from `setup.py` to `pyproject.toml`.

In `plone.meta` this script from `zope.meta` has been adapted to suit the needs of the Plone ecosystem.

## Conversion

To convert the metadata do the following:

```bash
cd $REPOSITORY
uvx --from plone.meta setup-to-pyproject .
```

i.e. go to your repository and run the `setup-to-pyproject` script from `plone.meta`.

This will automatically create a commit on your repository with the changes.

:::{note}
Please review them carefully to ensure that the conversion was done properly.
:::

Ideally `setup.py` should look like this:

```python
from setuptools import setup

# See pyproject.toml for package metadata
setup()
```

### Issues link

`setup-to-pyproject` accepts an optional argument: `--issues`.

This option is to customize the issues link displayed on PyPI related to the project.

It accepts the following options:

- `own`: use the repository itself as the issue tracker
- _URL_: provide a custom URL that will be used verbatim
- _None_: if no value is provided `Products.CMFPlone` issue tracker is used

## Clean up

Run some tooling `tox run -e test` to ensure that the conversion worked.

:::{note}
It might be that the license field in `project.license` within `pyproject.toml` is broken.

Please have a look at valid [license expressions](https://packaging.python.org/en/latest/specifications/license-expression/) to solve it.
:::

Re-configure the repository with `plone.meta` to ensure that the project metadata is kept:

```bash
cd $REPOSITORY
uvx --from plone.meta config-package branch=current .
```

Make sure to review the commit generated by `config-package`.
