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 643 (Dynamic field for core metadata) #4698

Merged
merged 12 commits into from
Jan 8, 2025

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented Oct 21, 2024

IMPORTANT: #4701 needs to be merged first, then this PR needs to be rebased (probably there will be conflicts). It might also be a good idea to wait until the next version of wheel is released (v0.45).

Summary of changes

This PR attempts to implement the 2nd approach suggested in #2685:

Mark everything as Dynamic if it comes from setup.py, but not if it comes from setup.cfg or pyproject.toml.

Values given via setup.py are considered dynamic for the sake of simplicity.

The "trick" implemented in this PR to avoid the problems with plugins/customisations described in #4629 (comment), is to mark static values instead of dynamic ones.

This marking is a bit "unconventional" (via subclasses of buit-in types), but it simplifies the tracking of changes and is backward compatible with the existing distutils/setuptools code base.

OPEN PROBLEM: wheel.metadata.pkginfo_to_metadata hardcodes Metadata-Version: 2.1.

Closes #2685

Pull Request Checklist

@abravalheri
Copy link
Contributor Author

@jaraco would this kind of approach be acceptable in setuptools?

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

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

I haven't gone deep into the details, but at a high level, this change seems to honor the intentions of PEP 643.

It's not obvious to me what changes from a user's perspective. What projects are affected by this change? Does it simplify or complicate their experience? I think the answer is that projects largely don't have to do anything, but this change gives more fidelity to the metadata (at the cost of the added logic maintenance). If that's right, that seems like a fair tradeoff. Happy to give it a try. Let me know if there's a type of project you think I should run it against.

@abravalheri
Copy link
Contributor Author

Thank you very much @jaraco.

The motivation of the PEP is purely to catch up with the standards, I don't think it changes much from a user's perspective. However it may be used by frontends/installer for optimisations and therefore improve installation speed.

Let me know if there's a type of project you think I should run it against.

This week I will not have the time, but my plan is to build some projects and try to upload them to test.pypi.io, to see if the metadata still passes all the validations done by PyPI. I that goes well, we can release the change and start working on PEP 639.

return _CONVERSIONS.get(type(value), noop)(value) # type: ignore[call-overload]


def is_static(value: Any) -> bool:
Copy link
Contributor

@Avasam Avasam Nov 30, 2024

Choose a reason for hiding this comment

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

An object parameter should match anything. You should be able to avoid using Any here.

Suggested change
def is_static(value: Any) -> bool:
def is_static(value: object) -> bool:

You can also make this function a type-guard with:

Suggested change
def is_static(value: Any) -> bool:
if TYPE_CHECKING:
from typing_extensions import TypeGuard # Added to typing in Python 3.10
def is_static(value: object) -> TypeGuard[Static]:

Copy link
Contributor Author

@abravalheri abravalheri Jan 8, 2025

Choose a reason for hiding this comment

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

Thank you!

In 72c4222, I went with the first approach suggested because I don't want the type checker to change the type it sees in a variable. For example if a variable is _static.Str | str, I would like the typechecker to keep considering it _static.Str | str...

Later if we need, we can change it to a TypeGuard.

@ofek
Copy link
Contributor

ofek commented Jan 7, 2025

Has there been any update on this? At work we have a dependency in our chain that causes a source distribution build during resolution which takes dozens of minutes which would be unnecessary with this implemented.

@abravalheri
Copy link
Contributor Author

I did some very simple tests with test.pypi.org in a couple of projects:

The test was done using:

[build-system]
requires = ["setuptools @ git+https://github.com/abravalheri/setuptools@issue-2685-pep643", ...]

I think it makes sense to move ahead with this one now and allow a couple of weeks to see if any edge cases comes up. Worst case scenario can revert back.

@abravalheri abravalheri merged commit f285d01 into pypa:main Jan 8, 2025
21 of 23 checks passed
@abravalheri abravalheri deleted the issue-2685-pep643 branch January 8, 2025 17:00
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.

[FR] Add support for PEP 643 - metadata for sdists
4 participants