Skip to content

Require semantic equivalence between pyproject.toml, PKG-INFO and METADATA - #1594

Open
konstin wants to merge 2 commits into
python:mainfrom
konstin:konsti/match
Open

konstin wants to merge 2 commits into
python:mainfrom
konstin:konsti/match

Conversation

@konstin

@konstin konstin commented Aug 25, 2024 •

Copy link
Copy Markdown
Contributor

In the current version of the description of static fields in the core metadata, it is unclear whether "match" means string equivalence or semantic equivalence. Given that normalizing fields is current practice, and even packaging is reordering version specifiers, we clarify that there must be semantic equivalence between the static fields for pyproject.toml, PKG-INFO and METADATA. Semantic equivalence means that the fields work exactly the same, e.g. <3, >=2 and >=2,<3, but not torch and torch>=2.12. This does not apply to dynamic fields.

Data

I had codex pull some data on that for that for the top 1k PyPI packages:

Names compared Exact mismatches
PyPI page vs. wheel METADATA 50 / 997 (5.0%)
PyPI page vs. sdist pyproject.toml 39 / 668 (5.8%)
PyPI page vs. sdist PKG-INFO 58 / 954 (6.1%)
Wheel METADATA vs. sdist pyproject.toml 3 / 668 (0.4%)
Wheel METADATA vs. sdist PKG-INFO 10 / 951 (1.1%)
Sdist pyproject.toml vs. sdist PKG-INFO 3 / 668 (0.4%)
Build backend PyPI differs from matching METADATA and PKG-INFO Wheel METADATA has hyphens and sdist PKG-INFO has underscores pyproject.toml differs from matching METADATA and PKG-INFO PyPI differs from wheel METADATA (no sdist)
Setuptools, explicit 18 2 0 0
Setuptools, implicit or legacy 7 6 0 0
Flit 7 0 0 0
Hatchling 13 0 0 0
Maturin 2 0 0 0
scikit-build-core 1 0 0 0
OpenCV custom backend (scikit-build) 0 2 0 0
uv_build 0 0 2 0
Poetry 0 0 1 0
Setuptools (wheel generator) 0 0 0 1
pipcl (wheel generator) 0 0 0 1
Total 48 10 3 2

There can even be drift between source distribution and wheel, e.g. building nox 2026.8.17 from source distribution with two different hatchling version can give you a one byte difference in METADATA, hatchling 1.32.0 says Version: 2026.8.17, while hatchling 1.32.3 says Version: 2026.08.17 due to pypa/hatch#2398 (with a subsequent fixup in pypa/hatch#2438).


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

@konstin konstin changed the title Clarity the meaning of "match" between sdist and wheel Clarify the meaning of "match" between sdist and wheel Aug 25, 2024
@sinoroc

sinoroc commented Aug 25, 2024

Copy link
Copy Markdown
Contributor

@konstin, this seems like a reasonable clarification to me but I don't know what is the process when making edits to a specification. I think maybe it should be discussed in the "Packaging" category of discuss.python.org first.

@konstin

konstin commented Aug 26, 2024

Copy link
Copy Markdown
Contributor Author

