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

Implement PEP 639 #4829

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft

Implement PEP 639 #4829

wants to merge 47 commits into from

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented Feb 17, 2025

Summary of changes

This PR is a "mega PR" that simply make sure all the steps to implement PEP 639 are added at the same time to the main branch.
This is done to avoid problems with incomplete changes:

  • We know that tools are being designed and implement PEP 639 compatibility
  • We know existing tools know how to understand the current implementation in setuptools
  • We don't know how tools would react to something that is not quite a PEP 639 implementation or the exact existing implementation in setuptools.

All the PR are previous reviewed individually.

Good to have according to #4829 (comment):

  • The PEP specifies that tools should reject any patterns which contain not-approved chars.
  • Furthermore, it should be an error if a pattern doesn't match any files.
  • Tools should also validate that the license files themselves are utf-8 encoded. Although I don't think that's a priority tbh.
  • Currently missing but not blocking
  • Lastly, we should probably provide some kind of transition path from tool.setuptools.license-files to project.license-files. Be it as simple as rejecting both together (in which case tool.setuptools.license-files is used) or emitting a warning that tool.setuptools.license-files is deprecated in favor of project.license-files.

Compatibility with other peps:

NOTE: I believe that we can simply fast forward the Core Metadata to 2.4 considering that:

https://github.com/pypa/setuptools/blob/v75.8.0/setuptools/_core_metadata.py#L236-L250

Closes

Pull Request Checklist

Footnotes

  1. Currently there is a problem with packaging implementation https://github.com/pypa/packaging/issues/845, but for the sake of advancing the setuptools implementation to catch up with the standards we can consider this a "well known bug" that would be solved in the context of pypa/packaging.

@cdce8p
Copy link
Contributor

cdce8p commented Feb 17, 2025

Opened #4830 with the metadata version bump. I can rebase it after #4706 is merged into the feature branch.

@abravalheri
Copy link
Contributor Author

Thank you very much @cdce8p!

It seems that a new error with installing tox on cygwin appeared on the CI. I will try to check if it exists in the main branch as it is probably unrelated.

@cdce8p
Copy link
Contributor

cdce8p commented Feb 17, 2025

One area in which the implementation could still be improved is probably the license-files handling. https://peps.python.org/pep-0639/#add-license-files-key

  • The PEP specifies that tools should reject any patterns which contain not-approved chars.
  • Furthermore, it should be an error if a pattern doesn't match any files.
  • Tools should also validate that the license files themselves are utf-8 encoded. Although I don't think that's a priority tbh.
  • Lastly, we should probably provide some kind of transition path from tool.setuptools.license-files to project.license-files. Be it as simple as rejecting both together (in which case tool.setuptools.license-files is used) or emitting a warning that tool.setuptools.license-files is deprecated in favor of project.license-files.

There is also the matter of setup.py and setup.cfg files. My initial intent was to require pyproject.toml for PEP 639. However I haven't tested what happens if one of the setup files overwrites the project metadata.

Side note: Adding support for license expressions to setup.py or setup.cfg is probably a lost cause in itself, as these use a license key already.

--
This looks like a larger list than it is. In particular, they are mostly quality-of-life improvements. So I wouldn't consider them a necessity for the initial implementation.

@abravalheri
Copy link
Contributor Author

abravalheri commented Feb 17, 2025

Thank you for the review @cdce8p.

Let's make a checkbox:

  • The PEP specifies that tools should reject any patterns which contain not-approved chars.
  • Furthermore, it should be an error if a pattern doesn't match any files.
  • Tools should also validate that the license files themselves are utf-8 encoded. Although I don't think that's a priority tbh.
  • Lastly, we should probably provide some kind of transition path from tool.setuptools.license-files to project.license-files. Be it as simple as rejecting both together (in which case tool.setuptools.license-files is used) or emitting a warning that tool.setuptools.license-files is deprecated in favor of project.license-files.

I would like to tackle at least the last of this points before releasing because we can introduce all the related deprecation warnings/breaking errors at once.

Side note: Adding support for license expressions to setup.py or setup.cfg is probably a lost cause in itself, as these use a license key already.

I agree that there is not much point on updating setup.cfg or setup.py support... although it might be the case if someone sets license_expression = ... there it will just work (remains untested).

@abravalheri
Copy link
Contributor Author

abravalheri commented Feb 18, 2025

@cdce8p we are probably in a good state after:

I am considering if we should ask for volunteers to test in their projects before the release.


Possibly License-Expression and License-Files should be reviewed in the context of PEP 643.
We could modify https://github.com/pypa/setuptools/blob/v75.8.0/setuptools/_core_metadata.py#L304-L305. We might also have to mark with _static.Str and _static.List other places, and test it more thoroughly. PEP 639 does allow setuptools to populate License-Files automatically without marking it as dynamic, but the same is not true for setup.py.


I am not intending to implement for now:

Tools should also validate that the license files themselves are utf-8 encoded. Although I don't think that's a priority tbh.

But that can be a follow-up PR (not sure where is the best place to implement, maybe https://github.com/pypa/setuptools/blob/v75.8.0/setuptools/command/egg_info.py#L598-L602? maybe in the sdist/bdist_wheel command once we are actually writing the file?)

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