pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.34k stars 1.14k forks source link

Requires-Dist metadata not canonicalized between wheels and sdists #4336

Closed wimglenn closed 2 weeks ago

wimglenn commented 2 weeks ago

setuptools version

setuptools==69.5.1 wheel==0.43.0

Python version

3.12

OS

macOS/Linux

Description

Requirements are normalized differently in sdist PKG-INFO file and wheel METADATA file

Expected behavior

Metadata in sdist and wheel are same

How to Reproduce

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "example-proj"
version = "0.1"

[project.optional-dependencies]
all = ["typing-extensions >=4.2,   <5 ; python_version  <'3.8'"]

Using build I get an sdist and wheel that are mostly identical (sans trailing newline) but the Requires-Dist: values are formatted differently.

Output

After extraction, the wheel metadata looks like this

$ cat example_proj-0.1.dist-info/METADATA
Metadata-Version: 2.1
Name: example-proj
Version: 0.1
Provides-Extra: all
Requires-Dist: typing-extensions <5,>=4.2 ; (python_version < "3.8") and extra == 'all'

The sdist metadata looks like this

$ cat example_proj-0.1/PKG-INFO              
Metadata-Version: 2.1
Name: example-proj
Version: 0.1
Provides-Extra: all
Requires-Dist: typing-extensions<5,>=4.2; python_version < "3.8" and extra == "all"

Although the meaning is the same, it would be nice if metadata files in wheel and sdist were byte-for-byte identical.

For the record, the sdist's content seems to be in agreement with the way packaging wants:

>>> from packaging.requirements import Requirement
>>> print(Requirement("typing-extensions >=4.2,   <5 ; (python_version  <'3.8')   and extra == 'all'"))
typing-extensions<5,>=4.2; python_version < "3.8" and extra == "all"

I'm not sure if the best place to address the issue is in setuptools directly or in pypa/wheel.

wimglenn commented 2 weeks ago

https://github.com/pypa/wheel/issues/395 similar issue on the wheel repo

abravalheri commented 2 weeks ago

I think handling this in wheel is the way to go. If I am not mistaken we already use packaging for "canonicalising" the requirements in the setuptools code base.

wimglenn commented 2 weeks ago

@abravalheri I've handled it in wheel. I'm now curious, though, why doesn't setuptools vendor wheel as it does with the other packages it wants to use?

abravalheri commented 2 weeks ago

I would say it is a work in progress 😅

It is slightly more complicated than usual because the integration happens at entry-point level.