This is a clarification on what is already happening in practice (like e.g. #1550), since packaging is already reordering specifiers. I will of course open a discourse thread if it's required, but i'd like to avoid the noise if it isn't.

@brettcannon

Copy link
Copy Markdown
Member

It's technically up to @pfmoore whether we need to have a discussion or not.

@pfmoore

pfmoore commented Aug 26, 2024

Copy link
Copy Markdown
Member

For the example of specifiers I agree1 that this is the intended meaning, and the proposed change is just a textual clarification, which can be done by a PR.

For the Name field, I'm not as happy, though. I think it's correct to say that the values must be semantically equivalent (i.e., normalise to the same value) but I don't want to give the impression that this means it's OK for build backends to change the name - the Name field is used unnormalised as the "official" (display) name for a project, and it's absolutely not OK to arbitrarily normalise that name when building a wheel.

So while the PR as it stands is OK, I'd like it to add a note that makes it clear that the equivalence rule does not imply permission to alter user-supplied values in a way that could be visible to the user (with the project name given as an explicit example of this).

Footnotes

  1. as the PEP author ↩

@konstin

konstin commented Aug 26, 2024

Copy link
Copy Markdown
Contributor Author

That's a really interesting perspective, cause the inverse is how we initially got to recognizing this as a problem: In uv, we were preserving the order of specifiers exactly because we didn't want to alter user provided values. We were then seeing differences in the lockfile (which serializes the requirements of workspace packages so we can check lockfile freshness) when this information was read directly from pyproject.toml vs. through PEP 517.

In uv, we are also currently also normalizing all package and extra names (though we currently don't have a build backend), since we found that these were often inconsistent, even for a single wheel or project. In the resolver, we couldn't determine a source for a canonical name, so we chose the normalized name instead. Effectively, our implementation is assuming the inverse: You can normalize the package name, but we were treating the specifier order as user input. For context, i have a PR up normalizing the specifier order (astral-sh/uv#6333), and my intent is to upstream this concept.

If we want to preserve certain characteristic (e.g. the spelling of the project name), should we annotate this for the applicable core metadata fields?

@pfmoore

pfmoore commented Aug 26, 2024

Copy link
Copy Markdown
Member

OK, I've thought some more about this and changed my mind. There appears to be a lot more subtlety here than I originally thought, and I'm not comfortable with simply changing "match" to "semantically equivalent". I'm happy for now to explore the issue further here, rather than going to a full community debate and possibly a PEP, but I'm not ruling that out at this point.

In uv, we are also currently also normalizing all package and extra names

First of all, what is uv doing modifying project metadata? As far as I'm aware, uv doesn't build wheels itself - as you say, it's not a build backend1. In fact, I'd go further than that - why is uv even impacted by this question? The Dynamic metadata field was introduced purely to allow tools that consume sdists to avoid doing a build step if all they need is metadata that's not marked as dynamic in the sdist. Nobody should be comparing values from the sdist and the wheel - the whole point is that you don't need to do that.

If I had to clarify "match", I'd probably say that it means "tools consuming the data can use data from either source without fear of errors, and tools that produce the data must write the data so that the previous assumption holds". But I'm not sure that's better than simply saying "match" - it's just longer.

You can normalize the package name, but we were treating the specifier order as user input.

Of course you can normalise the package name for the purposes of the resolver, but you also need to retain the unnormalised name, because that's what you have to use when displaying the package name to the user. If you're displaying normalised names to the user, and you haven't received bug reports yet, let me find the users who complained at pip for doing precisely that, and ask them to express their unhappiness to you as well 🙂

If we want to preserve certain characteristic (e.g. the spelling of the project name), should we annotate this for the applicable core metadata fields?

Personally, I think that might cause more disruption than it warrants. This is the first time I've seen anyone suggest that it's an issue, and I'd like to understand why it's causing you a problem before we start trying to "solve" it.

Footnotes

  1. I'll ignore the implications of "currently" - we can argue the correctness of any future uv build backend independently of this discussion. ↩

@brettcannon

Copy link
Copy Markdown
Member

Given that pypa/packaging is reordering version specifiers between sdist and wheel when used by a build backend

I just realized there's a slight misunderstanding here: packaging isn't causing build back-ends to use it to normalize or re-order anything. I think what's happening is build back-ends are using packaging to validate pyproject.toml or PKG-INFO values and then they are blindly taking the str of the various objects and writing it out to METADATA. I.e. packaging itself isn't directly causing this as we actually don't have an API to take in core metadata and then write it back out; you can only consume metadata in packaging.

If we want to preserve certain characteristic (e.g. the spelling of the project name), should we annotate this for the applicable core metadata fields?

I've seen projects store the original name as the "display name" and/or the normalized name as, well, the "normalized name" if they wanted to avoid normalizing at file input time.

why is uv even impacted by this question?

I'm going to guess it's about what gets written out to uv.lock somehow. I bet they are getting metadata from sdists for the lock file and that would sometimes require building it. That would put them in a position to be comparing PKG-INFO to METADATA for any field, not just Dynamic.

@konstin

konstin commented Aug 27, 2024

Copy link
Copy Markdown
Contributor Author

Of course you can normalise the package name for the purposes of the resolver, but you also need to retain the unnormalised name, because that's what you have to use when displaying the package name to the user. If you're displaying normalised names to the user, and you haven't received bug reports yet, let me find the users who complained at pip for doing precisely that, and ask them to express their unhappiness to you as well 🙂

Please share! We haven't received any reports, but we always try to learn from other projects' experiences.

So far, we're showing the name in all sorts of messages and serializing the name into the lockfile (which needs to be user-readable, for auditing and PR reviews). Relatively early in development we switched to normalized names after seeing that the spelling of the name in the wheel filename, in {name}-{version}.dist-info, in METADATA, on pypi and in their own documentation often mismatched. If the METADATA one should be the canonical one, we'll switch to that when adding a uv build backend.

For reference, here's an excerpt from a uv.lock. albatross is a workspace member, anyio is an external dependency:

[[package]]
name = "albatross"
version = "0.1.0"
source = { editable = "." }
dependencies = [
    { name = "bird-feeder" },
    { name = "tqdm" },
]

[package.metadata]
requires-dist = [
    { name = "bird-feeder", editable = "packages/bird-feeder" },
    { name = "tqdm", specifier = ">=4,<5" },
]

[[package]]
name = "anyio"
version = "4.4.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
    { name = "idna" },
    { name = "sniffio" },
]
sdist = { url = "https://files.pythonhosted.org/packages/e6/e3/c4c8d473d6780ef1853d630d581f70d655b4f8d7553c6997958c283039a2/anyio-4.4.0.tar.gz", hash = "sha256:5aadc6a1bbb7cdb0bede386cac5e2940f5e2ff3aa20277e991cf028e0585ce94", size = 163930 }
wheels = [
    { url = "https://files.pythonhosted.org/packages/7b/a2/10639a79341f6c019dedc95bd48a4928eed9f1d1197f4c04f546fc7ae0ff/anyio-4.4.0-py3-none-any.whl", hash = "sha256:c1b2d8f46a8a812513012e1107cb0e68c17159a7a594208005a57dc776e1bdc7", size = 86780 },
]

@pfmoore

pfmoore commented Aug 27, 2024

Copy link
Copy Markdown
Member

Please share! We haven't received any reports, but we always try to learn from other projects' experiences.

I'll be honest, I'm not sure I can. We've been using the project name unnormalised for years now, and have treated cases where we've accidentally displayed normalised names as bugs for as long, so any reports would be from a long time ago. I did a search on the tracker, and couldn't find anything specific, but it's difficult to think of a good search term. So I may well be misremembering the history here.

There's a lot of tangential discussion of issues related to name normalisation on Discourse. One that I found is https://discuss.python.org/t/change-in-pypi-upload-behavior-intentional-accidental-pebkac/27707. It's mostly about normalising the project name in wheel filenames and .disti-info directory names, but it does contain a lot of comments suggesting that people aren't willing to just switch to normalised names everywhere. How much of that is because people prefer a different display name, and how much is because of the churn it would cause, I can't say.

It's possible that I'm either mistaken in how much importance I'm putting on this, or flat-out spreading FUD based on what I recall of old discussions. So feel free to ignore me on this point.

None of this is relevant to this issue, though. I'd still like to understand why the precise wording matters to you. I clarified my intended meaning of "match" above:

If I had to clarify "match", I'd probably say that it means "tools consuming the data can use data from either source without fear of errors, and tools that produce the data must write the data so that the previous assumption holds". But I'm not sure that's better than simply saying "match" - it's just longer.

and that remains my position.

If this is about building a backend, then I'm not the person to advise you as I have no experience with that. I'd suggest asking other backend developers what their view is, as no-one else seems to have hit an issue with the wording as it stands. If it turns out we do need a more precise wording, I'd like to see what's being proposed before saying whether it needs a PEP - but the change in this PR to say "semantically equivalent" is no better in practice than the current form, because we don't have a precise definition of what "semantic equivalence" means (both in terms of the complexities of specifier equivalence, and in terms of the question of whether the display form of a project name counts as "semantically significant").

@konstin

konstin commented Aug 27, 2024

Copy link
Copy Markdown
Contributor Author

My intention with this change was to clarify that the strings don't need to be identical between pyproject.toml and METADATA, which i didn't find clear in the current version, hoping it saves the next person from hitting the same problems i had.

tools consuming the data can use data from either source without fear of errors, and tools that produce the data must write the data so that the previous assumption holds

We can totally use this as clarification for what "match" means. For a tool that does this kind of transformation, it's important to know what kind of changes are safe to do without fear of errors, and which changes could lead to an error. I think we agree that let's say removing whitespace in version specifiers (like >= 3 to >=3) is safe, but is replacing ~= 2.2 with >= 2.2, == 2.*? (Explanatory examples, there's no problem path rn to discuss). Independent of the exact wording in the spec, as a consumer, an output-writer and also future producer of metadata, and especially one that can't just depend on packaging, we have to take care of these kinds of normalizations and transformations, and we're trying to align around standards and community norms to maximize interoperability.

@pfmoore

pfmoore commented Aug 27, 2024

Copy link
Copy Markdown
Member

My intention with this change was to clarify that the strings don't need to be identical between pyproject.toml and METADATA

But that's got nothing to do with the core metadata Dynamic field, which was introduced by PEP 643. What controls the process of writing METADATA from pyproject.toml is the project.dynamic field introduced in PEP 621 and documented here. The key statement here is

Static metadata is specified in the pyproject.toml file directly and cannot be specified or changed by a tool (this includes data referred to by the metadata, e.g. the contents of files referenced by the metadata).

I think this is pretty explicit that the data provided by the user must be copied unchanged.

@rgommers rgommers added type: enhancement A self-contained enhancement or new feature component: specifications labels Nov 10, 2026
@konstin

konstin commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

I had codex survey build backends, starting with requires-python = ">= 3.9, < 4" in pyproject.toml. It seems that all apply some string transformations.

Build backend and version tested Requires-Python value written Changes to dependency strings (Requires-Dist)
Setuptools 84.2.1, PBR 7.1.3, PDM-backend 2.5.0, scikit-build-core 1.1.2, meson-python 0.22.1 <4,>=3.9 Removed spaces and reordered specifiers, e.g. >= 2, < 3 → <3,>=2.
Hatchling 1.33.0 <4,>=3.9 Removed spaces, reordered specifiers, normalized dependency and extra names, and sorted dependency entries.
Poetry-core 2.5.0 >= 3.9, < 4 Reformatted constraints, e.g. >= 2, < 3 → (>=2,<3), and sorted dependency entries.
Flit-core 4.2.0 >= 3.9, < 4 Kept specifier spacing and order. Normalized extras, e.g. [Zed,alpha] → [zed, alpha].
uv-build 0.13.10, Maturin 1.16.0 >=3.9, <4 Removed specifier whitespace, normalized names, and rewrote the test marker from python_version to python_full_version.

In the current version of the description of `Dynamic` in the core metadata, it is unclear whether "match" means string equivalence or semantic equivalence. Given that pypa/packaging is reordering version specifiers between sdist and wheel when used by a build backend (which to my best knowledge are all build backend written in python), we can clarify this to semantic equivalence.
@notatallshaw

Copy link
Copy Markdown
Contributor

FYI, I assume some of these normalization is being inherited from packaging's normalization and ASCII ordering of specifiers, which was recently discussed: pypa/packaging#1416, we're probably never going to change the default normalization to avoid causing breakages.

We are looking adding raw_version on the version object for users to use, it's not unreasonable for us then to build on top of this to do raw_specifier, and raw_requirement, but tools would need to call it to preserve original text.

@konstin

konstin commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Good to know! FWIW I don't hold a strong opinion on what tool should do. There's arguments for preserving the strings verbatim (it's what the user gave us, casing preferences) and for normalizing (more consistent, also removing redundancy (we do this when writing uv's lockfile), makes it easier for consumers), this is really just about making sure we align our specs with the current practice.

@pfmoore

pfmoore commented Nov 28, 2026

Copy link
Copy Markdown
Member

I'm still frustrated by the mismatch here between what the original comment was talking about and what's being quoted as evidence.

The original post was specifically about Dynamic in the core metadata. What's in pyproject.toml is completely irrelevant to that question, and that's entirely intentional (speaking as the author of PEP 643). The idea of that field is that if a sdist contains a value, which is not marked as Dynamic, then the wheel must contain a matching value. I concede that "matching" is not as precise a term as we'd like, but I stand by my previous clarification, it means that tools consuming the data must behave identically whether they see the value from the sdist or the value in the wheel. The simplest way of ensuring that is to use a textually identical string, but there's some leeway for "semantically equivalent" variations1.

I'm not claiming any special knowledge about the intention behind the rules for transferring values from pyproject.toml into project metadata, but I find it hard to believe that "Static metadata is specified in the pyproject.toml file directly and cannot be specified or changed by a tool" means anything other than "copy the data unchanged".

All of this is what the rules say. What tools do in practice is a different matter - if tools aren't following the rules, then my initial position would be that the behaviour should simply be viewed as a bug in the tools. We could loosen the specifications so that the behaviour is no longer disallowed, but that's precisely where we need to be cautious about compatibility. The evidence from existing build backends is interesting, but I'm not sure how helpful it is. Without knowing whether projects care about differences, it's hard to see what we can do with the information (plus, not all build backends are used equally - I imagine setuptools is still used far more than most other backends, and it's the strictest, so by that measure, we've no information about whether most projects would be impacted by looser constraints).

Personally, my gut feeling is that for core metadata we'd probably be OK treating the term "match" as meaning "normalises to the same value" for everything except the project name. For project name I'd prefer string equality to be the interpretation. I don't want to claim authority on the rules for pyproject.toml values, so I'll say nothing more on that case beyond what I said above (that my reading of the spec makes me think that copying the data unchanged is required).

So where does that leave us?

  • If "stated intention of the original PEP author" has any authority, I've stated my view on what's acceptable as a "clarification" for the core metadata field.
  • I have no authority (any more) to make a statement on the pyproject.toml field, so I'll leave that to others to decide.
  • Anything can be done via a PEP or PPC approval, so that option is always available.

Footnotes

  1. I'm still uncomfortable with counting names that are textually different but normalise the same as "semantically equivalent" because I know people have expressed strong opinions about whether their project name is recorded as foo.bar or foo_bar or foo-bar... ↩

@pfmoore

pfmoore commented Nov 28, 2026

Copy link
Copy Markdown
Member

this is really just about making sure we align our specs with the current practice.

Surely "aligning current practice with our specs" (i.e., fixing standard compliance bugs in tools) should be our initial position here, with changing the specs only being considered if there's a good case that tool behaviour is better for the user and for interoperability?

@konstin

konstin commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

The effective rules are set by implementations (i.e., CPython) and tools (i.e., packaging and pip). When reimplementing all those specs for uv, we started by following the documentation on packaging.python.org, only to eventually just copy what pip does, cause that's what actual packages use. Usually, what the implementations do is more correct and more helpful than the specs, and sometimes you want to deviate even further, caused you measured something or you have the user reports for something that you know can be done better. In general, I'd say that changing PPO is better for the user and for interoperability. We've accumulated a lot of debt on PPO!

The problems in the specs can range from being wrong over being unhelpful to being actively misleading. Tools can and do change the rules without the spec, in the linked case because a vendor changed the rules (and I don't think apple will consider the rules we set down in the PEP for macOS versioning), and sometimes we do change the specs for tools incompatiblities. I find it more helpful to see PPO as documentation, and I'm interested in having high-quality documentation for the Python packaging ecosystem.

@pfmoore

pfmoore commented Nov 28, 2026

Copy link
Copy Markdown
Member

I find it more helpful to see PPO as documentation

So if PPO is simply documentation, and implementations do what they choose based on user reports, where do the official standards reside, that we (as a community) have agreed we will all follow? Surely somewhere needs to be the formal record of the standards (which are changed - as opposed to clarified - only via a formal process) and if that place isn't PPO then where is it?

For the record, in my view, the "Packaging standards" section of PPO is the formal location of our standards and has different, stricter, rules for how it may be changed than the rest of PPO. If the PPC feel differently, they can say so.

Anyway, I'm not sure where this is getting us.

I'm a strong -1 on this change as it stands, and I don't consider the information around pyproject.toml usage to be relevant in terms of changing my mind on that.

@rgommers

Copy link
Copy Markdown
Contributor

On the technical questions, there seem to be two separate ones mixed here:

  1. What, if any, transformations are allowed when going from pyproject.toml to Core Metadata? (PEP 621 related)
  2. What, if any, transformations are allowed when going from PKG-INFO in an sdist to METADATA in a wheel? (PEP 643 related)

I believe @pfmoore is right that the current diff in this PR is about (2), while some of the arguments are in support of semantic rather than textual equivalence for (1).

I think that the arguments from @konstin for using "semantic equivalence" for pyproject.toml -> sdist/wheel are fairly solid, but that @pfmoore is right that an exception should be made for name which tools shouldn't change (that has a long history indeed) when writing out Core Metadata content. And that it is "semantic equivalence" in a narrow sense (normalization, whitespace cleanup, etc.) - larger metadata rewrites were recently discussed and rejected in PEP 808. It seems that that's already close to consensus.

For PKG-INFO -> METADATA transformation, I don't see a strong need for "semantic" rather than "textual", because presumably whatever needs normalizing will be normalized in the exact same way when going from pyproject.toml -> PKG-INFO already. However, there is some risk for drift in case the sdist and wheel are built with different versions of a build backend and the implementation got changed. Because backends will read from pyproject.toml instead of PKG-INFO, so there is a real-world possibility of this happening and then the letter of the specification not being followed unless it does mean "semantic" and not "textual". Possibly this is what worried you @konstin?

The discussion about specification vs. implementations is mostly a distraction I think, and a bit too black-and-white. Standards are clearly more than just documentation, they have normative power. However it's also true that standards get clarified, amended, etc. based on real-world needs. That's true even for much more mature and rigorously-maintained standards (e.g., for C/C++), and doubly so for packaging specs which have accumulated a major amount of technical debt over time on this site. So, this kind of thing can get handled on a case-by-case basis, it's not always one or the other.

@rgommers

Copy link
Copy Markdown
Contributor

I did a bit of follow-up digging to ensure I got the implementation risk above right for PKG-INFO -> METADATA. All of the main backends (I checked eight: setuptools, meson-python, scikit-build-core, Maturin, Hatchling, Flit, PDM-backend and uv-build) use metadata from pyproject.toml rather than copying the static metadata from the sdist's PKG-INFO (Hatchling does read PKG-INFO to recover values for fields declared dynamic in pyproject.toml). This makes sense, and also aligns with a long discussion we had about what is authoritative between pyproject.toml and PKG-INFO - this comment by @pfmoore was the resolution (tl;dr pyproject.toml, except for fields marked dynamic in pyproject.toml and static in PKG-INFO).

Hence there is a real possibility of drift if the sdist and wheel are built with different versions of the build backend or its dependencies (e.g., packaging or pyproject-metadata). Now this is unlikely to be common for releases on PyPI that get built at the same moment in time, however it is possible - and especially given that some projects have/had a habit of uploading more wheels for new platforms or a new CPython version well after the initial release. And it's even more likely in other scenarios, e.g. for another index where rebuilds happen later based on an sdist from PyPI.

That seems like a reasonable argument in favor of semantic rather than textual equivalence for (2) as well. Requiring textual equivalence would effectively make the exact serialization behavior of build backends and their dependencies part of their backwards compatibility guarantees. Even changing backends now to preserve user-supplied strings verbatim would cause textual mismatches when building wheels from existing sdists. The alternative would be to require backends to take non-dynamic metadata directly from PKG-INFO, adding complexity to their implementations. Neither seems particularly desirable in the absence of a clear benefit to users or consumers of the metadata.

@konstin

konstin commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

On the technical questions, there seem to be two separate ones mixed here:

1. What, if any, transformations are allowed when going from `pyproject.toml` to Core Metadata? (PEP 621 related)

2. What, if any, transformations are allowed when going from `PKG-INFO` in an sdist to `METADATA` in a wheel? (PEP 643 related)

I believe @pfmoore is right that the current diff in this PR is about (2), while some of the arguments are in support of semantic rather than textual equivalence for (1).

Fair point, I made this more clear by covering pyproject.toml -> PKG-INFO -> METADATA explicitly.

And that it is "semantic equivalence" in a narrow sense (normalization, whitespace cleanup, etc.) - larger metadata rewrites were recently discussed and rejected in PEP 808. It seems that that's already close to consensus.

I mean semantic equivalence in the sense that they are functionally equivalent, which e.g. torch and torch>=1.2 aren't (they would accept/reject different resolution). (And we're assuming the most cursed of platforms where you can't interchange sys_platform and os_name.) Do we need to say more to make this clearer?

I think that the arguments from @konstin for using "semantic equivalence" for pyproject.toml -> sdist/wheel are fairly solid, but that @pfmoore is right that an exception should be made for name which tools shouldn't change (that has a long history indeed) when writing out Core Metadata content.

I had codex pull some data on that for that for the top 1k PyPI packages:

Names compared Exact mismatches
PyPI page vs. wheel METADATA 50 / 997 (5.0%)
PyPI page vs. sdist pyproject.toml 39 / 668 (5.8%)
PyPI page vs. sdist PKG-INFO 58 / 954 (6.1%)
Wheel METADATA vs. sdist pyproject.toml 3 / 668 (0.4%)
Wheel METADATA vs. sdist PKG-INFO 10 / 951 (1.1%)
Sdist pyproject.toml vs. sdist PKG-INFO 3 / 668 (0.4%)
Build backend PyPI differs from matching METADATA and PKG-INFO Wheel METADATA has hyphens and sdist PKG-INFO has underscores pyproject.toml differs from matching METADATA and PKG-INFO PyPI differs from wheel METADATA (no sdist)
Setuptools, explicit 18 2 0 0
Setuptools, implicit or legacy 7 6 0 0
Flit 7 0 0 0
Hatchling 13 0 0 0
Maturin 2 0 0 0
scikit-build-core 1 0 0 0
OpenCV custom backend (scikit-build) 0 2 0 0
uv_build 0 0 2 0
Poetry 0 0 1 0
Setuptools (wheel generator) 0 0 0 1
pipcl (wheel generator) 0 0 0 1
Total 48 10 3 2

For PKG-INFO -> METADATA transformation, I don't see a strong need for "semantic" rather than "textual", because presumably whatever needs normalizing will be normalized in the exact same way when going from pyproject.toml -> PKG-INFO already. However, there is some risk for drift in case the sdist and wheel are built with different versions of a build backend and the implementation got changed. Because backends will read from pyproject.toml instead of PKG-INFO, so there is a real-world possibility of this happening and then the letter of the specification not being followed unless it does mean "semantic" and not "textual". Possibly this is what worried you @konstin?

Yeah, it does happen that build backends change/fix their normalization rules. There's a consistency argument, if pyproject.toml -> PKG-INFO and pyproject.toml -> METADATA can normalize, it would be strange if PKG-INFO -> METADATA couldn't, you'd need to build separate paths where you don't normalize just for the case.

@konstin konstin changed the title Clarify the meaning of "match" between sdist and wheel Require semantic equivalence between pyproject.toml, PKG-INFO and METADATA Dec 1, 2026
@konstin

konstin commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Found a concrete case for drift between source distribution and wheel: Building nox 2026.8.17 from source distribution with two different hatchling versions. Hatchling 1.32.0 says Version: 2026.8.17, while hatchling 1.32.3 says Version: 2026.08.17 due to pypa/hatch#2398 (with a subsequent fixup in pypa/hatch#2438).

@pfmoore

pfmoore commented Dec 1, 2026

Copy link
Copy Markdown
Member

Thanks. I'm happy to confirm that for that specific case, I'd consider the two different values to "match" in the sense that I intended it in the original PEP.

If you can find a case of drift in Name, that would be of more concern to me.

@konstin

konstin commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

The table above is all name mismatches!

Sampling 5 random concrete cases:

  1. typing-extensions 4.16.0 shows typing-extensions on PyPI. All three files say typing_extensions. Twine changed the name on upload.
  2. stack-data 0.6.3 has stack_data in PKG-INFO and stack-data in wheel METADATA. PyPI uses the wheel spelling.
  3. supabase-auth 2.34.1 declares supabase_auth in pyproject.toml. uv_build writes supabase-auth in both metadata files.
  4. InquirerPy 0.3.4 declares InquirerPy in pyproject.toml. Poetry writes inquirerpy in both metadata files.
  5. pymupdf-layout 2.2 shows pymupdf-layout on PyPI and pymupdf_layout in wheel METADATA. The release has no sdist.

@pfmoore

pfmoore commented Dec 1, 2026

Copy link
Copy Markdown
Member

My apologies, I hadn't realised that. I'll admit I skimmed the post rather than looking in detail - I thought you were reporting on differences between pyproject.toml, PKG-INFO and METADATA. I should have read more carefully, sorry.

As things stand (i.e., based on existing standards) these seem like they are all tool bugs to me1. If we want to reclassify any of them as acceptable behaviour, I think we need to have a public discussion on DPO. While I can understand the argument "tools do this already, so we have evidence that it doesn't matter", I can say from personal experience that for at least one of my projects, I wanted the name to be spelled a certain way, but was frustrated to find I couldn't make that happen. So "it doesn't matter", feels a bit strong to me, it's more a case of "it's an annoyance but the difficulty getting consensus on DPO has meant no-one has bothered trying to make an issue of it". I don't think we should change the standard just because our current processes are bad at enforcing our agreed standards...

To be clear, I'm not completely against changing the rules, even for Name. I just want to be sure that whatever change we make is supported by both project maintainers and tool developers. The evidence you've shown suggests that tool developers have problems implementing the current rules, but you have no evidence that your proposed weakening of the rules (essentially to "you can specify whatever you want, but we are allowed to change it to any alternative form that normalises the same, and we won't even guarantee that we'll do so consistently everywhere"2) is acceptable to project authors. Personally, if I were persuaded that we should change the rules, I'd prefer a strengthening, where we say that data in pyproject.toml and the core metadata must always be in normalised form, and tools are required to warn and normalise when unnormalised data is found in pyproject.toml (rejecting with an error would also be OK, but would need such a long transition that I don't think it's practical given the existing codebases we have to deal with).

Footnotes

  1. With the possible exception of the twine one demonstrated by typing-extensions, because we don't have a standard for what PyPI presents as the project name as distinct from what the project metadata files contain... ↩

  2. Yes, I'm stating that in the worst possible way, to emphasise how little the proposal guarantees for project maintainers. ↩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: specifications type: enhancement A self-contained enhancement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants