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

Add initial support for License-Expression (PEP 639) #4706

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented Oct 28, 2024

Summary of changes

 [project]
 name = "spam"
 ...
-license = {text = "MIT"}
+license = "MIT"

Missing: The license expression isn't yet validated. The next version of validate_pyproject will likely add that once a new version of packaging has been released. From the PEP:

Build and publishing tools SHOULD check that the License-Expression field contains a valid SPDX expression, including the validity of the particular license identifiers (as defined above).

It should be fine to omit that part for the moment.

Refs: #4629

@cdce8p cdce8p marked this pull request as draft October 28, 2024 05:58
@cdce8p cdce8p marked this pull request as ready for review October 28, 2024 12:58
@abravalheri
Copy link
Contributor

Hi @cdce8p thank you very much for having a look on this.

We probably have to organise so that PEP 639 lands after PEP 685 implementation (ideally we want a couple of days/weeks between the two so that users have time to report potential bugs).

return self.license_expression

get_license_expression = get_license_expression

Copy link
Contributor

@abravalheri abravalheri Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to implement this feature without changing the _distutils folder?

In general, we don't modify the contents to that folder directly. Instead, the code is maintained in the pypa/distutils repository and merged back in setuptools periodically, (see also our development guidelines). So changes in the folder have to be submitted first in pypa/distutils and later merged here.

Additionally, there are some people that still use the deprecated SETUPTOOLS_USE_DISTUTILS=stdlib in Python3.9 ... 3.11, so we need to ensure it is also backwards compatible with the stdlib version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to implement this feature without changing the _distutils folder?

Yes. Removed those changes as they weren't necessary to begin with. I added them initially but the better solution was to add license_expression to _DISTUTILS_UNSUPPORTED_METADATA in setuptools/dist.py. This is also fully compatible with SETUPTOOLS_USE_DISTUTILS=stdlib. 390b95f

@cdce8p
Copy link
Contributor Author

cdce8p commented Nov 5, 2024

We probably have to organise so that PEP 639 lands after PEP 685 implementation (ideally we want a couple of days/weeks between the two so that users have time to report potential bugs).

Maybe I'm missing something obvious but I'm not quite sure how PEP 685 is related. Would you mind explaining it a bit more?

The way I've designed the PR, it shouldn't depend on anything. It just allows users to specify license = MIT in pyproject.toml which will be used for the License-Expression field. Note, the metadata version is still 2.2 (not 2.4 which is the first to "require" support for PEP 639).

@cdce8p
Copy link
Contributor Author

cdce8p commented Nov 6, 2024

Opened #4734 with just the validate-pyproject update. This will make the changes here easier to review.

@abravalheri
Copy link
Contributor

Maybe I'm missing something obvious but I'm not quite sure how PEP 685 is related. Would you mind explaining it a bit more?

The problem is that the metadata version of the core metadata is incremental:

  • PEP 685 stablishes 2.2
  • PEP 639 stablishes 2.3

So we cannot implement PEP 639 before 685, otherwise metadata validation may fail.

Even if the PR is independent we cannot merge it now because of the nature of the releases of setuptools (we cannot risk PEP 639 support being released before PEP 685 support).

@cdce8p
Copy link
Contributor Author

cdce8p commented Nov 11, 2024

So we cannot implement PEP 639 before 685, otherwise metadata validation may fail.

The validation will only happen once we update the metadata version.
https://github.com/pypa/packaging/blob/24.2/src/packaging/metadata.py#L826-L831

If not, a lot of wheel uploads would probably fail as we currently include License-File metadata that's not up to spec. #3596 (Fix: #4728).

What I'm proposing here is simply to add the basic support to setuptools. It won't get validated by PyPI until we're ready to move to 2.4 but then all projects using the "new" syntax for pyproject.license will already be ready to go.

@abravalheri
Copy link
Contributor

For sure the existence of the License-File in the setuptools-produced metadata with version 2.1 is violating the specs. However, this is a well known violation that the Python ecosystem has grown acquainted to since the early prototype implementation of PEP 639, and for better or worse, learned how to deal with.

By accepting only some aspects of PEP 639, we add other kinds of spec violations that some tools may not be prepared to deal with.

So for the sake of reducing the unknown risks, I propose we pipeline the changes you kindly contributed after the implementation of 685. Unfortunately, it means that people cannot start modifying their pyproject.toml immediately, but it feels safer.

@abravalheri
Copy link
Contributor

abravalheri commented Nov 11, 2024

Sorry, I have been using the wrong PEP number, sorry for the confusion.

PEP 685 is important, but the really big one for us to implement before 639 is PEP 643 (the one with Dynamic).

@cdce8p
Copy link
Contributor Author

cdce8p commented Nov 12, 2024

So for the sake of reducing the unknown risks, I propose we pipeline the changes you kindly contributed after the implementation of 685. Unfortunately, it means that people cannot start modifying their pyproject.toml immediately, but it feels safer.

I understand your reasoning. One last suggestion. The last days I've been looking into how hatchling does it as I noticed it was one of the earliest adopters of License-Expression in the metadata. Turns out the packaging update caused upload failures pypa/hatch#1786. I can't reproduce it with PyPI at the moment. However, packaging==24.2 rejects any License-Expression and License-File keys with metadata <2.4. That would be relevant for us too. After the issue report, they removed the PEP 639 keys from the metadata and now include the project.license as part of the License key.

My suggestion

What do you think?

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.

2 participants