pyproject-fmt icon indicating copy to clipboard operation
pyproject-fmt copied to clipboard

When using [project.readme] it gets shifted to inside [project] and breaks pyproject.toml.

Open ocefpaf opened this issue 2 years ago • 7 comments

Sorry if I'm doing something wrong but when running the pyproject-fmt it breaks our pyproject.toml and moving it manually to below the "dynamic" entry fixes it.

One can see that in first commit of https://github.com/Unidata/netcdf4-python/pull/1267 in https://github.com/Unidata/netcdf4-python/pull/1267/commits/1872af61568a58807f221a435516573fc086e0f1.

Thanks for the awesome tool!

Feel free to close this if what I'm doing is out of scope for this tool.

ocefpaf avatar Jul 11 '23 19:07 ocefpaf

PR welcome to fix it.

gaborbernat avatar Jul 11 '23 19:07 gaborbernat

PR welcome to fix it.

I'd be happy to if I understand first:

  1. that it is really pyproject-fmt
  2. how pyproject-fmt works :-)

ocefpaf avatar Jul 11 '23 19:07 ocefpaf

Yes to both.

gaborbernat avatar Jul 11 '23 20:07 gaborbernat

Hey, I have tried to come up with a solution for this but think it’s actually an issue with the usage of the TOML-syntax. In their docs it’s emphasized, that you should not introduce sub-tables (e.g. [project.readme]) after the top-level table ([project]). The reason is, that readme and another field of the same level are treated equally, even if their actual rendering might look different. So you could switch the order in your file and introduce all sub-tables (readme, scripts, urls…) beforehand like:

[project.readme]
text = '''netCDF version 4 has many features not found in earlier versions of the library...
'''
content-type = "text/x-rst"

[project]
name = "netcdf4"
description = "Provides an object-oriented python interface to the netCDF version 4 library"
dynamic = [
  "version",
]

This should not break your file.

mj0nez avatar Aug 09 '23 21:08 mj0nez

I just encountered this - minimal example:

[project]
name = "widgetizer"
keywords = ["widgets"]

[project.readme]
file = "README.rst"

…gets reformatted to:

[project]
name = "widgetizer"
[project.readme]
file = "README.rst"
keywords = [
  "widgets",
]

Sorting project.readme first works as suggested, leaving the file as:

[project.readme]
file = "README.rst"

[project]
name = "widgetizer"
keywords = [
  "widgets",
]

adamchainz avatar Oct 24 '23 10:10 adamchainz

PR welcome 👍

gaborbernat avatar Oct 24 '23 14:10 gaborbernat

I think per https://github.com/diazona/setuptools-pyproject-migration/pull/112 and https://github.com/diazona/setuptools-pyproject-migration/pull/114 , it would be a good feature if pyproject-fmt converted a few keys to inline variants: authors, license, maintainers, and readme. This would match the setuptools docs too.

adamchainz avatar Oct 25 '23 20:10 adamchainz

Done via https://github.com/tox-dev/pyproject-fmt/releases/tag/2.0.0

gaborbernat avatar May 10 '24 21:05 gaborbernat