Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyproject.toml: specify description is one line #1533

Merged
merged 1 commit into from
Apr 18, 2024
Merged

Conversation

henryiii
Copy link
Contributor

@henryiii henryiii commented Apr 16, 2024

See pypa/pyproject-metadata#30. This fills the Summary field, which must be a single line, so this should also be a single line. Historically, tools have done different things here. Setuptools removes anything after the first line. pyproject-metadata based backends (pdm-backend, scikit-build-core, and meson-python) join the lines into one line. The next version of scikit-build-core will error instead. Third party tools reading a config like this:

[project]
description = """Two
Line"""

Cannot know if the Summary will be "Two Line", "Two", or an error.

Enforcing this as one line also helps authors that put what should go into project.readme.text here instead.

There are three levels of response possible here, this PR is the middle one:

  1. Just mention one line, pulled from the Summary field.
  2. Mention that tools MAY error here. That's the current state of this PR. I think this will help validation tools (validate-pyproject and SchemaStore) make newlines a validation error.
  3. Say tools MUST error. My favorite, I think it would help authors in the long run, but probably too late to do this.

📚 Documentation preview 📚: https://python-packaging-user-guide--1533.org.readthedocs.build/en/1533/

@chrysle
Copy link
Contributor

chrysle commented Apr 16, 2024

Say tools MUST error. My favorite, I think it would help authors in the long run, but probably too late to do this.

I believe adding a ruff rule with an auto-fixing mechanism could be rewarding, and wouldn't pose a big problem concerning migration?

@edgarrmondragon
Copy link
Contributor

edgarrmondragon commented Apr 16, 2024

Say tools MUST error. My favorite, I think it would help authors in the long run, but probably too late to do this.

I believe adding a ruff rule with an auto-fixing mechanism could be rewarding, and wouldn't pose a big problem concerning migration?

Would https://github.com/tox-dev/pyproject-fmt be a better place for such an auto-fix?

In fact it already strips whitespace from the description field: https://github.com/tox-dev/pyproject-fmt/blob/bb6005786f6624d72a66b7be876696a788ce7414/src/pyproject_fmt/formatter/project.py#L41-L42

@abravalheri
Copy link
Contributor

abravalheri commented Apr 16, 2024

Say tools MUST error. My favorite, I think it would help authors in the long run, but probably too late to do this.

When we tried to enforce one-line Summary in the core metadata, we got a very hard push back from the community (see the generalised commotion in pypa/setuptools#1390 and pypa/setuptools#2893). I don't think we are currently in a position that it will not bring disruption to the community if we try something similar again. (Enforcing on pyproject.toml might be different... but since historically we have already been told off by the community, I am not sure what would be the willingness of setuptools to try it).

The middle ground option sounds good.

@henryiii
Copy link
Contributor Author

FYI, the problem was backward compatibility; people didn't want a project that used to build start to fail due to this. Failing a previously passing build is the problem, and there's not usually a way around it.1 Projects that don't have a large user base absolutely can (and should in my opinion) error on this. It was only because older code supported it. It would have been nice if the pyproject.toml support had included it from the start, as there was no legacy at that time, but it is obviously too late. 0.2% of pyproject.tomls with a project.description field on PyPI have multiline descriptions, and all the ones I checked obviously didn't know it was supposed to be a single line, and would get chopped. All of them would like like knowing this, but zero of them would like this to cause their SDists to no longer be buildable into a wheel.

Ruff does not auto fix or even lint pyproject.toml. validate-pyproject lints pyproject.toml, and pyproject-fmt formats it. I think both places2 would be good places to check for this. I think pyproject-fmt should automatically remove newlines, maybe making them escaped newlines.

Footnotes

  1. Scikit-build-core actually does have a way around it; the minimum-version field is used to handle this. But no other build backend has this built in that I'm aware of.

  2. I think validate-pyproject is used internally by setuptools, so that might be a problem adding a regex here to protect against newlines?

@chrysle
Copy link
Contributor

chrysle commented Apr 17, 2024

Ruff does not auto fix or even lint pyproject.toml.

Hmm, I checked the docs and there was one certain RUF200 rule which sounded promising... However doing this in pyproject-fmt also makes sense to me, while setuptools, as you mentioned invokes validate-pyproject; I personally see fixing a build error like this as a small maintenance task that can be done on the side, and especially large projects should have pyproject.toml linting configured – but I trust you can estimate the overall downside better.

@edgarrmondragon
Copy link
Contributor

Ruff does not auto fix or even lint pyproject.toml.

Hmm, I checked the docs and there was one certain RUF200 rule which sounded promising... However doing this in pyproject-fmt also makes sense to me, while setuptools, as you mentioned invokes validate-pyproject; I personally see fixing a build error like this as a small maintenance task that can be done on the side, and especially large projects should have pyproject.toml linting configured – but I trust you can estimate the overall downside better.

Latest pyproject-fmt now formats description into a one line string.

@chrysle
Copy link
Contributor

chrysle commented Apr 17, 2024

Latest pyproject-fmt now formats description into a one line string.

Great, thanks for the initiative!

@chrysle chrysle added this pull request to the merge queue Apr 18, 2024
Merged via the queue into pypa:main with commit 595f76d Apr 18, 2024
6 checks passed
@chrysle
Copy link
Contributor

chrysle commented Apr 18, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants